Update SPO and ICC Vote Totals for Plomin Upgrade #36
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 and ICC 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') | |
cc_not_voted=$((7 - cc_yes - cc_no - cc_abstain)) | |
cc_yes_pct=$(echo "$response" | jq -r '.[0].committee_yes_pct') | |
cc_no_pct=$(echo "$response" | jq -r '.[0].committee_no_pct') | |
cc_abstain_pct=$(echo "scale=2; 100 / 7 * $cc_abstain" | bc) | |
cc_not_voted_pct=$(echo "scale=2; 100 - $cc_yes_pct - $cc_no_pct - $cc_abstain_pct" | bc) | |
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_not_voted=$((2787 - spo_yes - spo_no - spo_abstain)) | |
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') | |
spo_total_stake=21800000000000000 | |
spo_not_voted_stake=$((spo_total_stake - spo_yes_stake - spo_no_stake - spo_abstain_stake)) | |
spo_yes_pct=$(echo "$response" | jq -r '.[0].pool_yes_pct') | |
spo_no_not_pct=$(echo "$response" | jq -r '.[0].pool_no_pct') | |
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 | |
} | |
echo "cc_yes=$cc_yes" >> $GITHUB_ENV | |
echo "cc_no=$cc_no" >> $GITHUB_ENV | |
echo "cc_abstain=$cc_abstain" >> $GITHUB_ENV | |
echo "cc_not_voted=$cc_not_voted" >> $GITHUB_ENV | |
echo "cc_yes_pct=$cc_yes_pct" >> $GITHUB_ENV | |
echo "cc_no_pct=$cc_no_pct" >> $GITHUB_ENV | |
echo "cc_abstain_pct=$cc_abstain_pct" >> $GITHUB_ENV | |
echo "cc_not_voted_pct=$cc_not_voted_pct" >> $GITHUB_ENV | |
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) | |
spo_not_voted_stake_formatted=$(format_stake $spo_not_voted_stake) | |
echo "spo_yes=$spo_yes" >> $GITHUB_ENV | |
echo "spo_no=$spo_no" >> $GITHUB_ENV | |
echo "spo_abstain=$spo_abstain" >> $GITHUB_ENV | |
echo "spo_not_voted=$spo_not_voted" >> $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 "spo_not_voted_stake_formatted=$spo_not_voted_stake_formatted" >> $GITHUB_ENV | |
echo "spo_yes_pct=$spo_yes_pct" >> $GITHUB_ENV | |
echo "spo_no_not_pct=$spo_no_not_pct" >> $GITHUB_ENV | |
echo "spo_yes=$spo_yes" | |
echo "spo_no=$spo_no" | |
echo "spo_abstain=$spo_abstain" | |
echo "spo_not_voted=$spo_not_voted" | |
echo "spo_yes_stake_formatted=$spo_yes_stake_formatted" | |
echo "spo_no_stake_formatted=$spo_no_stake_formatted" | |
echo "spo_abstain_stake_formatted=$spo_abstain_stake_formatted" | |
echo "spo_not_voted_stake_formatted=$spo_not_voted_stake_formatted" | |
echo "spo_yes_pct=$spo_yes_pct" | |
echo "spo_no_not_pct=$spo_no_not_pct" | |
- name: Update page | |
run: | | |
cc_yes=${{ env.cc_yes }} | |
cc_no=${{ env.cc_no }} | |
cc_abstain=${{ env.cc_abstain }} | |
cc_not_voted=${{ env.cc_not_voted }} | |
cc_yes_pct=${{ env.cc_yes_pct }} | |
cc_no_pct=${{ env.cc_no_pct }} | |
cc_abstain_pct=${{ env.cc_abstain_pct }} | |
cc_not_voted_pct=${{ env.cc_not_voted_pct }} | |
spo_yes_pct=${{ env.spo_yes_pct }} | |
spo_no_not_pct=${{ env.spo_no_not_pct }} | |
spo_yes=${{ env.spo_yes }} | |
spo_no=${{ env.spo_no }} | |
spo_abstain=${{ env.spo_abstain }} | |
spo_not_voted=${{ env.spo_not_voted }} | |
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 }} | |
spo_not_voted_stake_formatted=${{ env.spo_not_voted_stake_formatted }} | |
current_datetime=$(date +"%Y-%m-%d %H:%M:%S") | |
sed -i "s/| Yes |.*|/| Yes | $spo_yes_pct% |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/| No + Not Voted |.*|/| No + Not Voted | $spo_no_not_pct% |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/SPO vote summary last updated: .*/SPO vote summary 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 | $spo_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/| Not Voted |.*|/| Not Voted | $spo_not_voted | $spo_not_voted_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 | |
sed -i "s/| Constitutional |.*|/| Constitutional | $cc_yes | $cc_yes_pct% |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/| Unconstitutional |.*|/| Unconstitutional | $cc_no | $cc_no_pct% |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/| Abstain |.*|/| Abstain | $cc_abstain | $cc_abstain_pct% |/" ./gitbook/plomin-upgrade/chang-upgrade-2-readiness/README.md | |
sed -i "s/| Not voted |.*|/| Not voted | $cc_not_voted | $cc_not_voted_pct% |/" ./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 | |
- 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 Plomin readiness vote totals" | |
git push origin HEAD:main |