-
Notifications
You must be signed in to change notification settings - Fork 19
155 lines (129 loc) · 5.29 KB
/
update-snapshot.yml
File metadata and controls
155 lines (129 loc) · 5.29 KB
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
name: Update Snapshots
on:
workflow_dispatch:
permissions:
contents: write # required for push commit
pull-requests: write # required for create pr
env:
GH_TOKEN: ${{ github.token }}
jobs:
define-matrix:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
networks: ${{ steps.networks.outputs.networks }}
steps:
- uses: actions/checkout@v5
- name: Generate network matrix
id: networks
run: echo "networks=$(node scripts/generate-ci-matrix.mjs)" >> "$GITHUB_OUTPUT"
update:
needs: define-matrix
runs-on: ubuntu-latest
timeout-minutes: 240
strategy:
fail-fast: false
matrix:
network: ${{ fromJSON(needs.define-matrix.outputs.networks) }}
steps:
- uses: actions/checkout@v5
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 22.x
cache: 'yarn'
- run: yarn --immutable
- name: Install Subway
run: |
docker create --name subway-extract acala/subway:v0.1.1
sudo docker cp subway-extract:/usr/local/bin/subway /usr/local/bin/subway
docker rm subway-extract
sudo chmod +x /usr/local/bin/subway
subway --version
- name: Update known good block numbers
run: yarn update-known-good
- name: Source known good block numbers
run: |
NETWORK_UPPER=$(echo "${{ matrix.network.name }}" | tr '[:lower:]' '[:upper:]')
ENV_FILE="KNOWN_GOOD_BLOCK_NUMBERS_${NETWORK_UPPER}.env"
echo "Sourcing block numbers from $ENV_FILE"
cat "$ENV_FILE" >> $GITHUB_ENV
- name: Start all Subway instances
run: |
echo "Starting all Subway instances for ${{ matrix.network.name }}..."
echo '${{ toJSON(matrix.network.chains) }}' | jq -c '.[]' | while read chain; do
CHAIN=$(echo $chain | jq -r '.chain')
PORT=$(echo $chain | jq -r '.port')
# Get endpoints from pet-chain-endpoints.json
ENDPOINTS=$(jq -c ".$CHAIN" packages/networks/src/pet-chain-endpoints.json)
if [ "$ENDPOINTS" = "null" ] || [ -z "$ENDPOINTS" ]; then
echo "Error: No endpoints found for chain $CHAIN"
exit 1
fi
echo "Starting Subway for $CHAIN on port $PORT..."
sed -e "s/{{PORT}}/$PORT/g" -e "s|{{ENDPOINTS}}|$ENDPOINTS|g" .github/subway-template.yml > /tmp/subway-$PORT.yml
subway --config /tmp/subway-$PORT.yml > /tmp/subway-$PORT.log 2>&1 &
echo $! >> /tmp/subway.pids
done
echo "Waiting for all Subway instances to start..."
echo '${{ toJSON(matrix.network.chains) }}' | jq -c '.[]' | while read chain; do
PORT=$(echo $chain | jq -r '.port')
timeout=60
elapsed=0
while [ $elapsed -lt $timeout ]; do
if curl -sf http://127.0.0.1:$PORT/health > /dev/null 2>&1; then
echo "Subway on port $PORT started successfully!"
break
fi
sleep 1
elapsed=$((elapsed + 1))
done
if [ $elapsed -ge $timeout ]; then
echo "Timeout waiting for subway on port $PORT"
cat /tmp/subway-$PORT.log
exit 1
fi
done
echo "All Subway instances started successfully!"
- name: Set endpoint environment variables
run: |
echo '${{ toJSON(matrix.network.chains) }}' | jq -c '.[]' | while read chain; do
ENDPOINT_VAR=$(echo $chain | jq -r '.endpoint_var')
PORT=$(echo $chain | jq -r '.port')
echo "${ENDPOINT_VAR}=ws://localhost:${PORT}" >> $GITHUB_ENV
done
- name: Run Tests
run: yarn test:${{ matrix.network.name }} -u --pool=threads --maxWorkers=2 --retry=3
- name: Cleanup Subway instances
if: always()
run: |
if [ -f /tmp/subway.pids ]; then
cat /tmp/subway.pids | xargs kill || true
fi
- name: Commit and Create PR
uses: actions/github-script@v8
with:
script: |
const { network } = context.payload.inputs || { network: '${{ matrix.network.name }}' };
const branchName = `update-snapshots-${network}-${context.sha.slice(0, 7)}`;
const upperNetwork = network.toUpperCase();
await exec.exec(`git config --global user.name 'github-actions[bot]'`);
await exec.exec(`git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'`);
const { stdout: status } = await exec.getExecOutput('git', ['status', '--porcelain']);
if (!status) {
console.log('No changes to commit.');
return;
}
await exec.exec(`git checkout -b ${branchName}`);
await exec.exec('git', ['add', '-A', `packages/${network}`]);
await exec.exec('git', ['add', '-A', `KNOWN_GOOD_BLOCK_NUMBERS_${upperNetwork}.env`]);
await exec.exec('git', ['commit', '-m', `Update snapshots for ${network}`]);
await exec.exec(`git push origin HEAD:${branchName}`);
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Update Snapshots for ${network}`,
head: branchName,
base: 'master',
body: `Update Snapshots for ${network}\n\nClose and reopen this PR to trigger CI.`,
});