-
Notifications
You must be signed in to change notification settings - Fork 1
245 lines (213 loc) · 8.21 KB
/
ci.yml
File metadata and controls
245 lines (213 loc) · 8.21 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
name: CI/CD
permissions:
contents: read
on:
push:
branches: [main]
tags: ["v*"]
# Skip the run entirely when only doc / Claude / screenshot paths
# change — none of these end up in the published image, and the
# Docker build + Playwright runs are the slow ones to spin up. A
# change that mixes a doc edit with a real source edit still
# triggers, because GitHub triggers when *any* changed path is
# outside this list.
paths-ignore:
- '**/*.md'
- 'docs/**'
- 'LICENSE'
- 'scripts/take_screenshots.js'
pull_request:
branches: [main]
paths-ignore:
- '**/*.md'
- 'docs/**'
- 'LICENSE'
- 'scripts/take_screenshots.js'
workflow_dispatch:
inputs:
tag:
description: "Extra tag alongside :latest (e.g. v1.2.0). Leave blank for just :latest."
required: false
default: ""
jobs:
# Detect which top-level areas changed so downstream jobs can skip
# expensive work (Docker build, Cloudflare deploy) when irrelevant.
changes:
runs-on: ubuntu-latest
outputs:
app: ${{ steps.filter.outputs.app }}
relay: ${{ steps.filter.outputs.relay }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v4
id: filter
with:
filters: |
app:
- 'dotnet/**'
- 'app/**'
- 'scripts/fetch_plane_shapes.py'
relay:
- 'relay-worker/**'
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: Restore
working-directory: dotnet
run: dotnet restore FlightJar.slnx
- name: Format check
working-directory: dotnet
run: dotnet format FlightJar.slnx --verify-no-changes --no-restore
- name: Build
working-directory: dotnet
run: dotnet build FlightJar.slnx -c Release --no-restore /p:TreatWarningsAsErrors=true
- name: Test
working-directory: dotnet
run: dotnet test FlightJar.slnx -c Release --no-build --logger "console;verbosity=normal"
- uses: actions/setup-node@v6
with:
node-version: "22"
- name: Node tests (frontend modules)
# Glob expanded by bash — Node 22 stopped treating the bare
# directory path as a discovery target and tries to resolve it
# as a single module instead.
run: node --test tests/js/*.test.js
- name: Relay worker type check
working-directory: relay-worker
run: npm install && npm run check
e2e:
# Playwright smoke suite against the real .NET backend in its
# no-BEAST harness mode (see playwright.config.js webServer env).
# Runs in parallel with `check`; `publish` gates on this one too
# so a broken UI also blocks the image push.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- uses: actions/setup-node@v6
with:
node-version: "22"
# Cache the Playwright browser binaries across runs. npm install
# doesn't need its own cache since we deliberately don't commit a
# lockfile (single dep, resolves fast; no cross-CI reproducibility
# concern). The cache key includes the @playwright/test version
# pinned in package.json so a bump invalidates cleanly.
- name: Cache Playwright browsers
uses: actions/cache@v5
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ hashFiles('package.json') }}
- name: Install Playwright + Chromium
run: |
npm install
npx playwright install --with-deps chromium
- name: Stage auto-generated assets
# tar1090 silhouettes aren't committed; fetch them so the app serves
# a complete page. Python interpreter is preinstalled on GitHub runners.
env:
TAR1090_SHAPES_DEST: ${{ github.workspace }}/app/static/tar1090_shapes.js
TAR1090_TYPES_DEST: ${{ github.workspace }}/app/static/icao_aircraft_types.js
run: python3 scripts/fetch_plane_shapes.py
- name: Publish backend for Playwright
run: dotnet publish dotnet/src/FlightJar.Api/FlightJar.Api.csproj -c Release -o dotnet-publish
- name: Playwright tests
run: npm run test:e2e
- name: Upload report on failure
if: failure()
uses: actions/upload-artifact@v7
with:
name: playwright-report
path: playwright-report/
retention-days: 7
publish:
# Build + push the Docker image only when application files changed
# (dotnet/, app/, fetch_plane_shapes.py). A relay-worker-only push
# skips this job and goes straight to deploy-relay instead.
needs: [check, e2e, changes]
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' &&
needs.changes.outputs.app == 'true' &&
(github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/tags/v')))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: docker/setup-qemu-action@v4
- uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Compute image tags
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/flightjar
tags: |
type=raw,value=latest
type=sha,format=short,prefix=git-
type=semver,pattern={{version}}
type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}
# Rolling weekly key for the upstream-data layer in the Dockerfile.
# Per-commit pushes hit the cache (so a code-only change doesn't
# re-pull aircraft_db / airports / navaids / airlines / shapes);
# a real upstream change comes in within 7 days. Bump-on-demand:
# change this format string or trigger a workflow_dispatch with
# --no-cache equivalent.
- name: Compute weekly data cachebust
id: cachebust
run: echo "value=$(date -u +%Y-W%V)" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
file: dotnet/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# DATA_CACHEBUST is a weekly ISO-week string (YYYY-WNN) so
# commits don't re-pull unchanged upstream files but a real
# upstream change comes in within ~7 days. Everything else
# (dotnet publish, static-asset copy) still caches normally
# between builds. FLIGHTJAR_VERSION stamps the image with
# the commit that produced it; /api/stats exposes it and the
# About dialog shows the short form next to the title.
build-args: |
DATA_CACHEBUST=${{ steps.cachebust.outputs.value }}
FLIGHTJAR_VERSION=${{ github.sha }}
POSTHOG_API_KEY=${{ vars.POSTHOG_API_KEY }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy-relay:
# Deploy the Cloudflare Worker relay when relay-worker/ files change.
# Gates on `check` so a TypeScript error blocks the deploy.
needs: [check, changes]
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' &&
needs.changes.outputs.relay == 'true' &&
github.ref == 'refs/heads/main')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: "22"
- name: Install dependencies
working-directory: relay-worker
run: npm install
- name: Deploy to Cloudflare Workers
working-directory: relay-worker
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: npx wrangler deploy