generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 114
206 lines (179 loc) · 8.52 KB
/
register-validator.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Register validator
on:
issues:
types: [ labeled, unlabeled ]
concurrency:
group: register-validator-${{ github.event.issue.number }}
cancel-in-progress: true
jobs:
resolve-context:
if: |
!github.event.issue.pull_request &&
contains(github.event.issue.labels.*.name, 'register-validator') &&
!contains(github.event.issue.labels.*.name, 'invalid')
runs-on: ubuntu-22.04
outputs:
network: ${{ fromJson(steps.parse-issue.outputs.jsonString).network }}
gentx: ${{ steps.extract-gentx.outputs.gentx }}
delegator_addr: ${{ fromJson(steps.parse-issue.outputs.jsonString).delegator_addr }}
moniker: ${{ steps.extract-gentx.outputs.moniker }}
register-config: ${{ steps.register-config.outputs.config }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Parse issue form content
id: parse-issue
uses: stefanbuck/github-issue-parser@v3
with:
issue-body: ${{ github.event.issue.body }}
template-path: .github/ISSUE_TEMPLATE/register-validator.yml
- name: Extract gentx
id: extract-gentx
env:
# GENTX_MD needs some sorcery as it is not well extracted from the form issue.
GENTX_MD: ${{ fromJson(steps.parse-issue.outputs.jsonString).gentx }}
run: |
set -eo pipefail
gentx=$(echo "$GENTX_MD" | tail -n +2 | sed '$d' | jq -c '.')
moniker=$(echo "$gentx" | jq -r '.body.messages[0].description.moniker')
echo "moniker=${moniker}" >> $GITHUB_OUTPUT
echo "gentx=${gentx}" >> $GITHUB_OUTPUT
- name: Get network register config
id: register-config
run: |
set -eo pipefail
config=$(cat chains/${{ fromJson(steps.parse-issue.outputs.jsonString).network }}/register-config.json | jq -c '.')
echo "config=${config}" >> $GITHUB_OUTPUT
check:
needs:
- resolve-context
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Setup jq
run: |
sudo apt install -y jq
- name: Check gentx
id: check-gentx
env:
GENTX: ${{ needs.resolve-context.outputs.gentx }}
run: |
set -e
echo "🧐 Checking gentx"
startTime=$(date --date="${{ fromJson(needs.resolve-context.outputs.register-config).start-date }}" +%s)
endTime=$(date --date="${{ fromJson(needs.resolve-context.outputs.register-config).end-date }}" +%s)
now=$(date +%s)
if [[ $now < $startTime ]]; then
echo error='Register process is not open yet for this network.' >> $GITHUB_OUTPUT
exit 1
elif [[ $now > $endTime ]]; then
echo error='Register process is closed for this network.' >> $GITHUB_OUTPUT
exit 1
fi
delegationAmount=$(echo "$GENTX" | jq -r '.body.messages[0].value.amount')
delegationDenom=$(echo "$GENTX" | jq -r '.body.messages[0].value.denom')
if [ "${{ fromJson(needs.resolve-context.outputs.register-config).delegation.amount }}" != "$delegationAmount" ]; then
echo error='Invalid delegation amount.' >> $GITHUB_OUTPUT
exit 1
elif [ "${{ fromJson(needs.resolve-context.outputs.register-config).delegation.denom }}" != "$delegationDenom" ]; then
echo error='Invalid delegation denom.' >> $GITHUB_OUTPUT
exit 1
fi
echo "👍 gentx seems right."
- name: Mark issue invalid
if: ${{ failure() }}
uses: andymckay/labeler@master
with:
repo-token: ${{ secrets.OPS_TOKEN }}
add-labels: "invalid"
- name: Add failure comment
if: ${{ failure() }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.OPS_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: |
😢 I couldn't process your request: `${{ steps.check-gentx.outputs.error }}`
process:
needs:
- resolve-context
- check
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
- name: Process gentx
id: add-gentx
env:
GENTX: ${{ needs.resolve-context.outputs.gentx }}
DELEGATOR_ADDR: ${{ needs.resolve-context.outputs.delegator_addr }}
NODE_HOME: /tmp/node
run: |
mkdir -p chains/${{ needs.resolve-context.outputs.network }}/gentx
echo "$GENTX" > chains/${{ needs.resolve-context.outputs.network }}/gentx/gentx-${{ github.event.issue.number }}.json
mkdir -p $NODE_HOME
docker run --rm --user $(id -u):$(id -g) -v $NODE_HOME:$NODE_HOME axoneprotocol/axoned:`cat ./chains/${{ needs.resolve-context.outputs.network }}/version.txt` init --home $NODE_HOME whatever
cp chains/${{ needs.resolve-context.outputs.network }}/genesis.json $NODE_HOME/config/genesis.json
delegator_balance="`expr ${{ fromJson(needs.resolve-context.outputs.register-config).delegation.amount }} + 200000`${{ fromJson(needs.resolve-context.outputs.register-config).delegation.denom }}"
docker run --rm --user $(id -u):$(id -g) -v $NODE_HOME:$NODE_HOME axoneprotocol/axoned:`cat ./chains/${{ needs.resolve-context.outputs.network }}/version.txt` genesis add-genesis-account --home $NODE_HOME $DELEGATOR_ADDR $delegator_balance
docker run --rm --user $(id -u):$(id -g) -v $NODE_HOME:$NODE_HOME -v $PWD/chains/${{ needs.resolve-context.outputs.network }}/gentx:/gentx axoneprotocol/axoned:`cat ./chains/${{ needs.resolve-context.outputs.network }}/version.txt` genesis collect-gentxs --home $NODE_HOME --gentx-dir /gentx
cp $NODE_HOME/config/genesis.json chains/${{ needs.resolve-context.outputs.network }}/genesis.json
- name: Prepare commit message
id: commit-message
run: |
type=feat
scope="${{ needs.resolve-context.outputs.network }}"
description="register validator gentx ${{ needs.resolve-context.outputs.moniker }}"
body="Closes #${{ github.event.issue.number }}"
line1="$type($scope): $description"
line1=$(echo "$line1" | awk -v len=90 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }' )
message="$line1\n\n$body"
message="${message//'%'/'%25'}"
message="${message//$'\n'/'%0A'}"
message="${message//$'\r'/'%0D'}"
echo "message=${message}" >> $GITHUB_OUTPUT
- name: Create Pull Request
id: open-pr
uses: peter-evans/create-pull-request@v7
with:
commit-message: |
${{ steps.commit-message.outputs.message }}
committer: ${{ vars.BOT_GIT_COMMITTER_NAME }} <${{ vars.BOT_GIT_COMMITTER_EMAIL }}>
author: ${{ vars.BOT_GIT_AUTHOR_NAME }} <${{ vars.BOT_GIT_AUTHOR_EMAIL }}>
token: ${{ secrets.OPS_TOKEN }}
branch: feat/${{ github.event.issue.number }}-register-${{ needs.resolve-context.outputs.network }}
title: '⚖️ Register `${{ needs.resolve-context.outputs.moniker }}` Validator'
body: |
Register [new validator](${{ github.event.issue.html_url }}) gentx on the ${{ needs.resolve-context.outputs.network }} network.
labels: "register-validator,chain: ⛓️ ${{ needs.resolve-context.outputs.network }}"
assignees: amimart,ccamel
reviewers: amimart,ccamel,tpelliet
- name: Link PR
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.OPS_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: |
😉 Here is the corresponding PR: ${{ steps.open-pr.outputs.pull-request-url }}
- name: Mark issue invalid
if: ${{ failure() }}
uses: andymckay/labeler@master
with:
repo-token: ${{ secrets.OPS_TOKEN }}
add-labels: "invalid"
- name: Add failure comment
if: ${{ failure() }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.OPS_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: 😢 I couldn't process your request...