-
Notifications
You must be signed in to change notification settings - Fork 59
263 lines (232 loc) · 9.48 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
name: Test Software Upgrade
on:
pull_request:
push:
branches:
- main
jobs:
checkout-and-setup:
runs-on: ubuntu-latest
outputs:
LATEST_TAG: ${{ steps.get-latest-tag.outputs.LATEST_TAG }}
SNAPSHOT_BLOCK_HEIGHT: ${{ steps.retrieve-info.outputs.SNAPSHOT_BLOCK_HEIGHT }}
SNAPSHOT_DOWNLOAD_URL: ${{ steps.retrieve-info.outputs.SNAPSHOT_DOWNLOAD_URL }}
steps:
- 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
id: get-latest-tag
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "::set-output name=LATEST_TAG::$LATEST_TAG"
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
echo "Latest tag: $LATEST_TAG"
- name: Retrieve info.json and set snapshot path
id: retrieve-info
run: |
DOWNLOAD_URL=https://snapshots-testnet.stake-town.com/elys/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 "::set-output name=SNAPSHOT_BLOCK_HEIGHT::$SNAPSHOT_BLOCK_HEIGHT"
echo "SNAPSHOT_BLOCK_HEIGHT=$SNAPSHOT_BLOCK_HEIGHT" >> $GITHUB_ENV
echo "Snapshot block height: $SNAPSHOT_BLOCK_HEIGHT"
# set snapshot download url
SNAPSHOT_DOWNLOAD_URL=https://snapshots-testnet.stake-town.com/elys/elystestnet-1_latest.tar.lz4
echo "::set-output name=SNAPSHOT_DOWNLOAD_URL::$SNAPSHOT_DOWNLOAD_URL"
echo "SNAPSHOT_DOWNLOAD_URL=$SNAPSHOT_DOWNLOAD_URL" >> $GITHUB_ENV
cache-and-retrieve:
runs-on: ubuntu-latest
needs: checkout-and-setup
outputs:
CACHE_HIT: ${{ steps.cache-elys-folders.outputs.cache-hit }}
steps:
- name: Cache Directories
id: cache-elys-folders
uses: actions/cache@v4
with:
path: |
/tmp/elys-backup
/tmp/elys2-backup
key: ${{ runner.os }}-elys-folders-${{ needs.checkout-and-setup.outputs.LATEST_TAG }}
- name: Retrieve latest binary
run: |
DOWNLOAD_URL=https://github.com/elys-network/elys/releases/download/${{ needs.checkout-and-setup.outputs.LATEST_TAG }}/elysd-${{ needs.checkout-and-setup.outputs.LATEST_TAG }}-linux-amd64
OLD_BINARY_PATH=/tmp/elysd-${{ needs.checkout-and-setup.outputs.LATEST_TAG }}
curl -L $DOWNLOAD_URL -o $OLD_BINARY_PATH && chmod +x $OLD_BINARY_PATH
echo "OLD_BINARY_PATH=$OLD_BINARY_PATH" >> $GITHUB_ENV
- name: Create git tag
run: git tag v999.999.999
build-new-binaries:
runs-on: ubuntu-latest
needs: cache-and-retrieve
steps:
- name: Build new binaries
run: |
# build new elys binary
make build
NEW_BINARY_PATH=./build/elysd
echo "NEW_BINARY_PATH=$NEW_BINARY_PATH" >> $GITHUB_ENV
# build new upgrade assure binary
make build-upgrade-assure
NEW_UPGRADE_ASSURE_BINARY_PATH=./build/new-upgrade-assure
mv ./build/upgrade-assure $NEW_UPGRADE_ASSURE_BINARY_PATH
echo "NEW_UPGRADE_ASSURE_BINARY_PATH=$NEW_UPGRADE_ASSURE_BINARY_PATH" >> $GITHUB_ENV
# build upload snapshot binary
make build-upload-snapshot
UPLOAD_SNAPSHOT_BINARY_PATH=./build/upload-snapshot
echo "UPLOAD_SNAPSHOT_BINARY_PATH=$UPLOAD_SNAPSHOT_BINARY_PATH" >> $GITHUB_ENV
build-old-binaries:
runs-on: ubuntu-latest
needs: cache-and-retrieve
if: needs.cache-and-retrieve.outputs.CACHE_HIT != 'true'
steps:
- name: Copy upgrade assure folder
run: |
cp -a ./cmd/upgrade-assure ./cmd/upgrade-assure-skip
- name: Check out latest tag
run: git checkout ${{ needs.checkout-and-setup.outputs.LATEST_TAG }}
- name: Copy old upgrade assure types.go file
run: |
cp -a ./scripts/upgrade-assure/types.go ./cmd/upgrade-assure-skip/types.go
- name: Build old binaries
run: |
# build old upgrade assure binary
go build -o build ./cmd/upgrade-assure-skip
OLD_UPGRADE_ASSURE_BINARY_PATH=./build/old-upgrade-assure
mv ./build/upgrade-assure-skip $OLD_UPGRADE_ASSURE_BINARY_PATH
echo "OLD_UPGRADE_ASSURE_BINARY_PATH=$OLD_UPGRADE_ASSURE_BINARY_PATH" >> $GITHUB_ENV
chain-operations:
runs-on: ubuntu-latest
needs: build-old-binaries
if: needs.cache-and-retrieve.outputs.CACHE_HIT != 'true'
steps:
- name: Chain snapshot and export
run: |
GOMEMLIMIT=8GiB $OLD_UPGRADE_ASSURE_BINARY_PATH $SNAPSHOT_DOWNLOAD_URL $OLD_BINARY_PATH $NEW_BINARY_PATH \
--skip-chain-init \
--skip-node-start \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
- name: Chain initialization
run: |
GOMEMLIMIT=8GiB $OLD_UPGRADE_ASSURE_BINARY_PATH $SNAPSHOT_DOWNLOAD_URL $OLD_BINARY_PATH $NEW_BINARY_PATH \
--skip-snapshot \
--skip-node-start \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
create-validator:
runs-on: ubuntu-latest
needs: chain-operations
steps:
- name: Check out new branch
run: git checkout ${{ github.head_ref }}
- name: Create second validator
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
command: |
GOMEMLIMIT=8GiB $NEW_UPGRADE_ASSURE_BINARY_PATH $SNAPSHOT_DOWNLOAD_URL $OLD_BINARY_PATH $NEW_BINARY_PATH \
--skip-snapshot \
--skip-chain-init \
--skip-prepare-validator-data \
--skip-submit-proposal \
--skip-upgrade-to-new-binary \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
- name: Save up space
run: |
rm -rf ~/.elys/config/genesis.json
- name: Prepare second validator data
run: |
GOMEMLIMIT=8GiB $NEW_UPGRADE_ASSURE_BINARY_PATH $SNAPSHOT_DOWNLOAD_URL $OLD_BINARY_PATH $NEW_BINARY_PATH \
--skip-snapshot \
--skip-chain-init \
--skip-create-validator \
--skip-submit-proposal \
--skip-upgrade-to-new-binary \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
- name: Submit new proposal
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
command: |
GOMEMLIMIT=8GiB $NEW_UPGRADE_ASSURE_BINARY_PATH $SNAPSHOT_DOWNLOAD_URL $OLD_BINARY_PATH $NEW_BINARY_PATH \
--skip-snapshot \
--skip-chain-init \
--skip-create-validator \
--skip-prepare-validator-data \
--skip-upgrade-to-new-binary \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
backup-restore:
runs-on: ubuntu-latest
needs: create-validator
steps:
- name: Backup elys folders
run: |
cp -a $HOME/.elys /tmp/elys-backup
cp -a $HOME/.elys2 /tmp/elys2-backup
if: needs.cache-and-retrieve.outputs.CACHE_HIT != 'true'
- name: Restore elys folders from backup
run: |
mv /tmp/elys-backup $HOME/.elys
mv /tmp/elys2-backup $HOME/.elys2
if: needs.cache-and-retrieve.outputs.CACHE_HIT == 'true'
upgrade-binary:
runs-on: ubuntu-latest
needs: backup-restore
steps:
- name: Upgrade to new binary
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
command: |
GOMEMLIMIT=4GiB $NEW_UPGRADE_ASSURE_BINARY_PATH $SNAPSHOT_DOWNLOAD_URL $NEW_BINARY_PATH $NEW_BINARY_PATH \
--skip-snapshot \
--skip-chain-init \
--skip-create-validator \
--skip-prepare-validator-data \
--skip-submit-proposal \
--timeout-next-block 100000 \
--timeout-wait-for-node 100000
create-snapshot:
runs-on: ubuntu-latest
needs: upgrade-binary
steps:
- 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
tar -cf - .elys | lz4 -z - > "$NEW_SNAPSHOT_PATH"
- name: Upload snapshot
run: |
export R2_ACCESS_KEY=${{ secrets.R2_ACCESS_KEY }}
export R2_SECRET_KEY=${{ secrets.R2_SECRET_KEY }}
export R2_ENDPOINT=${{ secrets.R2_ENDPOINT }}
export R2_BUCKET_NAME=${{ secrets.R2_BUCKET_NAME }}
$UPLOAD_SNAPSHOT_BINARY_PATH $NEW_SNAPSHOT_PATH
- name: Remove snapshot file
run: |
rm -f $NEW_SNAPSHOT_PATH
- name: Info about the snapshot
run: |
echo "Snapshot URL: https://snapshots.elys.network/$NEW_SNAPSHOT_FILENAME"