forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 1
2384 lines (2149 loc) · 101 KB
/
Copy pathci.yml
File metadata and controls
2384 lines (2149 loc) · 101 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: CI
on:
pull_request:
types: [opened, synchronize, reopened]
push:
# Ref: GHA Filter pattern syntax: https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#filter-pattern-cheat-sheet
# Run on pushes to main, release branches, and previous/future major version branches
branches:
- main
- 'v[0-9]+.*' # Matches any release branch, e.g. v6.0.3, v12.1.0
- '[0-9]+.x' # Matches any major version branch, e.g. 5.x, 23.x
tags:
- 'v[0-9]*' # Version tags trigger release publishing (npm, GitHub Release, Docker)
env:
FORCE_COLOR: 1
HEAD_COMMIT: ${{ github.sha }}
NODE_VERSION: 22.23.1
# Disable v8-compile-cache to prevent intermittent V8 deserializer crashes
# when multiple parallel Nx workers race to read/write shared bytecode cache
# files. The cache lives in /tmp and is discarded after each run anyway,
# so disabling it has no meaningful performance impact in CI.
# See: https://github.com/nodejs/node/issues/51555
DISABLE_V8_COMPILE_CACHE: 1
# Nx's native (Rust/NAPI) command runner intermittently segfaults on the CI
# runners when it forks a task through its pseudo-terminal — the process is
# killed with SIGSEGV before the target script even starts. It's an upstream
# Nx instability (see nrwl/nx#27917, nrwl/nx#2956), not a Ghost bug, and it
# can hit any job that runs `nx run`/`nx run-many`, so the switch to the
# legacy child_process runner is set globally rather than per-job. The legacy
# runner was Nx's default before the native one existed; parallelism is
# unaffected and output/colour is preserved (FORCE_COLOR is set above), so
# there's no meaningful cost in CI.
NX_NATIVE_COMMAND_RUNNER: "false"
concurrency:
# Tag pushes get a unique uninterruptible group so a release CI run always
# finishes; branch / PR pushes keep cancel-on-newer behavior.
group: ${{ startsWith(github.ref, 'refs/tags/') && format('release-{0}', github.ref) || github.head_ref || github.ref }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
# Default least-privilege token for all jobs; jobs that need more declare
# their own permissions block, which overrides this default.
permissions:
contents: read
jobs:
job_setup:
name: Setup
runs-on: ubuntu-latest
timeout-minutes: 15
env:
IS_MAIN: ${{ github.ref == 'refs/heads/main' }}
IS_TAG: ${{ startsWith(github.ref, 'refs/tags/v') }}
IS_DEVELOPMENT: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/6.x' }}
IS_SIX: ${{ github.ref == 'refs/heads/6.x' }}
IS_SIX_PR: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == '6.x' }}
permissions:
actions: read
contents: read
# Required by dorny/paths-filter, which calls pulls.listFiles on
# pull_request events. Private forks of this repo don't grant this
# implicitly when an explicit permissions block is present, so it must
# be listed here for the Setup job to succeed on those forks.
pull-requests: read
steps:
- name: Checkout current commit
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
ref: ${{ env.HEAD_COMMIT }}
fetch-depth: 0
# fetch a treeless clone to improve checkout speed, the job will fetch contents later if needed
filter: 'tree:0'
- name: Output GitHub context
if: env.RUNNER_DEBUG == '1'
run: |
echo "GITHUB_EVENT_NAME: ${{ github.event_name }}"
echo "GITHUB_CONTEXT: ${{ toJson(github.event) }}"
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- name: Set up Node
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
env:
FORCE_COLOR: 0
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
# Replaced nrwl/nx-set-shas, which verified each candidate commit over the
# API and hid the errors — see scripts/nx-set-shas.js.
- name: Set SHAs for Nx Commands
if: env.IS_TAG != 'true'
env:
GITHUB_TOKEN: ${{ github.token }}
BRANCH: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.ref_name }}
# Canonical main is the one branch where too narrow a base means
# untested commits land, so there a lookup that comes up empty fails
# the run rather than falling back to the previous commit.
ON_MISSING: ${{ (env.IS_MAIN == 'true' && github.repository == 'TryGhost/Ghost') && 'error' || 'previous-commit' }}
run: node scripts/nx-set-shas.js --branch "$BRANCH" --head "$HEAD_COMMIT" --on-missing "$ON_MISSING"
- name: Check user org membership
id: check_user_org_membership
if: github.event_name == 'pull_request'
run: |
echo "Looking up: ${{ github.triggering_actor }}"
ENCODED_USERNAME=$(printf '%s' '${{ github.triggering_actor }}' | jq -sRr @uri)
LOOKUP_USER=$(curl --write-out "%{http_code}" --silent --output /dev/null --location "https://api.github.com/orgs/tryghost/members/$ENCODED_USERNAME" --header "Authorization: Bearer ${{ secrets.CANARY_DOCKER_BUILD }}")
if [ "$LOOKUP_USER" == "204" ]; then
echo "User is in the org"
echo "is_member=true" >> $GITHUB_OUTPUT
else
echo "User is not in the org"
echo "is_member=false" >> $GITHUB_OUTPUT
fi
- name: Determine changed packages
if: env.IS_TAG != 'true'
uses: AurorNZ/paths-filter@c9dd42e99db87803313ff6f4b1150cc9f6c836af # v5.0.0
id: changed
with:
base: ${{ env.NX_BASE }}
filters: |
shared: &shared
- '.github/**'
# The @internal/scripts workspace sits outside .github but is
# invoked by the workflows below, so it needs the same treatment
# the '.github/**' glob used to give it when it lived there.
- 'scripts/**'
# Renovate config / workflow files have no Ghost
# runtime/test impact. Anchored as &renovate_only and
# referenced from every filter below so a PR touching
# only these files skips all downstream jobs; the
# rollup gate passes on skipped deps.
- &renovate_only
- '!.github/renovate.json5'
- '!.github/renovate-bot.cjs'
- '!.github/workflows/renovate.yml'
- '.npmrc'
- 'nx.json'
- 'package.json'
- 'pnpm-lock.yaml'
- 'pnpm-workspace.yaml'
ci:
- '.github/workflows/**'
- *renovate_only
- '.github/actions/**'
- '.github/scripts/**'
- 'scripts/**'
docs:
- '**/*.md'
- '.agents/**'
- '.claude/**'
- '.github/workflows/ci.yml'
- 'package.json'
- 'scripts/check-agent-skill-links.js'
- 'scripts/test/check-agent-skill-links.test.js'
core:
- *shared
# Repository documentation and ownership metadata do not affect
# Ghost runtime behaviour, even though they live in .github.
- '!.github/**/*.md'
- '!.github/CODEOWNERS'
- 'ghost/**'
- '!ghost/core/core/server/data/tinybird/**'
# Unit tests + vitest config are exercised only by job_unit-tests;
# they never affect the acceptance / legacy / ghost-cli jobs.
- '!ghost/core/test/unit/**'
- '!ghost/core/vitest.config.ts'
- '!ghost/core/test/utils/vitest-setup.ts'
# Koenig packages that are runtime deps of ghost/core — changes
# here alter server rendering behaviour, so the acceptance /
# legacy suites must run. Editor-only packages are excluded.
- 'koenig/**'
- '!koenig/koenig-lexical/**'
- '!koenig/kg-unsplash-selector/**'
- '!koenig/kg-simplemde/**'
- '!koenig/*/test/**'
unit-test-globals:
- 'vitest.config.mjs'
core-unit-test-globals:
- 'ghost/core/vitest.config.ts'
- 'ghost/core/test/utils/vitest-*.ts'
any-code:
- '!**/*.md'
- '!.devcontainer/**'
- '!.vscode/**'
- *renovate_only
# Drives the run_e2e output: matches any changed file that could
# affect a running Ghost instance. Test files, test config and
# docs are excluded — a change confined to them cannot alter
# product behaviour, so the build + E2E lane is skipped.
# ghost/core test paths are listed today; app test paths can be
# added here as their conventions are confirmed.
e2e:
- '!**/*.md'
- '!.devcontainer/**'
- '!.vscode/**'
- '!ghost/core/test/**'
- '!ghost/core/vitest.config.ts'
- '!koenig/*/test/**'
- *renovate_only
# The Analytics E2E shards normally pull a prebuilt tb-cli image
# from GHCR, which is only republished from main. Without this the
# PR that changes the Dockerfile is the one PR that never exercises
# it — the break lands on main and surfaces in someone else's PR.
tb-cli:
- 'docker/tb-cli/**'
- name: Define Node test matrix
id: node_matrix
run: |
echo 'matrix=["22.23.1"]' >> $GITHUB_OUTPUT
- name: Start Nx Cloud CI run
run: pnpm nx start-ci-run
- name: Determine Affected Projects
id: affected
run: |
# if the ci files have changed or we're in a tag, ensure we don't just look at affected
# projects and we run the necessary jobs on all projects
AFFECTED_ARG="--affected"
if [[ "${{ steps.changed.outputs.ci }}" == 'true' || "${{ env.IS_TAG }}" == 'true' ]]; then
AFFECTED_ARG=""
fi
AFFECTED_PROJECTS=$(pnpm -s nx show projects ${AFFECTED_ARG} --json)
echo "affected_projects=$AFFECTED_PROJECTS" >> "$GITHUB_OUTPUT"
# string list for use in run-many commands
AFFECTED_PROJECTS_STR=$(pnpm -s nx show projects ${AFFECTED_ARG} --sep=, | tr -d '\n')
echo "affected_projects_str=$AFFECTED_PROJECTS_STR" >> "$GITHUB_OUTPUT"
UNIT_TEST_AFFECTED_ARG="$AFFECTED_ARG"
if [[ "${{ steps.changed.outputs.unit-test-globals }}" == 'true' ]]; then
UNIT_TEST_AFFECTED_ARG=""
fi
UNIT_TEST_PROJECTS_STR=$(pnpm -s nx show projects ${UNIT_TEST_AFFECTED_ARG} --withTarget test:unit --sep=, | tr -d '\n')
if [[ "${{ steps.changed.outputs.core-unit-test-globals }}" == 'true' ]]; then
UNIT_TEST_PROJECTS_STR=$(printf '%s\n%s\n' "$UNIT_TEST_PROJECTS_STR" "ghost" | awk 'NF && !seen[$0]++' | paste -sd, -)
fi
echo "unit_test_projects_str=$UNIT_TEST_PROJECTS_STR" >> "$GITHUB_OUTPUT"
# "i18n" tag = packages whose source is scanned by @tryghost/i18n's
# translate:* scripts (not packages that merely import @tryghost/i18n).
I18N_PROJECTS=$(pnpm -s nx show projects ${AFFECTED_ARG} --projects 'tag:i18n' --sep=, | tr -d '\n')
echo "affected_i18n_projects=${I18N_PROJECTS}" >> "$GITHUB_OUTPUT"
# "playwright" tag = projects whose test:acceptance suite runs in
# job_apps_acceptance-tests. Tag-based rather than directory-based so
# the matrix isn't coupled to the workspace layout (apps/*, koenig/*, ...).
PLAYWRIGHT_PROJECTS=$(pnpm -s nx show projects ${AFFECTED_ARG} \
--withTarget test:acceptance \
--projects 'tag:playwright' \
--json)
echo "affected_playwright_projects=$PLAYWRIGHT_PROJECTS" >> "$GITHUB_OUTPUT"
# Build the publish matrix for affected public apps. Matrix context
# isn't available in a job-level `if:`, so the publish job can't filter
# itself per-app — instead we emit the matrix here and it skips when
# the result is `[]`. The publish job's own is_main / event gates keep
# tags and PRs from publishing regardless of what this lists.
PUBLISH_PUBLIC_APPS_MATRIX=$(node scripts/build-public-apps-matrix.js "$AFFECTED_PROJECTS")
echo "publish_public_apps_matrix=$PUBLISH_PUBLIC_APPS_MATRIX" >> "$GITHUB_OUTPUT"
outputs:
affected_projects: ${{ steps.affected.outputs.affected_projects }}
affected_projects_str: ${{ steps.affected.outputs.affected_projects_str }}
unit_test_projects_str: ${{ steps.affected.outputs.unit_test_projects_str }}
affected_playwright_projects: ${{ steps.affected.outputs.affected_playwright_projects }}
publish_public_apps_matrix: ${{ steps.affected.outputs.publish_public_apps_matrix }}
changed_i18n_apps: ${{ steps.affected.outputs.affected_i18n_projects != '' }}
changed_core: ${{ steps.changed.outputs.core }}
changed_any_code: ${{ steps.changed.outputs.any-code }}
changed_docs: ${{ steps.changed.outputs.docs }}
changed_tb_cli: ${{ steps.changed.outputs.tb-cli }}
# Single gate for the build + browser-E2E lane. True for tags, or when a
# changed file could affect a running Ghost instance (see the `e2e` path
# filter above). A test-only / docs-only change keeps this false.
run_e2e: ${{ env.IS_TAG == 'true' || steps.changed.outputs.e2e == 'true' }}
# Coverage instrumentation (c8 for core, ember-cli-code-coverage for
# admin) and the Codecov upload only happen on the canonical repo. Forks
# — including TryGhost's private ones — don't report to Ghost's Codecov
# project, so instrumenting their test runs just slows CI down to produce
# a report nothing consumes.
coverage_enabled: ${{ github.repository == 'TryGhost/Ghost' }}
is_main: ${{ env.IS_MAIN }}
is_tag: ${{ env.IS_TAG }}
is_development: ${{ env.IS_DEVELOPMENT }}
is_six: ${{ env.IS_SIX }}
is_six_pr: ${{ env.IS_SIX_PR }}
member_is_in_org: ${{ steps.check_user_org_membership.outputs.is_member }}
has_perf_tests_label: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'perf-tests') }}
node_version: ${{ env.NODE_VERSION }}
node_test_matrix: ${{ steps.node_matrix.outputs.matrix }}
nx_base: ${{ env.NX_BASE }}
job_app_version_bump_check:
name: Check app version bump
runs-on: ubuntu-latest
needs: [job_setup]
if: github.event_name == 'pull_request'
steps:
- name: Checkout PR head commit
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Fetch main branch
run: git fetch --no-tags origin main
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
env:
FORCE_COLOR: 0
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
# The script's only runtime dep is semver, so install @internal/scripts
# alone rather than the whole workspace — ~0.5s and a single package.
- name: Install scripts dependencies
run: pnpm install --frozen-lockfile --filter @internal/scripts --prod --ignore-scripts
- name: Check app version bump
env:
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_COMPARE_SHA: ${{ github.event.pull_request.head.sha }}
run: node scripts/check-app-version-bump.js
# Fail the PR if a publishable package changed (source or a catalog entry
# it consumes) but the branch adds no changeset covering it. Prototype of
# pnpm's forthcoming `pnpm change check`.
- name: Check for missing changesets
env:
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_COMPARE_SHA: ${{ github.event.pull_request.head.sha }}
run: node scripts/change-check.js
job_migration_integrity_check:
name: Check migration integrity
runs-on: ubuntu-latest
needs: [job_setup]
if: github.event_name == 'pull_request'
steps:
- name: Checkout PR head commit
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Fetch PR base branch
run: git fetch --no-tags origin "${{ github.event.pull_request.base.ref }}"
- name: Check migration integrity
env:
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_COMPARE_SHA: ${{ github.event.pull_request.head.sha }}
run: node scripts/check-migration-integrity.cjs
job_lint:
runs-on: ubuntu-latest
needs: [job_setup]
if: needs.job_setup.outputs.is_tag == 'true' || needs.job_setup.outputs.affected_projects_str != ''
name: Lint
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 1000
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
env:
FORCE_COLOR: 0
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5
with:
path: ghost/**/.eslintcache
key: eslint-cache
- name: Lint projects
run: pnpm nx run-many -t lint -p "${{ needs.job_setup.outputs.affected_projects_str }}"
env:
NX_BASE: ${{ needs.job_setup.outputs.nx_base }}
NX_HEAD: ${{ env.HEAD_COMMIT }}
- name: Lint boundaries
run: pnpm nx run ghost-monorepo:lint:boundaries
- uses: tryghost/actions/actions/slack-build@e7a401946f91165a6426290705f501a377ec1533 # main
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
status: ${{ job.status }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
job_lint_docs:
name: Lint docs
runs-on: ubuntu-slim
needs: [job_setup]
if: needs.job_setup.outputs.changed_docs == 'true'
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: ${{ env.NODE_VERSION }}
- name: Lint agent skills
run: node scripts/check-agent-skill-links.js
job_i18n:
runs-on: ubuntu-latest
needs: [job_setup]
name: i18n
if: |
needs.job_setup.outputs.is_tag == 'true'
|| needs.job_setup.outputs.changed_i18n_apps == 'true'
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile --filter @tryghost/i18n... --ignore-scripts
- name: Run i18n tests
run: pnpm --filter @tryghost/i18n test
job_admin-tests:
runs-on: ubuntu-latest
needs: [job_setup]
if: |
needs.job_setup.outputs.is_tag == 'true'
|| contains(fromJSON(needs.job_setup.outputs.affected_projects), 'ghost-admin')
name: Admin tests - Chrome
env:
MOZ_HEADLESS: 1
JOBS: 1
CI: true
COVERAGE: ${{ needs.job_setup.outputs.coverage_enabled }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- run: pnpm nx run ghost-admin:test
env:
BROWSER: Chrome
# Merge coverage reports and upload
- name: Merge Admin test coverage
if: needs.job_setup.outputs.coverage_enabled == 'true'
run: pnpm ember coverage-merge
working-directory: apps/ember-admin
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
if: needs.job_setup.outputs.coverage_enabled == 'true'
with:
name: admin-coverage
path: apps/*/coverage/cobertura-coverage.xml
- uses: tryghost/actions/actions/slack-build@e7a401946f91165a6426290705f501a377ec1533 # main
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
status: ${{ job.status }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# Measures Ghost's boot time with hyperfine and appends the result to the
# long-running series charted at https://tryghost.github.io/Ghost-Benchmarks/
# (data lives on the gh-pages branch of TryGhost/Ghost-Benchmarks).
#
# Changing the runner label or the hyperfine version makes new results
# incomparable with the existing history - treat both as pinned.
job_perf-tests:
runs-on: blacksmith-2vcpu-ubuntu-2404
needs: [job_setup]
if: (needs.job_setup.outputs.changed_core == 'true' && needs.job_setup.outputs.is_development == 'true') || needs.job_setup.outputs.has_perf_tests_label == 'true'
name: Performance tests
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
# Boot activates the default theme, which is a submodule
submodules: true
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
env:
FORCE_COLOR: 0
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install dependencies
# --force for the same reason as job_unit-tests: better-sqlite3 is an
# optionalDependency and boot uses it for the development database.
run: pnpm install --frozen-lockfile --force
- name: Install hyperfine
uses: ./.github/actions/install-hyperfine
- name: Build TS code
run: pnpm nx run-many -t build:tsc
- name: Run hyperfine on boot
working-directory: ghost/core
run: hyperfine --show-output --warmup 3 'GHOST_CI_SHUTDOWN_AFTER_BOOT=1 node index.js' --export-json boot-perf.json
- name: Report result
uses: ./.github/actions/report-boot-benchmark
with:
results-file: ghost/core/boot-perf.json
series: Benchmark
metric: Boot time
title: Boot time (dev tree)
github-token: ${{ secrets.CANARY_DOCKER_BUILD }}
# Boot time of the production image, as a series separate from job_perf-tests:
# that one tracks the code, this one tracks what ships (NODE_ENV=production, no
# devDependencies, jemalloc, baked compile cache). Never merge them - a base image
# bump would land in the code series as a regression with no Ghost commit behind it.
job_perf-tests-image:
name: Performance tests (production image)
runs-on: blacksmith-2vcpu-ubuntu-2404
needs: [job_setup, job_docker]
# Registry path only: benchmarks are a canonical-repo series, so this pulls the
# core image from GHCR rather than loading the artifact-path tarball.
if: |
needs.job_docker.result == 'success' &&
needs.job_docker.outputs.use-artifact == 'false' &&
((needs.job_setup.outputs.changed_core == 'true' && needs.job_setup.outputs.is_development == 'true') || needs.job_setup.outputs.has_perf_tests_label == 'true')
permissions:
contents: read
packages: read
steps:
# Only for .github/actions/load-docker-image; nothing is built from source here.
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Install hyperfine
uses: ./.github/actions/install-hyperfine
- name: Load core image
uses: ./.github/actions/load-docker-image
id: load
with:
use-artifact: 'false'
image-tags: ${{ needs.job_docker.outputs.image-core-tags }}
- name: Start MySQL
# Own network rather than a service container, so Ghost can reach it by name.
# Pinned by digest: a MySQL bump moves the measurement, so it should be a
# deliberate baseline change rather than drift in the series.
run: |
docker network create ghost-perf
docker run -d --name mysql --network ghost-perf \
--tmpfs /var/lib/mysql \
-e MYSQL_DATABASE=ghost \
-e MYSQL_ROOT_PASSWORD=root \
--health-cmd "mysqladmin ping -h 127.0.0.1 -uroot -proot" \
--health-interval=2s \
--health-timeout=5s \
--health-retries=60 \
mysql:8.0@sha256:7dcddc01f13bab2f15cde676d44d01f61fc9f99fe7785e86196dfc07d358ae2b
for _ in $(seq 1 60); do
if [ "$(docker inspect -f '{{.State.Health.Status}}' mysql)" = "healthy" ]; then
exit 0
fi
sleep 2
done
echo "MySQL did not become healthy"
docker logs mysql
exit 1
- name: Start Ghost container
# Kept alive with `sleep` so each measured run is a `docker exec`; timing
# `docker run` would put container create/start inside the measurement.
env:
IMAGE_TAG: ${{ steps.load.outputs.image-tag }}
run: |
docker run -d --name ghost --network ghost-perf --entrypoint sleep \
-e GHOST_CI_SHUTDOWN_AFTER_BOOT=1 \
-e database__client=mysql \
-e database__connection__host=mysql \
-e database__connection__user=root \
-e database__connection__password=root \
-e database__connection__database=ghost \
"$IMAGE_TAG" infinity
- name: Run migrations (discarded first boot)
# A fresh database costs ~6.5s of migrations vs ~2.3s steady state.
run: docker exec ghost node index.js
- name: Run hyperfine on boot
run: hyperfine --show-output --warmup 3 'docker exec ghost node index.js' --export-json boot-perf-image.json
- name: Report result
uses: ./.github/actions/report-boot-benchmark
with:
results-file: boot-perf-image.json
# Own subdirectory in the benchmarks repo (like dx/), so this series gets its
# own chart and data file and the root series is left untouched.
data-dir: docker
series: Production image
metric: Boot time
title: Boot time (production image)
github-token: ${{ secrets.CANARY_DOCKER_BUILD }}
job_unit-tests:
runs-on: ubuntu-latest
needs: [job_setup]
if: needs.job_setup.outputs.is_tag == 'true' || needs.job_setup.outputs.unit_test_projects_str != ''
strategy:
matrix:
node: ${{ fromJSON(needs.job_setup.outputs.node_test_matrix) }}
name: Unit tests (Node ${{ matrix.node }})
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 1000
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
env:
FORCE_COLOR: 0
with:
node-version: ${{ matrix.node }}
cache: pnpm
- name: Install dependencies
# better-sqlite3 is an optionalDependency. Without --force, pnpm may skip
# installing/linking it when restoring from a cached store. --force
# ensures all optional deps are installed regardless.
# (ghost core's test:unit job requires better-sqlite3)
run: pnpm install --frozen-lockfile --force
- name: Set timezone (non-UTC)
uses: szenius/set-timezone@1f9716b0f7120e344f0c62bb7b1ee98819aefd42 # v2.0
with:
timezoneLinux: "America/New_York"
- name: Run unit tests
# ghost/core's unit tests run on vitest (see ghost/core/vitest.config.ts);
# other packages run their own test:unit target.
#
# Retried up to 3 attempts: ghost/core's vitest run intermittently
# crashes a worker on loaded CI runners — an abnormal process exit,
# not a reported test failure. nx caches the projects that already
# passed, so a retry only re-runs the crashed one. Interim stopgap
# until the vitest worker/teardown issue is fixed.
#
# Each attempt is bounded by `timeout`: a test process that finishes
# its suites but never exits (lingering worker/handle) would otherwise
# wedge the job until the 6h runner limit. Killing it turns the hang
# into a retriable failure. A full cold (uncached) run takes ~10min.
run: |
for attempt in 1 2 3; do
timeout 25m pnpm nx run-many -t test:unit -p "${{ needs.job_setup.outputs.unit_test_projects_str }}" && exit 0
if [ "${attempt}" -lt 3 ]; then
echo "::warning::Unit tests attempt ${attempt} failed — retrying"
else
echo "::error::Unit tests failed after ${attempt} attempts — no more retries"
fi
done
exit 1
env:
FORCE_COLOR: 0
NX_SKIP_LOG_GROUPING: true
logging__level: fatal
- name: Check for unexpected file changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Tests generated unexpected file changes. Commit them before merging:"
git status
git diff
exit 1
fi
- uses: tryghost/actions/actions/slack-build@e7a401946f91165a6426290705f501a377ec1533 # main
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
status: ${{ job.status }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
job_acceptance-tests:
runs-on: ubuntu-latest
needs: [job_setup]
if: needs.job_setup.outputs.is_tag == 'true' || needs.job_setup.outputs.changed_core == 'true'
services:
mysql:
image: ${{ matrix.env.DB == 'mysql8' && 'mysql:8.0' || '' }}
env:
MYSQL_DATABASE: ghost_testing
MYSQL_ROOT_PASSWORD: root
ports:
- 3306
# Poll the healthcheck every 2s instead of 10s — same max wait window
# (120s = 60 × 2s), but ready-state is discovered ~8s earlier on a
# typical boot. Same change on the redis service below.
options: >-
--tmpfs /var/lib/mysql
--health-cmd "mysqladmin ping -h 127.0.0.1 -uroot -proot"
--health-interval=2s
--health-timeout=5s
--health-retries=60
redis:
image: redis:7.4@sha256:a8f08480e1f88f2647fed492d1178c06abb0d0c1fbf02c682a61e2f483fb3954
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval=2s
--health-timeout=5s
--health-retries=60
strategy:
matrix:
node: ${{ fromJSON(needs.job_setup.outputs.node_test_matrix) }}
env:
- DB: mysql8
NODE_ENV: testing-mysql
include:
- node: ${{ needs.job_setup.outputs.node_version }}
env:
DB: better-sqlite3
NODE_ENV: testing
env:
DB: ${{ matrix.env.DB }}
NODE_ENV: ${{ matrix.env.NODE_ENV }}
# The `test:ci:*` targets wrap the suites in c8. Only the sqlite leg is
# instrumented (mysql covers the same code), and only on the canonical
# repo — see job_setup's coverage_enabled output.
COVERAGE_ENABLED: ${{ needs.job_setup.outputs.coverage_enabled == 'true' && matrix.env.DB == 'better-sqlite3' }}
name: Acceptance tests (Node ${{ matrix.node }}, ${{ matrix.env.DB }})
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
env:
FORCE_COLOR: 0
with:
node-version: ${{ matrix.node }}
cache: pnpm
- name: Install dependencies
# better-sqlite3 is an optionalDependency. Without --force, pnpm may skip
# installing/linking it when restoring from a cached store. --force
# ensures all optional deps are installed regardless. The mysql leg
# doesn't need better-sqlite3, so it skips --force and gets a fast cache
# restore (matches the legacy-tests job below).
run: |
if [ "${{ matrix.env.DB }}" = "better-sqlite3" ]; then
pnpm install --frozen-lockfile --force
else
pnpm install --frozen-lockfile
fi
- name: Set timezone (non-UTC)
uses: szenius/set-timezone@1f9716b0f7120e344f0c62bb7b1ee98819aefd42 # v2.0
with:
timezoneLinux: "America/New_York"
- name: Set env vars (SQLite)
if: contains(matrix.env.DB, 'sqlite')
run: echo "database__connection__filename=/dev/shm/ghost-test.db" >> "$GITHUB_ENV"
- name: Set env vars (MySQL)
if: contains(matrix.env.DB, 'mysql')
run: |
{
echo "database__connection__host=127.0.0.1"
echo "database__connection__port=${{ job.services.mysql.ports['3306'] }}"
echo "database__connection__password=root"
} >> "$GITHUB_ENV"
- name: E2E tests
run: |
if [ "$COVERAGE_ENABLED" = "true" ]; then
pnpm nx run ghost:test:ci:e2e
else
pnpm nx run ghost:test:e2e
fi
- name: Start MinIO for integration tests
run: |
docker run -d --rm --name minio \
-p 9000:9000 \
-e MINIO_ROOT_USER=minio-user \
-e MINIO_ROOT_PASSWORD=minio-pass \
minio/minio:RELEASE.2024-12-13T22-19-12Z@sha256:149fdd73108553247ceee85fc65466f51034bd6e145d6e0c0e415167f5f1274f \
server /data
for i in $(seq 1 30); do
if curl -sf http://127.0.0.1:9000/minio/health/ready; then
echo "MinIO ready after ${i}s"
exit 0
fi
sleep 1
done
echo "MinIO did not become ready in time" >&2
docker logs minio
exit 1
- name: Integration tests
run: |
if [ "$COVERAGE_ENABLED" = "true" ]; then
pnpm nx run ghost:test:ci:integration
else
pnpm nx run ghost:test:integration
fi
- name: Check for unexpected file changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Tests generated unexpected file changes. Commit them before merging:"
git status
git diff
exit 1
fi
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
if: env.COVERAGE_ENABLED == 'true' && matrix.node == env.NODE_VERSION
with:
name: e2e-coverage
path: |
ghost/*/coverage-e2e/cobertura-coverage.xml
ghost/*/coverage-integration/cobertura-coverage.xml
- uses: tryghost/actions/actions/slack-build@e7a401946f91165a6426290705f501a377ec1533 # main
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
status: ${{ job.status }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
job_legacy-tests:
runs-on: ubuntu-latest
needs: [job_setup]
if: needs.job_setup.outputs.is_tag == 'true' || needs.job_setup.outputs.changed_core == 'true'
services:
mysql:
image: ${{ matrix.env.DB == 'mysql8' && 'mysql:8.0' || '' }}
env:
MYSQL_DATABASE: ghost_testing
MYSQL_ROOT_PASSWORD: root
ports:
- 3306
options: >-
--tmpfs /var/lib/mysql
--health-cmd "mysqladmin ping -h 127.0.0.1 -uroot -proot"
--health-interval=10s
--health-timeout=5s
--health-retries=12
strategy:
matrix:
include:
- node: ${{ needs.job_setup.outputs.node_version }}
env:
DB: mysql8
NODE_ENV: testing-mysql
- node: ${{ needs.job_setup.outputs.node_version }}
env:
DB: better-sqlite3
NODE_ENV: testing
env:
DB: ${{ matrix.env.DB }}
NODE_ENV: ${{ matrix.env.NODE_ENV }}
name: Legacy tests (Node ${{ matrix.node }}, ${{ matrix.env.DB }})
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
submodules: true
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
env:
FORCE_COLOR: 0
with:
node-version: ${{ matrix.node }}
cache: pnpm
- name: Install dependencies
# better-sqlite3 is an optionalDependency. Without --force, pnpm may skip
# installing/linking it when restoring from a cached store. --force
# ensures all optional deps are installed regardless.
run: |
if [ "${{ matrix.env.DB }}" = "better-sqlite3" ]; then
pnpm install --frozen-lockfile --force
else
pnpm install --frozen-lockfile
fi
- name: Set env vars (SQLite)
if: contains(matrix.env.DB, 'better-sqlite')
run: echo "database__connection__filename=/dev/shm/ghost-test.db" >> $GITHUB_ENV
- name: Set env vars (MySQL)
if: contains(matrix.env.DB, 'mysql')
run: |
echo "database__connection__host=127.0.0.1" >> $GITHUB_ENV
echo "database__connection__port=${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV
echo "database__connection__password=root" >> $GITHUB_ENV
- name: Legacy tests
# Bounded so a vitest run that completes its suites but hangs in
# teardown fails fast instead of wedging the job until the 6h runner
# limit. A normal run takes ~2-3min; 10m leaves ample headroom.
timeout-minutes: 10
run: pnpm nx run ghost:test:legacy
- name: Check for unexpected file changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Tests generated unexpected file changes. Commit them before merging:"
git status
git diff
exit 1
fi
- uses: tryghost/actions/actions/slack-build@e7a401946f91165a6426290705f501a377ec1533 # main
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
status: ${{ job.status }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
job_apps_acceptance-tests:
runs-on: ubuntu-latest
needs: [job_setup]
if: needs.job_setup.outputs.affected_playwright_projects != '[]'
name: App Playwright Acceptance Tests
strategy:
fail-fast: false
matrix:
app: ${{ fromJSON(needs.job_setup.outputs.affected_playwright_projects) }}
env:
CI: true
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
env:
FORCE_COLOR: 0
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install dependencies
# Each matrix leg only Playwright-tests one app, so scope the install to that
# app's dependency subgraph instead of the whole monorepo (which drags in
# ghost/core, ghost-admin and unrelated apps). nx and the app's workspace deps
# are still installed; the nx project name matches the package name.
run: pnpm install --frozen-lockfile --filter ${{ matrix.app }}...
- name: Setup Playwright
uses: ./.github/actions/setup-playwright
# The Koenig editor suite is the only one that needs apt packages on top
# of the runner image (setup-playwright deliberately avoids apt-get, see
# its README note about hangs — scoping this to one matrix leg contains
# that risk):
# - MS core fonts: caret-position assertions depend on where text wraps,
# which depends on Arial's font metrics
# - playwright firefox deps: system media codecs so firefox can decode
# the H.264 fixtures in the video card tests
- name: Install Koenig editor test dependencies (fonts + media codecs)
if: matrix.app == '@tryghost/koenig-lexical'
env:
DEBIAN_FRONTEND: noninteractive
DEBCONF_NONINTERACTIVE_SEEN: "true"
run: |
sudo sh -c "echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections"
sudo apt-get update -yq
sudo apt-get install -yq msttcorefonts
pnpm exec playwright install-deps firefox
- name: Run Playwright tests
run: pnpm nx run ${{ matrix.app }}:test:acceptance
- name: Get App Name