KNGHT donations 2023-05 2024-12 #1152
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Validate JSONs and Donation files | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
validate-donation-entries: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
#with: | |
# ref: ${{ github.head_ref }} | |
- name: Check files in donations.yml | |
uses: mikefarah/yq@v4.6.1 | |
with: | |
cmd: ls -la */donations.yml; for F in */donations.yml; do PROOFS="`yq e '.[].files' $F | cut -d' ' -f2`"; for PROOF in $PROOFS; do echo -n $PROOF; [ ! -f "$PROOF" ] && echo ' MISSING' && exit 1; echo ' exists'; done; done | |
- name: Create jsons out of donations.yml | |
uses: mikefarah/yq@v4.6.1 | |
with: | |
cmd: "for F in */donations.yml; do DEST=${F/yml/json}; yq -j e . $F > $DEST; cat $DEST; done" | |
- name: The Validate JSON action insists of adding the pwd to all json paths, so lets trick it | |
run: | | |
mkdir -p /home/runner/work/Donations/Donations/home/runner/work/Donations/ | |
ln -s /home/runner/work/Donations/Donations /home/runner/work/Donations/Donations/home/runner/work/Donations/Donations | |
ls -la /home/runner/work/Donations/Donations/home/runner/work/Donations | |
- name: Debug all donations.json files | |
run: "for i in */donations.json; do echo $i; cat $i; echo; done" | |
- name: Validate JSON | |
uses: kiriakos/validate-json-action@e97bf4885314574701657ab73e5b7fceb3e07130 | |
with: | |
schema: .github/schemas/donations-schema.json | |
env: | |
INPUT_SCHEMA: .github/schemas/donations-schema.json | |
INPUT_JSONS: "/home/runner/work/Donations/Donations/*/donations.json" | |
# Run calculations only to ensure they actually work | |
- name: Calculate Total Ada Donated per pool | |
uses: mikefarah/yq@v4.6.1 | |
with: | |
cmd: for F in */donations.yml; do TKR=`echo $F | cut -d/ -f1`; SUM=`yq e '.[].ada' "$F" | grep -v -e --- | paste -sd+ | bc`; echo -e "$SUM\t$TKR" >> /tmp/donations.ada; done; sort -nr /tmp/donations.ada > donations.ada | |
- name: Calculate Total USD Donated per pool | |
uses: mikefarah/yq@v4.6.1 | |
with: | |
cmd: for F in */donations.yml; do TKR=`echo $F | cut -d/ -f1`; SUM=`yq e '.[].usd' "$F" | grep -v -e --- | tr -d , | paste -sd+ | bc`; echo -e "$SUM\t$TKR" >> /tmp/donations.usd; done; sort -nr /tmp/donations.usd > donations.usd | |
- name: Calculate total Donations | |
run: | | |
cat donations.ada | cut -f1 | paste -sd+ | bc > totals.ada | |
cat donations.usd | cut -f1 | paste -sd+ | bc > totals.usd | |