Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(recipients-selection): move files and update scripts #607

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/execute-draw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ jobs:
with:
node-version: latest

- name: Install dchoose 🔧
run: npm install -g dchoose

- name: Make folders if necessary 📁
run: mkdir -p draws
run: |
mkdir -p ./recipients_selection/draws
mkdir -p ./recipients_selection/lists

- name: Draw 🎲
uses: drand/[email protected]
with:
inputDir: ./lists
outputDir: ./draws
count: 10
working-directory: recipients_selection
run: ./draw.sh

- name: Commit 🔐
run: |
git config --global user.name $BOT_NAME
Expand Down
20 changes: 20 additions & 0 deletions recipients_selection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Recipients selection

This directory contains everything related to the draw process.
Recipients lists are added to a private repo, their names are salted and
then the hashed versions get committed (automatically) to files in the
[./lists](./lists) directory. Once a new hashed recipient list hits the
main branch of this repo, the
[github draw action](../.github/workflows/execute-draw.yml) runs the
[draw.sh](./draw.sh) script. That script filters for lists that don't
have a corresponding draw, parses the filename for the number of
recipients to draw from the list, and triggers a draw using
[drand](https://drand.love). The randomness is not known until after the
list has been committed to, thus ensuring the selection process cannot
be biased. The output of that draw is then committed to a corresponding
file in the [./draws](./draws) directory. These draws are repeatable -
you can take the hashed recipient list and the corresponding drand
randomness, and re-run the draw using the
[dchoose](https://github.com/drand/dchoose) tool to confirm that the
outputs are the same. For further information on the draw process, check
out the [Social Income website](https://socialincome.org).
28 changes: 28 additions & 0 deletions recipients_selection/draw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -eux -o pipefail

# first we make some temp files to store each dirs contents
list_file=$(mktemp)
draw_file=$(mktemp)

# we then list all the files in the list and draw dirs respectively
$(cd ./lists && find . -type f | sort > "$list_file")
$(cd ./draws && find . -type f | sort > "$draw_file")

# we compare the contents to find files that exist as lists but not as draws
remaining_draw_filenames=$(comm -3 "$list_file" "$draw_file" | awk '{print $1}')

# we then actually run the draw
while IFS= read -r filename; do
# first we strip any leading ./
count_to_draw="${filename#./}"
# then we extract the number at the start of the filename
count_to_draw="${count_to_draw%%-*}"

# we then perform the draw, and write the output to the draw file
dchoose --count "$count_to_draw" --verbose < "./lists/$filename" > "./draws/$filename"
done <<< "$remaining_draw_filenames"

# clean up the temp files we created for storing the outputs of `ls`
rm -rf "$list_file" "$draw_file"
File renamed without changes.
File renamed without changes.
Loading