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