-
Notifications
You must be signed in to change notification settings - Fork 0
242 lines (203 loc) · 7.31 KB
/
Copy pathci.yml
File metadata and controls
242 lines (203 loc) · 7.31 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
name: CI
on:
push:
branches: [main]
pull_request:
# Cancel superseded runs on the same ref.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Least privilege: this workflow only needs to read the repo.
permissions:
contents: read
env:
MIX_ENV: test
# Erlang, Elixir, and Node versions come from `mise.toml` (installed by
# mise-action below), so local dev and CI stay in lockstep.
jobs:
build:
name: Compile · lint · test · dialyzer
runs-on: ubuntu-latest
services:
postgres:
# Pinned inline: GitHub Actions doesn't allow the `env` context in a
# service `image:`. Postgres isn't a mise runtime, so it's the one
# version CI pins on its own.
image: postgres:18-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: elixir_react_starter_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
# Actions are pinned to commit SHAs (GitHub's supply-chain
# recommendation). The trailing comment is the human-readable tag;
# let Dependabot bump both together.
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
# Installs Erlang, Elixir, and Node from mise.toml — the same file
# developers use locally. `cache: true` caches the toolchain so the
# one-time Erlang source compile doesn't repeat on every run.
- name: Set up Erlang / Elixir / Node (mise)
uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0
with:
cache: true
- name: Install hex + rebar
run: |
mix local.hex --force
mix local.rebar --force
- name: Cache npm
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('assets/package-lock.json') }}
restore-keys: ${{ runner.os }}-npm-
- name: Cache deps and _build
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Cache dialyzer PLTs
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: priv/plts
key: ${{ runner.os }}-plt-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-plt-
- name: Install Elixir deps
run: mix deps.get
- name: Install JS deps
run: npm ci
working-directory: assets
- name: Compile (warnings as errors)
run: mix compile --warnings-as-errors
- name: Check formatting
run: mix format --check-formatted
- name: Check for unused deps
run: mix deps.unlock --check-unused
- name: Lint (credo + biome)
run: mix lint
- name: i18n check
run: mix i18n.check
- name: Test
run: mix test --cover
- name: Dialyzer
run: mix dialyzer
e2e:
name: E2E (Playwright)
runs-on: ubuntu-latest
# The Playwright suite drives a real server, so it runs in :dev (the env
# that exposes /dev/e2e/users, the Swoosh mailbox JSON, and port 4000) —
# not :test. Override the workflow-level MIX_ENV=test for this job only.
env:
MIX_ENV: dev
services:
postgres:
image: postgres:18-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
# E2E runs against the dev database (see MIX_ENV above).
POSTGRES_DB: elixir_react_starter_dev
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Set up Erlang / Elixir / Node (mise)
uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0
with:
cache: true
- name: Install hex + rebar
run: |
mix local.hex --force
mix local.rebar --force
- name: Cache npm
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('assets/package-lock.json') }}
restore-keys: ${{ runner.os }}-npm-
# Keyed on MIX_ENV so the dev build artefacts don't clobber the build
# job's test PLT/_build cache (different env, different compiled output).
- name: Cache deps and _build
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-dev-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-mix-dev-
- name: Install Elixir deps
run: mix deps.get
- name: Install JS deps
run: npm ci
working-directory: assets
- name: Cache Playwright browsers
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('assets/package-lock.json') }}
restore-keys: ${{ runner.os }}-playwright-
- name: Install Playwright browser (chromium + system deps)
run: npx playwright install --with-deps chromium
working-directory: assets
- name: Set up database
run: |
mix ecto.create
mix ecto.migrate
# Build the browser bundle and priv/ssr.js once, up front. The server
# then runs with watchers off (see DISABLE_WATCHERS below), so a request
# can never land mid-rebuild and trip Inertia's raise_on_ssr_failure.
- name: Build assets
run: |
mix assets.setup
mix assets.build
- name: Start Phoenix server
env:
DISABLE_WATCHERS: "true"
run: |
mix phx.server > /tmp/phx-server.log 2>&1 &
echo "Waiting for http://localhost:4000 to come up..."
for _ in $(seq 1 60); do
if curl -sSf http://localhost:4000/login > /dev/null 2>&1; then
echo "Server is up."
exit 0
fi
sleep 2
done
echo "::error::Phoenix server did not become ready within 120s"
cat /tmp/phx-server.log
exit 1
- name: Run Playwright tests
working-directory: assets
run: npm run e2e
- name: Dump server log on failure
if: failure()
run: cat /tmp/phx-server.log || true
- name: Upload Playwright report
if: ${{ !cancelled() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: playwright-report
path: |
assets/playwright-report/
assets/test-results/
retention-days: 7