Skip to content

Commit 272a149

Browse files
authored
ci: run only the jobs of the packages a change touched (#54)
1 parent 49287e2 commit 272a149

4 files changed

Lines changed: 277 additions & 33 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 167 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,104 @@ permissions:
99
contents: read
1010

1111
jobs:
12+
# Which packages this run touched, so each job below runs only for them.
13+
# A pull request runs the jobs for the packages whose files changed, plus
14+
# every job when a shared file changed (the lockfile, the workspace file, a
15+
# root config, this workflow) or when the engine changed, since every
16+
# destination depends on it. A push to main and a release PR run everything.
17+
changes:
18+
name: Changed packages
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
pull-requests: read
23+
outputs:
24+
engine: ${{ steps.decide.outputs.engine }}
25+
postgres: ${{ steps.decide.outputs.postgres }}
26+
mongodb: ${{ steps.decide.outputs.mongodb }}
27+
mysql: ${{ steps.decide.outputs.mysql }}
28+
clickhouse: ${{ steps.decide.outputs.clickhouse }}
29+
steps:
30+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
31+
with:
32+
persist-credentials: false
33+
34+
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
35+
id: filter
36+
with:
37+
filters: |
38+
shared:
39+
- package.json
40+
- pnpm-lock.yaml
41+
- pnpm-workspace.yaml
42+
- tsconfig*.json
43+
- .oxlintrc.json
44+
- .oxfmtrc.json
45+
- .npmrc
46+
- .github/workflows/ci.yml
47+
engine:
48+
- packages/sync-engine/**
49+
postgres:
50+
- packages/sync-postgres/**
51+
- examples/**
52+
mongodb:
53+
- packages/sync-mongodb/**
54+
mysql:
55+
- packages/sync-mysql/**
56+
clickhouse:
57+
- packages/sync-clickhouse/**
58+
59+
- name: Decide
60+
id: decide
61+
env:
62+
EVENT: ${{ github.event_name }}
63+
HEAD_REF: ${{ github.head_ref }}
64+
SHARED: ${{ steps.filter.outputs.shared }}
65+
ENGINE: ${{ steps.filter.outputs.engine }}
66+
POSTGRES: ${{ steps.filter.outputs.postgres }}
67+
MONGODB: ${{ steps.filter.outputs.mongodb }}
68+
MYSQL: ${{ steps.filter.outputs.mysql }}
69+
CLICKHOUSE: ${{ steps.filter.outputs.clickhouse }}
70+
run: |
71+
all=false
72+
case "$EVENT" in push) all=true ;; esac
73+
case "$HEAD_REF" in release-please--*) all=true ;; esac
74+
if [ "$SHARED" = "true" ] || [ "$ENGINE" = "true" ]; then all=true; fi
75+
{
76+
echo "engine=$all"
77+
for d in postgres mongodb mysql clickhouse; do
78+
v=$(eval "echo \$$(echo "$d" | tr '[:lower:]' '[:upper:]')")
79+
if [ "$all" = "true" ] || [ "$v" = "true" ]; then echo "$d=true"; else echo "$d=false"; fi
80+
done
81+
} >> "$GITHUB_OUTPUT"
82+
echo "all=$all shared=$SHARED engine=$ENGINE postgres=$POSTGRES mongodb=$MONGODB mysql=$MYSQL clickhouse=$CLICKHOUSE"
83+
84+
# Each job below runs its steps only for a package this run touched. The
85+
# jobs themselves always run: a job skipped by a job-level condition is
86+
# skipped before its matrix expands, so the checks the branch rules
87+
# require by name (`Engine Node 22`, ...) would never be reported.
1288
engine:
1389
name: Engine Node ${{ matrix.node }}
90+
needs: changes
1491
runs-on: ubuntu-latest
1592
strategy:
1693
fail-fast: false
1794
matrix:
1895
node: [22, 24]
1996
steps:
2097
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
98+
if: needs.changes.outputs.engine == 'true'
2199
with:
22100
persist-credentials: false
23101

24102
# Package-manager setup comes first so Socket Firewall configures the
25103
# registry pnpm will actually use. The pnpm version is read from the
26104
# `packageManager` field in package.json.
27105
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
106+
if: needs.changes.outputs.engine == 'true'
28107

29108
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
109+
if: needs.changes.outputs.engine == 'true'
30110
with:
31111
node-version: ${{ matrix.node }}
32112

@@ -40,48 +120,63 @@ jobs:
40120
# allow-external-fork-fallback: true
41121

42122
- name: Install
123+
if: needs.changes.outputs.engine == 'true'
43124
run: pnpm install --frozen-lockfile
44125

45126
- name: Test
127+
if: needs.changes.outputs.engine == 'true'
46128
run: pnpm --filter @workos/sync-engine test
47129

48130
- name: Build
131+
if: needs.changes.outputs.engine == 'true'
49132
run: pnpm --filter @workos/sync-engine build
50133

134+
- name: Typecheck
135+
if: needs.changes.outputs.engine == 'true'
136+
run: pnpm --filter @workos/sync-engine typecheck
137+
51138
postgres:
52139
name: Postgres Node ${{ matrix.node }}
140+
needs: changes
53141
runs-on: ubuntu-latest
54142
strategy:
55143
fail-fast: false
56144
matrix:
57145
node: [22, 24]
58-
services:
59-
postgres:
60-
image: postgres:17-alpine
61-
env:
62-
POSTGRES_HOST_AUTH_METHOD: trust
63-
ports:
64-
- 127.0.0.1:5432:5432
65-
options: >-
66-
--health-cmd "pg_isready -U postgres"
67-
--health-interval 5s
68-
--health-timeout 5s
69-
--health-retries 10
70146
env:
71147
# Most of the suite runs on embedded PGlite; the multi-connection
72148
# regressions need a real server and skip themselves without this.
73149
TEST_DATABASE_URL: postgres://postgres@127.0.0.1:5432/postgres
74150
steps:
75151
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
152+
if: needs.changes.outputs.postgres == 'true'
76153
with:
77154
persist-credentials: false
78155

156+
# Started here rather than as a service container: a service starts
157+
# before the gate, so a PR that does not touch this package would
158+
# still boot a database for every Node version.
159+
- name: Start Postgres
160+
if: needs.changes.outputs.postgres == 'true'
161+
run: |
162+
docker run -d --name postgres -p 127.0.0.1:5432:5432 \
163+
-e POSTGRES_HOST_AUTH_METHOD=trust postgres:17-alpine
164+
for _ in $(seq 1 60); do
165+
if docker exec postgres pg_isready -U postgres >/dev/null 2>&1; then exit 0; fi
166+
sleep 1
167+
done
168+
echo "Postgres did not become ready" >&2
169+
docker logs postgres >&2
170+
exit 1
171+
79172
# Package-manager setup comes first so Socket Firewall configures the
80173
# registry pnpm will actually use. The pnpm version is read from the
81174
# `packageManager` field in package.json.
82175
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
176+
if: needs.changes.outputs.postgres == 'true'
83177

84178
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
179+
if: needs.changes.outputs.postgres == 'true'
85180
with:
86181
node-version: ${{ matrix.node }}
87182

@@ -95,100 +190,137 @@ jobs:
95190
# allow-external-fork-fallback: true
96191

97192
- name: Install
193+
if: needs.changes.outputs.postgres == 'true'
98194
run: pnpm install --frozen-lockfile
99195

100196
- name: Test
197+
if: needs.changes.outputs.postgres == 'true'
101198
run: pnpm --filter @workos/sync-postgres test
102199

103200
- name: Build
201+
if: needs.changes.outputs.postgres == 'true'
104202
run: pnpm --filter "@workos/sync-postgres..." build
105203

204+
- name: Typecheck
205+
if: needs.changes.outputs.postgres == 'true'
206+
run: |
207+
pnpm --filter @workos/sync-postgres typecheck
208+
pnpm --filter workos-sync-postgres-example typecheck
209+
106210
# The whole lifecycle — schema, backfill, tail, reconcile, repair —
107211
# against the fake API and an embedded Postgres, through the built
108212
# packages rather than the sources the unit tests import.
109213
- name: End-to-end example
214+
if: needs.changes.outputs.postgres == 'true'
110215
run: pnpm --filter workos-sync-postgres-example start
111216

112217
mongodb:
113218
name: MongoDB Node ${{ matrix.node }}
219+
needs: changes
114220
runs-on: ubuntu-latest
115221
strategy:
116222
fail-fast: false
117223
matrix:
118224
node: [22, 24]
119225
steps:
120226
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
227+
if: needs.changes.outputs.mongodb == 'true'
121228
with:
122229
persist-credentials: false
123230

124231
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
232+
if: needs.changes.outputs.mongodb == 'true'
125233

126234
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
235+
if: needs.changes.outputs.mongodb == 'true'
127236
with:
128237
node-version: ${{ matrix.node }}
129238

130239
# The suite runs on an embedded mongod (mongodb-memory-server), which
131240
# downloads the binary on first use; the cache keeps that off the
132241
# critical path. The version is pinned in the package's package.json.
133242
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
243+
if: needs.changes.outputs.mongodb == 'true'
134244
with:
135245
path: ~/.cache/mongodb-binaries
136246
key: mongodb-binaries-${{ runner.os }}-${{ hashFiles('packages/sync-mongodb/package.json') }}
137247

138248
- name: Install
249+
if: needs.changes.outputs.mongodb == 'true'
139250
run: pnpm install --frozen-lockfile
140251

141252
- name: Test
253+
if: needs.changes.outputs.mongodb == 'true'
142254
run: pnpm --filter @workos/sync-mongodb test
143255

144256
- name: Build
257+
if: needs.changes.outputs.mongodb == 'true'
145258
run: pnpm --filter "@workos/sync-mongodb..." build
146259

260+
- name: Typecheck
261+
if: needs.changes.outputs.mongodb == 'true'
262+
run: pnpm --filter @workos/sync-mongodb typecheck
263+
147264
mysql:
148265
name: MySQL Node ${{ matrix.node }}
266+
needs: changes
149267
runs-on: ubuntu-latest
150268
strategy:
151269
fail-fast: false
152270
matrix:
153271
node: [22, 24]
154-
services:
155-
mysql:
156-
image: mysql:8.4
157-
env:
158-
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
159-
ports:
160-
- 127.0.0.1:3306:3306
161-
options: >-
162-
--health-cmd "mysqladmin ping -h 127.0.0.1"
163-
--health-interval 5s
164-
--health-timeout 5s
165-
--health-retries 20
166272
env:
167273
# There is no embedded MySQL, so the whole suite runs against the
168274
# service; without this variable the database-backed tests skip.
169275
TEST_MYSQL_URL: mysql://root@127.0.0.1:3306
170276
steps:
171277
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
278+
if: needs.changes.outputs.mysql == 'true'
172279
with:
173280
persist-credentials: false
174281

282+
# Started here rather than as a service container, for the reason the
283+
# Postgres job gives.
284+
- name: Start MySQL
285+
if: needs.changes.outputs.mysql == 'true'
286+
run: |
287+
docker run -d --name mysql -p 127.0.0.1:3306:3306 \
288+
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:8.4
289+
for _ in $(seq 1 90); do
290+
if docker exec mysql mysqladmin ping -h 127.0.0.1 --silent >/dev/null 2>&1; then exit 0; fi
291+
sleep 1
292+
done
293+
echo "MySQL did not become ready" >&2
294+
docker logs mysql >&2
295+
exit 1
296+
175297
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
298+
if: needs.changes.outputs.mysql == 'true'
176299

177300
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
301+
if: needs.changes.outputs.mysql == 'true'
178302
with:
179303
node-version: ${{ matrix.node }}
180304

181305
- name: Install
306+
if: needs.changes.outputs.mysql == 'true'
182307
run: pnpm install --frozen-lockfile
183308

184309
- name: Test
310+
if: needs.changes.outputs.mysql == 'true'
185311
run: pnpm --filter @workos/sync-mysql test:database
186312

187313
- name: Build
314+
if: needs.changes.outputs.mysql == 'true'
188315
run: pnpm --filter "@workos/sync-mysql..." build
189316

317+
- name: Typecheck
318+
if: needs.changes.outputs.mysql == 'true'
319+
run: pnpm --filter @workos/sync-mysql typecheck
320+
190321
clickhouse:
191322
name: ClickHouse Node ${{ matrix.node }}
323+
needs: changes
192324
runs-on: ubuntu-latest
193325
strategy:
194326
fail-fast: false
@@ -200,13 +332,15 @@ jobs:
200332
TEST_CLICKHOUSE_URL: http://default@127.0.0.1:8123
201333
steps:
202334
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
335+
if: needs.changes.outputs.clickhouse == 'true'
203336
with:
204337
persist-credentials: false
205338

206339
# Not a service container: those start before the checkout, and the
207340
# server needs the config in test/clickhouse/ — an embedded Keeper for
208341
# the KeeperMap bookkeeping tables and `keeper_map_path_prefix`.
209342
- name: Start ClickHouse
343+
if: needs.changes.outputs.clickhouse == 'true'
210344
run: |
211345
docker run -d --name clickhouse -p 127.0.0.1:8123:8123 \
212346
-v "$PWD/packages/sync-clickhouse/test/clickhouse/config.xml:/etc/clickhouse-server/config.d/sync.xml:ro" \
@@ -223,16 +357,25 @@ jobs:
223357
exit 1
224358
225359
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
360+
if: needs.changes.outputs.clickhouse == 'true'
226361

227362
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
363+
if: needs.changes.outputs.clickhouse == 'true'
228364
with:
229365
node-version: ${{ matrix.node }}
230366

231367
- name: Install
368+
if: needs.changes.outputs.clickhouse == 'true'
232369
run: pnpm install --frozen-lockfile
233370

234371
- name: Test
372+
if: needs.changes.outputs.clickhouse == 'true'
235373
run: pnpm --filter @workos/sync-clickhouse test:database
236374

237375
- name: Build
376+
if: needs.changes.outputs.clickhouse == 'true'
238377
run: pnpm --filter "@workos/sync-clickhouse..." build
378+
379+
- name: Typecheck
380+
if: needs.changes.outputs.clickhouse == 'true'
381+
run: pnpm --filter @workos/sync-clickhouse typecheck

0 commit comments

Comments
 (0)