Update SPO and ICC Vote Totals for Plomin Upgrade #23
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: Update SPO Vote Totals for Plomin Upgrade | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
update-vote-totals: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Query koios for vote totals | |
id: query_api | |
run: | | |
curl -s -o vote_totals.json "https://api.koios.rest/api/v1/proposal_voting_summary?_proposal_id=gov_action1pvv5wmjqhwa4u85vu9f4ydmzu2mgt8n7et967ph2urhx53r70xusqnmm525" | |
- name: Parse API response, format data | |
id: parse_response | |
run: | | |
response=$(cat vote_totals.json) | |
cc_yes=$(echo "$response" | jq -r '.[0].committee_yes_votes_cast') | |
cc_no=$(echo "$response" | jq -r '.[0].committee_no_votes_cast') | |
cc_abstain=$(echo "$response" | jq -r '.[0].committee_abstain_votes_cast') | |
spo_yes=$(echo "$response" | jq -r '.[0].pool_yes_votes_cast') | |
spo_no=$(echo "$response" | jq -r '.[0].pool_no_votes_cast') | |
spo_abstain=$(echo "$response" | jq -r '.[0].pool_abstain_votes_cast') | |
spo_yes_stake=$(echo "$response" | jq -r '.[0].pool_active_yes_vote_power') | |
spo_no_stake=$(echo "$response" | jq -r '.[0].pool_active_no_vote_power') | |
spo_abstain_stake=$(echo "$response" | jq -r '.[0].pool_active_abstain_vote_power') | |
format_stake() { | |
num=$1 | |
num=$(echo "$num" | sed 's/.\{6\}$//') # Remove the 6 rightmost digits | |
if [ "$num" -ge 1000000000 ]; then | |
echo "$(bc <<< "scale=2; $num/1000000000")b" | |
elif [ "$num" -ge 1000000 ]; then | |
echo "$(bc <<< "scale=2; $num/1000000")m" | |
else | |
echo "$num" | |
fi | |
} | |
spo_yes_stake_formatted=$(format_stake $spo_yes_stake) | |
spo_no_stake_formatted=$(format_stake $spo_no_stake) | |
spo_abstain_stake_formatted=$(format_stake $spo_abstain_stake) | |
echo "cc_yes=$cc_yes" >> $GITHUB_ENV | |
echo "cc_no=$cc_no" >> $GITHUB_ENV | |
echo "cc_abstain=$cc_abstain" >> $GITHUB_ENV | |
echo "spo_yes=$spo_yes" >> $GITHUB_ENV | |
echo "spo_no=$spo_no" >> $GITHUB_ENV | |
echo "spo_abstain=$spo_abstain" >> $GITHUB_ENV | |
echo "spo_yes_stake_formatted=$spo_yes_stake_formatted" >> $GITHUB_ENV | |
echo "spo_no_stake_formatted=$spo_no_stake_formatted" >> $GITHUB_ENV | |
echo "spo_abstain_stake_formatted=$spo_abstain_stake_formatted" >> $GITHUB_ENV | |
echo "CC Yes votes: $cc_yes" | |
echo "CC No votes: $cc_no" | |
echo "CC Abstain votes: $cc_abstain" | |
- name: Update page | |
run: | | |
cc_yes=${{ env.cc_yes }} | |
cc_no=${{ env.cc_no }} | |
cc_abstain=${{ env.cc_abstain }} | |
spo_yes=${{ env.spo_yes }} | |
spo_no=${{ env.spo_no }} | |
spo_abstain=${{ env.spo_abstain }} | |
spo_yes_stake_formatted=${{ env.spo_yes_stake_formatted }} | |
spo_no_stake_formatted=${{ env.spo_no_stake_formatted }} | |
spo_abstain_stake_formatted=${{ env.spo_abstain_stake_formatted }} | |
current_datetime=$(date +"%Y-%m-%d %H:%M:%S") | |
sed -i "s/| Constitutional |.*|/| Constitutional | $cc_yes |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/| Unconstitutional |.*|/| Unconstitutional | $cc_no |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/| Abstain |.*|/| Abstain | $cc_abstain |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/ICC vote total last updated: .*/ICC vote total last updated: $current_datetime/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/| Yes |.*|/| Yes | $spo_yes | $spo_yes_stake_formatted |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/| No |.*|/| No | $no | $spo_no_stake_formatted |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/| Abstain |.*|/| Abstain | $spo_abstain | $spo_abstain_stake_formatted |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/SPO vote total last updated: .*/SPO vote total last updated: $current_datetime/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
- name: Commit and push changes | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git stash | |
git pull --rebase origin main | |
git stash pop | |
git add ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
git commit -m "Update vote totals" | |
git push origin HEAD:main |