Donations 20, 21, 22, 23, 24 & 25 NIMUE (#371) #255
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: Publish Donation files | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
publish-donation-entries: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.head_ref }} | |
token: ${{ secrets.BOT_PAT }} | |
- name: Check files in donations.yml | |
uses: mikefarah/[email protected] | |
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/[email protected] | |
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" | |
- name: Calculate Total Ada Donated per pool | |
uses: mikefarah/[email protected] | |
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/[email protected] | |
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 | |
- name: Commit and force push to live | |
run: | | |
BRANCH=`git branch --show-current` | |
[ "$BRANCH" = "main" ] || exit 0 | |
git config --global user.name "CardanoMDP Donations Workflow" | |
git config --global user.email "[email protected]" | |
git status | |
git add --all | |
git commit -am "Workflow results" | |
echo "Set URL to ssh://" | |
git remote -v | |
echo "Delete existing live branch" | |
git push origin --delete live || true | |
echo "Push to live" | |
git push --set-upstream origin "HEAD:live" --atomic --force |