1 name: Medusa Pipeline
2 on:
3 push:
4 branches:
5 - develop
6 - v1.x
7 pull_request:
8 branches:
9 - "**"
10
11 jobs:
12 setup:
13 runs-on: ubuntu-latest
14 env:
15 TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
16 TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
17 steps:
18 # Only ever cancels runs that are older AND share this run's head branch
19 # AND head repository AND have a *different* head SHA. That last guard is
20 # what makes the `!cancelled()` gates below safe: auto-cancellation can
21 # never strand the current head SHA with skipped (== passing, for a
22 # required check) gates, because a run on this exact SHA is never a
23 # cancellation target. Only a manual cancel can do that.
24 - name: Cancel Previous Runs
25 uses: styfle/cancel-workflow-action@0.11.0
26 with:
27 access_token: ${{ github.token }}
28
29 - name: Checkout
30 uses: actions/checkout@v4
31 with:
32 fetch-depth: 0
33
34 - name: Setup Node.js environment
35 uses: actions/setup-node@v4
36 with:
37 node-version: 22
38
39 - name: Assert changed
40 run: ./scripts/assert-changed-files-actions.sh "packages"
41
42 - name: Install dependencies
43 uses: ./.github/actions/cache-deps
44 with:
45 extension: pipeline
46
47 - name: Upload build artifacts
48 uses: actions/upload-artifact@v4
49 with:
50 name: build-artifacts
51 include-hidden-files: true
52 path: |
53 packages/**/dist
54 packages/plugins/*/.medusa/server
55 integration-tests/**/dist
56 !packages/**/node_modules
57 retention-days: 1
58
59 lint-medusa:
60 needs: setup
61 name: Lint (Medusa rules)
62 runs-on: ubuntu-latest
63 env:
64 TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
65 TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
66 steps:
67 - name: Checkout
68 uses: actions/checkout@v4
69 with:
70 fetch-depth: 100
71
72 - name: Install dependencies
73 uses: ./.github/actions/cache-deps
74 with:
75 extension: pipeline
76 skip-build: "true"
77
78 # The Medusa-only ESLint config resolves `@medusajs/eslint-plugin` from its
79 # built output, so build just that package.
80 - name: Build ESLint plugin
81 run: yarn workspace @medusajs/eslint-plugin build
82
83 # Runs ONLY the @medusajs/eslint-plugin convention rules (scope/rules from
84 # the root config, via eslint.medusa.cjs). ESLint exits non-zero on errors,
85 # so a Medusa rule error fails this check; warnings do not.
86 - name: Lint Medusa rules
87 run: yarn lint:medusa
88
89 admin-bundle:
90 needs: setup
91 name: Admin Bundle (Vite)
92 runs-on: ubuntu-latest
93 env:
94 TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
95 TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
96 steps:
97 - name: Checkout
98 uses: actions/checkout@v4
99 with:
100 fetch-depth: 100
101
102 - name: Install dependencies
103 uses: ./.github/actions/cache-deps
104 with:
105 extension: pipeline
106 skip-build: "true"
107
108 - name: Download build artifacts
109 uses: actions/download-artifact@v4
110 with:
111 name: build-artifacts
112 path: .
113
114 # @medusajs/admin-bundler is published as CommonJS, but `vite` (ESM-only
115 # since v6) and @vitejs/plugin-react (ESM-only since v5) can only be
116 # loaded through a genuine dynamic import(). If esbuild rewrites those to
117 # require(), the bundle still builds and typechecks — it only fails at
118 # runtime, with ERR_REQUIRE_ESM, for every `medusa develop` / `build` /
119 # `plugin:build`. Nothing else in CI would catch that.
120 - name: Assert admin-bundler loads ESM-only deps via import()
121 run: node ./packages/admin/admin-bundler/scripts/assert-esm-imports.mjs
122
123 - name: Assert admin-bundler is requireable from CommonJS
124 run: node -e 'require("./packages/admin/admin-bundler/dist/index.js")'
125
126 # `build:plugin` already runs during `setup` (root `yarn build` is
127 # `turbo run build build:plugin`), which exercises admin-bundler's Vite
128 # `build.lib` path. But a zero exit code does not prove both output
129 # formats were emitted, that externals stayed external, or that the
130 # emitted CJS interop is loadable.
131 - name: Assert plugin admin bundles
132 run: |
133 node ./scripts/assert-plugin-admin-bundle.mjs packages/plugins/draft-order
134 node ./scripts/assert-plugin-admin-bundle.mjs packages/plugins/loyalty
135
136 # The dashboard's own `build` script is tsgo + tsup, so a real `vite build`
137 # of the admin app runs nowhere else in CI. This targets a separate outDir
138 # (`dist-vite`), and runs after the steps above, so it cannot clobber the
139 # tsup output in `dist` that those steps depend on.
140 - name: Build admin dashboard with Vite
141 run: yarn workspace @medusajs/dashboard build:vite
142
143 - name: Assert admin dashboard bundle
144 run: |
145 test -f packages/admin/dashboard/dist-vite/index.html
146 grep -qE 'src="[^"]*/assets/index-[^"]+\.js"' packages/admin/dashboard/dist-vite/index.html
147 test -n "$(find packages/admin/dashboard/dist-vite/assets -name '*.css' -print -quit)"
148
149 unit-tests-matrix:
150 needs: setup
151 name: Unit Tests - Shard ${{ matrix.shard_index }}
152 runs-on: ubuntu-latest
153 strategy:
154 fail-fast: true
155 matrix:
156 shard_index: [1, 2, 3, 4]
157 env:
158 TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
159 TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
160 steps:
161 - name: Checkout
162 uses: actions/checkout@v4
163 with:
164 fetch-depth: 100
165
166 - name: Get number of CPU cores
167 id: cpu-cores
168 uses: SimenB/github-actions-cpu-cores@v2
169
170 - name: Install dependencies
171 uses: ./.github/actions/cache-deps
172 with:
173 extension: pipeline
174 skip-build: "true"
175
176 - name: Download build artifacts
177 uses: actions/download-artifact@v4
178 with:
179 name: build-artifacts
180 path: .
181
182 - name: Run unit tests
183 run: yarn test -- --shard=${{ matrix.shard_index }}/4 --maxWorkers=${{ steps.cpu-cores.outputs.count }} --passWithNoTests
184
185 unit-tests:
186 if: ${{ !cancelled() }}
187 runs-on: ubuntu-latest
188 needs: unit-tests-matrix
189 steps:
190 - run: exit 1
191 if: >-
192 ${{
193 contains(needs.unit-tests-matrix.result, 'failure')
194 || contains(needs.unit-tests-matrix.result, 'cancelled')
195 || contains(needs.unit-tests-matrix.result, 'skipped')
196 }}
197 - run: exit 0
198 if: ${{ contains(needs.unit-tests-matrix.result, 'success') }}
199
200 integration-tests-packages-matrix:
201 needs: setup
202 name: Package Integration Tests (${{ matrix.group }}) - Shard ${{ matrix.shard_index }}
203 runs-on: ubuntu-latest
204 strategy:
205 fail-fast: true
206 matrix:
207 group: ["slow", "fast"]
208 shard_index: [1, 2, 3]
209 env:
210 TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
211 TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
212
213 services:
214 redis:
215 image: redis
216 options: >-
217 --health-cmd "redis-cli ping"
218 --health-interval 1s
219 --health-timeout 10s
220 --health-retries 10
221 ports:
222 - 6379:6379
223 postgres:
224 image: postgres
225 env:
226 POSTGRES_PASSWORD: postgres
227 POSTGRES_USER: postgres
228 options: >-
229 --health-cmd pg_isready
230 --health-interval 1s
231 --health-timeout 10s
232 --health-retries 10
233 ports:
234 - 5432:5432
235
236 steps:
237 - name: Checkout
238 uses: actions/checkout@v4
239 with:
240 fetch-depth: 100
241
242 - name: Get number of CPU cores
243 id: cpu-cores
244 uses: SimenB/github-actions-cpu-cores@v2
245
246 - name: Install dependencies
247 uses: ./.github/actions/cache-deps
248 with:
249 extension: pipeline
250 skip-build: "true"
251
252 - name: Download build artifacts
253 uses: actions/download-artifact@v4
254 with:
255 name: build-artifacts
256 path: .
257
258 - name: Run package integration tests
259 run: yarn test:integration:packages:${{ matrix.group }} -- --shard=${{ matrix.shard_index }}/3 --maxWorkers=${{ steps.cpu-cores.outputs.count }}
260 env:
261 DB_PASSWORD: postgres
262 DB_USERNAME: postgres
263
264 integration-tests-packages:
265 if: ${{ !cancelled() }}
266 runs-on: ubuntu-latest
267 needs: integration-tests-packages-matrix
268 steps:
269 - run: exit 1
270 if: >-
271 ${{
272 contains(needs.integration-tests-packages-matrix.result, 'failure')
273 || contains(needs.integration-tests-packages-matrix.result, 'cancelled')
274 || contains(needs.integration-tests-packages-matrix.result, 'skipped')
275 }}
276 - run: exit 0
277 if: ${{ contains(needs.integration-tests-packages-matrix.result, 'success') }}
278
279 integration-tests-http-matrix:
280 needs: setup
281 name: HTTP Integration Tests - Shard ${{ matrix.shard_index }}
282 runs-on: ubuntu-latest
283 strategy:
284 fail-fast: true
285 matrix:
286 shard_index: [1, 2, 3, 4]
287 env:
288 TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
289 TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
290
291 services:
292 redis:
293 image: redis
294 options: >-
295 --health-cmd "redis-cli ping"
296 --health-interval 1s
297 --health-timeout 10s
298 --health-retries 10
299 ports:
300 - 6379:6379
301 postgres:
302 image: postgres
303 env:
304 POSTGRES_PASSWORD: postgres
305 POSTGRES_USER: postgres
306 options: >-
307 --health-cmd pg_isready
308 --health-interval 1s
309 --health-timeout 10s
310 --health-retries 10
311 ports:
312 - 5432:5432
313
314 steps:
315 - name: Checkout
316 uses: actions/checkout@v4
317 with:
318 fetch-depth: 100
319
320 - name: Get number of CPU cores
321 id: cpu-cores
322 uses: SimenB/github-actions-cpu-cores@v2
323
324 - name: Install dependencies
325 uses: ./.github/actions/cache-deps
326 with:
327 extension: pipeline
328 skip-build: "true"
329
330 - name: Download build artifacts
331 uses: actions/download-artifact@v4
332 with:
333 name: build-artifacts
334 path: .
335
336 - name: Run HTTP integration tests
337 run: yarn test:integration:http -- --shard=${{ matrix.shard_index }}/4 --maxWorkers=${{ steps.cpu-cores.outputs.count }}
338 env:
339 DB_USERNAME: postgres
340 DB_PASSWORD: postgres
341 NODE_OPTIONS: "--max_old_space_size=4096"
342
343 integration-tests-http:
344 if: ${{ !cancelled() }}
345 runs-on: ubuntu-latest
346 needs: integration-tests-http-matrix
347 steps:
348 - run: exit 1
349 if: >-
350 ${{
351 contains(needs.integration-tests-http-matrix.result, 'failure')
352 || contains(needs.integration-tests-http-matrix.result, 'cancelled')
353 || contains(needs.integration-tests-http-matrix.result, 'skipped')
354 }}
355 - run: exit 0
356 if: ${{ contains(needs.integration-tests-http-matrix.result, 'success') }}
357
358 integration-tests-modules-matrix:
359 needs: setup
360 name: Module Integration Tests - Shard ${{ matrix.shard_index }}
361 strategy:
362 matrix:
363 shard_index: [1, 2, 3, 4]
364 runs-on: ubuntu-latest
365 env:
366 TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
367 TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
368
369 services:
370 redis:
371 image: redis
372 options: >-
373 --health-cmd "redis-cli ping"
374 --health-interval 1s
375 --health-timeout 10s
376 --health-retries 10
377 ports:
378 - 6379:6379
379 postgres:
380 image: postgres
381 env:
382 POSTGRES_PASSWORD: postgres
383 POSTGRES_USER: postgres
384 options: >-
385 --health-cmd pg_isready
386 --health-interval 1s
387 --health-timeout 10s
388 --health-retries 10
389 ports:
390 - 5432:5432
391
392 steps:
393 - name: Checkout
394 uses: actions/checkout@v4
395 with:
396 fetch-depth: 100
397
398 - name: Get number of CPU cores
399 id: cpu-cores
400 uses: SimenB/github-actions-cpu-cores@v2
401
402 - name: Install dependencies
403 uses: ./.github/actions/cache-deps
404 with:
405 extension: pipeline
406 skip-build: "true"
407
408 - name: Download build artifacts
409 uses: actions/download-artifact@v4
410 with:
411 name: build-artifacts
412 path: .
413
414 - name: Run Modules integration tests
415 run: yarn test:integration:modules -- --shard=${{ matrix.shard_index }}/4 --maxWorkers=${{ steps.cpu-cores.outputs.count }}
416 env:
417 DB_USERNAME: postgres
418 DB_PASSWORD: postgres
419 NODE_OPTIONS: "--max_old_space_size=4096"
420 CHUNK: ${{ matrix.chunk }}
421 CHUNKS: ${{ needs.setup.outputs.module-chunks }}
422
423 integration-tests-modules:
424 if: ${{ !cancelled() }}
425 runs-on: ubuntu-latest
426 needs: integration-tests-modules-matrix
427 steps:
428 - run: exit 1
429 if: >-
430 ${{
431 contains(needs.integration-tests-modules-matrix.result, 'failure')
432 || contains(needs.integration-tests-modules-matrix.result, 'cancelled')
433 || contains(needs.integration-tests-modules-matrix.result, 'skipped')
434 }}
435 - run: exit 0
436 if: ${{ contains(needs.integration-tests-modules-matrix.result, 'success') }}