-
Notifications
You must be signed in to change notification settings - Fork 12
139 lines (115 loc) · 7.08 KB
/
update-plomin-votes.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
- 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 | $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