diff --git a/.github/workflows/execute-draw.yml b/.github/workflows/execute-draw.yml index 53b9f8f0d..4d18aaf61 100644 --- a/.github/workflows/execute-draw.yml +++ b/.github/workflows/execute-draw.yml @@ -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/draw-action@v0.0.10 - with: - inputDir: ./lists - outputDir: ./draws - count: 10 + working-directory: recipients_selection + run: ./draw.sh + - name: Commit 🔐 run: | git config --global user.name $BOT_NAME diff --git a/recipients_selection/README.md b/recipients_selection/README.md new file mode 100644 index 000000000..a2fd6fa0b --- /dev/null +++ b/recipients_selection/README.md @@ -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). diff --git a/recipients_selection/draw.sh b/recipients_selection/draw.sh new file mode 100755 index 000000000..20c48182c --- /dev/null +++ b/recipients_selection/draw.sh @@ -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" diff --git a/draws/aurora-2023-10-31.txt b/recipients_selection/draws/10-aurora-2023-10-31.txt similarity index 100% rename from draws/aurora-2023-10-31.txt rename to recipients_selection/draws/10-aurora-2023-10-31.txt diff --git a/draws/testlist b/recipients_selection/draws/2-testlist similarity index 100% rename from draws/testlist rename to recipients_selection/draws/2-testlist diff --git a/lists/aurora-2023-10-31.txt b/recipients_selection/lists/10-aurora-2023-10-31.txt similarity index 100% rename from lists/aurora-2023-10-31.txt rename to recipients_selection/lists/10-aurora-2023-10-31.txt diff --git a/lists/testlist b/recipients_selection/lists/2-testlist similarity index 100% rename from lists/testlist rename to recipients_selection/lists/2-testlist