-
Notifications
You must be signed in to change notification settings - Fork 55
289 lines (252 loc) · 12 KB
/
software-upgrade-test.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
name: Test Software Upgrade
on:
pull_request:
push:
branches:
- develop
- devnet
- main
jobs:
create-new-snapshot:
runs-on: elys-runner-x2-2
steps:
- name: Check if secrets are set
run: |
if [ -z "${{ secrets.R2_ACCESS_KEY }}" ]; then
echo "R2_ACCESS_KEY is not set."
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Get latest tag
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
echo "Latest tag: $LATEST_TAG"
- name: Retrieve latest binary
run: |
DOWNLOAD_URL=https://github.com/elys-network/elys/releases/download/${LATEST_TAG}/elysd-${LATEST_TAG}-linux-amd64
OLD_BINARY_PATH=/tmp/elysd-${LATEST_TAG}
# download binary from release
curl -L $DOWNLOAD_URL -o $OLD_BINARY_PATH && chmod +x $OLD_BINARY_PATH
# build binary from source
# git tag -f ${LATEST_TAG}
# make build
# mv ./build/elysd $OLD_BINARY_PATH
# git tag -d ${LATEST_TAG}
echo "OLD_BINARY_PATH=$OLD_BINARY_PATH" >> $GITHUB_ENV
- name: Retrieve post upgrade snapshot generator binary
run: |
# Get latest release version using GitHub API
POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION=$(curl -s https://api.github.com/repos/elys-network/post-upgrade-snapshot-generator/releases/latest | grep -Po '"tag_name": "\K.*?(?=")')
echo "Latest post-upgrade-snapshot-generator version: $POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION"
DOWNLOAD_URL=https://github.com/elys-network/post-upgrade-snapshot-generator/releases/download/${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}-linux-amd64
POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=/tmp/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}
curl -L $DOWNLOAD_URL -o $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH && chmod +x $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH
echo "POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=$POST_UPGRADE_SNAPSHOT_GENERATOR_PATH" >> $GITHUB_ENV
- name: Build new binary
run: |
# create new git tag
git tag -f v999.999.999
# build new elys binary
make build
NEW_BINARY_PATH=./build/elysd
echo "NEW_BINARY_PATH=$NEW_BINARY_PATH" >> $GITHUB_ENV
- name: Check submit new proposal from cache exists
uses: elys-network/actions-cache-s3/restore@eba1d2b54699fda7ee03d826049bc67dcf514887
id: cache-submit-new-proposal
with:
path: |
/home/runner/.elys
/home/runner/.elys2
key: ${{ runner.os }}-submit-new-proposal-${{ env.LATEST_TAG }}
lookup-only: true
aws-access-key-id: ${{ secrets.R2_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
aws-endpoint: ${{ secrets.R2_ENDPOINT }}
aws-s3-bucket: ${{ secrets.R2_BUCKET_NAME }}
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
- name: Retrieve info.json and set snapshot path
run: |
DOWNLOAD_URL=https://snapshots.elys.network/info.json
curl -L $DOWNLOAD_URL -o /tmp/info.json
echo "Info.json downloaded to check snapshot version."
# retrieve blockHeight field value from info.json
SNAPSHOT_BLOCK_HEIGHT=$(cat /tmp/info.json | awk -F'"' '/"blockHeight":/{print $4}')
echo "SNAPSHOT_BLOCK_HEIGHT=$SNAPSHOT_BLOCK_HEIGHT" >> $GITHUB_ENV
echo "Snapshot block height: $SNAPSHOT_BLOCK_HEIGHT"
APPLIED_URL=https://api.testnet.elys.network/cosmos/upgrade/v1beta1/applied_plan/${LATEST_TAG}
curl -L $APPLIED_URL -o /tmp/applied.json
echo "Applied.json downloaded to check snapshot version."
# retrieve height field value from applied.json
UPGRADE_HEIGHT=$(cat /tmp/applied.json | awk -F'"' '/"height":/{print $4}')
echo "Upgrade height: $UPGRADE_HEIGHT"
# SNAPSHOT_BLOCK_HEIGHT must be greater than UPGRADE_HEIGHT
if [ $SNAPSHOT_BLOCK_HEIGHT -le $UPGRADE_HEIGHT ]; then
echo "Snapshot block height ($SNAPSHOT_BLOCK_HEIGHT) is not greater than upgrade height ($UPGRADE_HEIGHT)."
exit 1
fi
# set snapshot download url
SNAPSHOT_DOWNLOAD_URL=https://snapshots.elys.network/snapshot.tar.lz4
echo "SNAPSHOT_DOWNLOAD_URL=$SNAPSHOT_DOWNLOAD_URL" >> $GITHUB_ENV
# set snapshot file path
SNAPSHOT_FILE_PATH=/tmp/snapshot.tar.lz4
echo "SNAPSHOT_FILE_PATH=$SNAPSHOT_FILE_PATH" >> $GITHUB_ENV
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'
- name: Check snapshot from cache exists
uses: elys-network/actions-cache-s3/restore@eba1d2b54699fda7ee03d826049bc67dcf514887
id: cache-snapshot-exists
with:
path: |
${{ env.SNAPSHOT_FILE_PATH }}
key: ${{ runner.os }}-snapshot-${{ env.LATEST_TAG }}
lookup-only: true
aws-access-key-id: ${{ secrets.R2_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
aws-endpoint: ${{ secrets.R2_ENDPOINT }}
aws-s3-bucket: ${{ secrets.R2_BUCKET_NAME }}
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'
- name: Download snapshot
run: |
curl -L $SNAPSHOT_DOWNLOAD_URL -o $SNAPSHOT_FILE_PATH
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true' && steps.cache-snapshot-exists.outputs.cache-hit != 'true'
- name: Save snapshot to cache
uses: elys-network/actions-cache-s3/save@eba1d2b54699fda7ee03d826049bc67dcf514887
with:
path: |
${{ env.SNAPSHOT_FILE_PATH }}
key: ${{ runner.os }}-snapshot-${{ env.LATEST_TAG }}
aws-access-key-id: ${{ secrets.R2_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
aws-endpoint: ${{ secrets.R2_ENDPOINT }}
aws-s3-bucket: ${{ secrets.R2_BUCKET_NAME }}
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true' && steps.cache-snapshot-exists.outputs.cache-hit != 'true'
- name: Restore snapshot from cache
uses: elys-network/actions-cache-s3/restore@eba1d2b54699fda7ee03d826049bc67dcf514887
with:
path: |
${{ env.SNAPSHOT_FILE_PATH }}
key: ${{ runner.os }}-snapshot-${{ env.LATEST_TAG }}
aws-access-key-id: ${{ secrets.R2_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
aws-endpoint: ${{ secrets.R2_ENDPOINT }}
aws-s3-bucket: ${{ secrets.R2_BUCKET_NAME }}
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true' && steps.cache-snapshot-exists.outputs.cache-hit == 'true'
- name: Chain snapshot and export
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} chain-snapshot-export \
${SNAPSHOT_FILE_PATH} \
${OLD_BINARY_PATH} \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'
- name: Chain initialization
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} chain-init \
${OLD_BINARY_PATH} \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'
- name: Create second validator
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} create-second-validator \
${OLD_BINARY_PATH} \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'
- name: Prepare validator data
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} prepare-validator-data \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'
- name: Submit new proposal
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} submit-new-proposal \
${OLD_BINARY_PATH} \
${NEW_BINARY_PATH} \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'
- name: Save submit new proposal to cache
uses: elys-network/actions-cache-s3/save@eba1d2b54699fda7ee03d826049bc67dcf514887
with:
path: |
/home/runner/.elys
/home/runner/.elys2
key: ${{ runner.os }}-submit-new-proposal-${{ env.LATEST_TAG }}
aws-access-key-id: ${{ secrets.R2_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
aws-endpoint: ${{ secrets.R2_ENDPOINT }}
aws-s3-bucket: ${{ secrets.R2_BUCKET_NAME }}
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
if: steps.cache-submit-new-proposal.outputs.cache-hit != 'true'
- name: Restore submit new proposal from cache
uses: elys-network/actions-cache-s3/restore@eba1d2b54699fda7ee03d826049bc67dcf514887
with:
path: |
/home/runner/.elys
/home/runner/.elys2
key: ${{ runner.os }}-submit-new-proposal-${{ env.LATEST_TAG }}
aws-access-key-id: ${{ secrets.R2_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
aws-endpoint: ${{ secrets.R2_ENDPOINT }}
aws-s3-bucket: ${{ secrets.R2_BUCKET_NAME }}
aws-region: auto
aws-s3-bucket-endpoint: false
aws-s3-force-path-style: true
if: steps.cache-submit-new-proposal.outputs.cache-hit == 'true'
- name: Upgrade to new binary
run: |
${POST_UPGRADE_SNAPSHOT_GENERATOR_PATH} upgrade-to-new-binary \
${NEW_BINARY_PATH} \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
- name: Create new snapshot file
run: |
SANITIZED_HEAD_REF=${{ github.head_ref || github.ref }}
SANITIZED_HEAD_REF=$(echo "$SANITIZED_HEAD_REF" | sed 's|refs/heads/||; s|/|_|g')
NEW_SNAPSHOT_FILENAME="elys-snapshot-${SANITIZED_HEAD_REF}.tar.lz4"
NEW_SNAPSHOT_PATH="/tmp/${NEW_SNAPSHOT_FILENAME}"
echo "NEW_SNAPSHOT_FILENAME=$NEW_SNAPSHOT_FILENAME" >> $GITHUB_ENV
echo "NEW_SNAPSHOT_PATH=$NEW_SNAPSHOT_PATH" >> $GITHUB_ENV
cd /home/runner
tar -cf - .elys | lz4 -z - > "$NEW_SNAPSHOT_PATH"
- name: Upload snapshot
env:
R2_BUCKET_NAME: ${{ secrets.R2_BUCKET_NAME }}
RCLONE_CONFIG_R2_TYPE: s3
RCLONE_CONFIG_R2_PROVIDER: Cloudflare
RCLONE_CONFIG_R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY }}
RCLONE_CONFIG_R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_KEY }}
RCLONE_CONFIG_R2_REGION: enam
RCLONE_CONFIG_R2_ENDPOINT: ${{ secrets.R2_ENDPOINT }}
run: |
# install rclone
curl https://rclone.org/install.sh | sudo bash
# copy snapshot to r2
rclone -vv copy "${NEW_SNAPSHOT_PATH}" r2:${R2_BUCKET_NAME}/
- name: Info about the snapshot
run: |
echo "Snapshot URL: https://snapshots.elys.network/$NEW_SNAPSHOT_FILENAME"