-
Notifications
You must be signed in to change notification settings - Fork 0
337 lines (287 loc) · 10.4 KB
/
ci.yml
File metadata and controls
337 lines (287 loc) · 10.4 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
name: CI
on:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
backend-fmt:
name: Backend Format
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Format
run: cargo fmt --all --check
backend-clippy:
name: Backend Clippy
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Cache Cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: backend
- name: Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
backend-test:
name: Backend Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: backend
- name: Test
run: cargo test --workspace --all-targets
backend-cli-db-flow:
name: Backend CLI DB Flow
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: atlas
POSTGRES_USER: atlas
POSTGRES_PASSWORD: atlas
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U atlas -d atlas"
--health-interval 5s
--health-timeout 5s
--health-retries 5
defaults:
run:
working-directory: backend
env:
PG_ADMIN_URL: postgres://atlas:atlas@127.0.0.1:5432/postgres
SOURCE_DB_URL: postgres://atlas:atlas@127.0.0.1:5432/atlas
RESTORE_DB_URL: postgres://atlas:atlas@127.0.0.1:5432/atlas_restore
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: backend
- name: Install PostgreSQL client
run: sudo apt-get update && sudo apt-get install -y postgresql-client
- name: Exercise migrate, dump, and restore commands
run: |
set -euo pipefail
psql "$PG_ADMIN_URL" -c "DROP DATABASE IF EXISTS atlas_restore;"
psql "$PG_ADMIN_URL" -c "CREATE DATABASE atlas_restore;"
DATABASE_URL="$SOURCE_DB_URL" cargo run --quiet --bin atlas-server -- migrate
psql "$SOURCE_DB_URL" <<'SQL'
INSERT INTO blocks (
number, hash, parent_hash, timestamp, gas_used, gas_limit, transaction_count, indexed_at
) VALUES (
424242,
'0x0000000000000000000000000000000000000000000000000000000000067932',
'0x0000000000000000000000000000000000000000000000000000000000067931',
1700000000,
21000,
30000000,
1,
NOW()
)
ON CONFLICT (number) DO NOTHING;
INSERT INTO transactions (
hash, block_number, block_index, from_address, to_address, value, gas_price, gas_used,
input_data, status, timestamp
) VALUES (
'0x0000000000000000000000000000000000000000000000000000000000067933',
424242,
0,
'0x4242420000000000000000000000000000000001',
'0x4242420000000000000000000000000000000002',
1000000000000000000,
20000000000,
21000,
'\x',
true,
1700000000
)
ON CONFLICT (hash, block_number) DO NOTHING;
SQL
DUMP_FILE="$RUNNER_TEMP/atlas-cli-db-flow.dump"
DATABASE_URL="$SOURCE_DB_URL" cargo run --quiet --bin atlas-server -- db dump "$DUMP_FILE"
DATABASE_URL="$RESTORE_DB_URL" cargo run --quiet --bin atlas-server -- db restore "$DUMP_FILE"
DATABASE_URL="$RESTORE_DB_URL" cargo run --quiet --bin atlas-server -- migrate
test "$(psql "$RESTORE_DB_URL" -Atc "SELECT COUNT(*) FROM blocks WHERE number = 424242")" = "1"
test "$(psql "$RESTORE_DB_URL" -Atc "SELECT COUNT(*) FROM transactions WHERE hash = '0x0000000000000000000000000000000000000000000000000000000000067933'")" = "1"
backend-cli-snapshot-compat:
name: Backend CLI Snapshot Compatibility
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: atlas
POSTGRES_USER: atlas
POSTGRES_PASSWORD: atlas
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U atlas -d atlas"
--health-interval 5s
--health-timeout 5s
--health-retries 5
defaults:
run:
working-directory: backend
env:
PG_ADMIN_URL: postgres://atlas:atlas@127.0.0.1:5432/postgres
SOURCE_DB_URL: postgres://atlas:atlas@127.0.0.1:5432/atlas_compat_source
RESTORE_DB_URL: postgres://atlas:atlas@127.0.0.1:5432/atlas_compat_restore
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: backend
- name: Install PostgreSQL client
run: sudo apt-get update && sudo apt-get install -y postgresql-client
- name: Resolve compatibility baseline
id: baseline
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "sha=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
else
echo "sha=${{ github.event.before }}" >> "$GITHUB_OUTPUT"
fi
- name: Restore a snapshot created from the previous revision
id: compat
continue-on-error: true
run: |
set -euo pipefail
BASE_SHA="${{ steps.baseline.outputs.sha }}"
if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
echo "No prior revision is available for snapshot compatibility testing."
exit 0
fi
BASE_WORKTREE="$RUNNER_TEMP/atlas-base"
DUMP_FILE="$RUNNER_TEMP/atlas-compat.dump"
git worktree add "$BASE_WORKTREE" "$BASE_SHA"
trap 'git worktree remove --force "$BASE_WORKTREE"' EXIT
psql "$PG_ADMIN_URL" -c "DROP DATABASE IF EXISTS atlas_compat_source;"
psql "$PG_ADMIN_URL" -c "DROP DATABASE IF EXISTS atlas_compat_restore;"
psql "$PG_ADMIN_URL" -c "CREATE DATABASE atlas_compat_source;"
psql "$PG_ADMIN_URL" -c "CREATE DATABASE atlas_compat_restore;"
HELPER_DIR="$RUNNER_TEMP/base-migrate-helper"
mkdir -p "$HELPER_DIR/src"
cat > "$HELPER_DIR/Cargo.toml" <<EOF
[package]
name = "base-migrate-helper"
version = "0.1.0"
edition = "2021"
[dependencies]
atlas-common = { path = "$BASE_WORKTREE/backend/crates/atlas-common" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
EOF
cat > "$HELPER_DIR/src/main.rs" <<'EOF'
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let database_url = std::env::args().nth(1).expect("database url argument");
atlas_common::db::run_migrations(&database_url).await?;
Ok(())
}
EOF
cargo run --quiet --manifest-path "$HELPER_DIR/Cargo.toml" -- "$SOURCE_DB_URL"
psql "$SOURCE_DB_URL" <<'SQL'
INSERT INTO blocks (
number, hash, parent_hash, timestamp, gas_used, gas_limit, transaction_count, indexed_at
) VALUES (
515151,
'0x000000000000000000000000000000000000000000000000000000000007db4f',
'0x000000000000000000000000000000000000000000000000000000000007db4e',
1700001000,
21000,
30000000,
1,
NOW()
)
ON CONFLICT (number) DO NOTHING;
SQL
pg_dump --dbname="$SOURCE_DB_URL" --format=custom --file "$DUMP_FILE"
DATABASE_URL="$RESTORE_DB_URL" cargo run --quiet --bin atlas-server -- db restore "$DUMP_FILE"
DATABASE_URL="$RESTORE_DB_URL" cargo run --quiet --bin atlas-server -- migrate
test "$(psql "$RESTORE_DB_URL" -Atc "SELECT COUNT(*) FROM blocks WHERE number = 515151")" = "1"
- name: Warn when snapshot compatibility fails
if: always() && steps.compat.outcome == 'failure'
run: |
echo "::warning::Snapshot compatibility check failed. Review the 'Backend CLI Snapshot Compatibility' job before release."
{
echo "## Snapshot compatibility warning"
echo
echo "The previous-revision dump/restore drill failed in CI."
echo "The workflow stayed green, but this should be reviewed before release."
} >> "$GITHUB_STEP_SUMMARY"
frontend:
name: Frontend (Bun)
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install
run: bun install --frozen-lockfile
- name: Lint
run: bun run lint
- name: Build
run: bun run build
docker:
name: Docker (GHCR)
needs: [backend-fmt, backend-clippy, backend-test, backend-cli-db-flow, frontend]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: ./.github/workflows/docker-build-push.yml
secrets: inherit
permissions:
contents: read
packages: write
with:
image-tag: main
apps: |
[
{"name": "atlas-oss-server", "context": "backend", "dockerfile": "backend/Dockerfile", "target": "server"},
{"name": "atlas-oss-frontend", "context": "frontend", "dockerfile": "frontend/Dockerfile", "target": ""}
]