@@ -12,78 +12,100 @@ concurrency:
1212 cancel-in-progress : true
1313
1414jobs :
15- ci :
16- name : Detect affected packages, build and test
15+ build :
16+ name : Build
1717 runs-on : ubuntu-latest
18+ outputs :
19+ any-workspace : ${{ steps.filter.outputs.any-workspace }}
20+ packages : ${{ steps.filter.outputs.changes }}
1821 steps :
1922 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
2023 - uses : actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
2124 with :
2225 cache : ' npm'
2326 node-version-file : ' .nvmrc'
24- - uses : wagoid/commitlint-github-action@9763196e10f27aef304c9b8b660d31d97fce0f99 # v5
2527 - name : Debug info
28+ # https://docs.github.com/en/actions/reference/security/secure-use#use-an-intermediate-environment-variable
29+ env :
30+ GH_HEAD_REF : ${{ github.head_ref }}
2631 run : |
2732 cat <<EOF
2833 Scratch environment: ${{ vars.SCRATCH_ENV || '<none>' }}
2934 Node version: $(node --version)
3035 NPM version: $(npm --version)
3136 GitHub ref: ${{ github.ref }}
32- GitHub head ref: ${{ github.head_ref } }
37+ GitHub head ref: ${GH_HEAD_REF }
3338 Working directory: $(pwd)
3439 EOF
3540
3641 - uses : dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
3742 id : filter
3843 with :
39- # Files in the `global` filter affect all workspaces, even if workspace-specific files have not changed.
40- filters : |
41- global:
42- - ".github/workflows/ci.yml"
43- - "package.json"
44- - "package-lock.json"
45- - "scripts/**"
46- any-workspace:
47- - "packages/**"
48- scratch-svg-renderer:
49- - "packages/scratch-svg-renderer/**"
50- scratch-render:
51- - "packages/scratch-render/**"
52- - "packages/scratch-svg-renderer/**"
53- scratch-vm:
54- - "packages/scratch-render/**"
55- - "packages/scratch-svg-renderer/**"
56- - "packages/scratch-vm/**"
57- scratch-gui:
58- - "packages/scratch-gui/**"
59- - "packages/scratch-render/**"
60- - "packages/scratch-svg-renderer/**"
61- - "packages/scratch-vm/**"
44+ filters : ./.github/path-filters.yml
6245
63- - if : ${{ steps.filter.outputs.global == 'true' || steps.filter.outputs. any-workspace == 'true' }}
46+ - if : ${{ steps.filter.outputs.any-workspace == 'true' }}
6447 uses : ./.github/actions/install-dependencies
6548
6649 - name : Build packages
67- if : ${{ steps.filter.outputs.global == 'true' || steps.filter.outputs. any-workspace == 'true' }}
50+ if : ${{ steps.filter.outputs.any-workspace == 'true' }}
6851 run : npm run build
6952
70- - name : Test scratch-svg-renderer
71- if : ${{ !cancelled() && ( steps.filter.outputs.global == 'true' || steps.filter.outputs.scratch-svg-renderer == 'true') }}
72- uses : ./.github/ actions/test-package
53+ - name : Store build artifacts
54+ if : ${{ steps.filter.outputs.any-workspace == 'true' }}
55+ uses : actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
7356 with :
74- package_name : scratch-svg-renderer
75- - name : Test scratch-render
76- if : ${{ !cancelled() && (steps.filter.outputs.global == 'true' || steps.filter.outputs.scratch-render == 'true') }}
77- uses : ./.github/actions/test-package
57+ name : build
58+ path : |
59+ packages/**/build
60+ packages/**/dist
61+ packages/**/playground
62+
63+ test :
64+ runs-on : ubuntu-latest
65+ needs : build
66+ if : ${{ needs.build.outputs.any-workspace == 'true' }}
67+ strategy :
68+ fail-fast : false
69+ matrix :
70+ package : ${{ fromJSON(needs.build.outputs.packages) }}
71+ exclude :
72+ - package : global
73+ - package : any-workspace
74+ name : Test ${{ matrix.package }}
75+ steps :
76+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
77+ - uses : actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
7878 with :
79- package_name : scratch-render
80- - name : Test scratch-vm
81- if : ${{ !cancelled() && (steps.filter.outputs.global == 'true' || steps.filter.outputs.scratch-vm == 'true') }}
82- uses : ./.github/ actions/test-package
79+ cache : ' npm '
80+ node-version-file : ' .nvmrc '
81+ - uses : ./.github/actions/install-dependencies
82+ - uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
8383 with :
84- package_name : scratch-vm
85- - name : Test scratch-gui
86- if : ${{ !cancelled() && (steps.filter.outputs.global == 'true' || steps.filter.outputs.scratch-gui == 'true') }}
87- uses : ./.github/actions/test-package
84+ name : build
85+ path : packages
86+ - uses : ./.github/actions/test-package
8887 with :
89- package_name : scratch-gui
88+ package_name : ${{ matrix.package }}
89+
90+ results :
91+ name : Results
92+ runs-on : ubuntu-latest
93+ needs : test
94+ if : ${{ always() }}
95+ steps :
96+ - run : |
97+ case "${{ needs.test.result }}" in
98+ success)
99+ echo "Tests passed successfully."
100+ exit 0
101+ ;;
102+ skipped)
103+ echo "Tests were unnecessary for these changes, so they were skipped."
104+ echo "If this is unexpected, check the path filters."
105+ exit 0
106+ ;;
107+ *)
108+ echo "Tests failed."
109+ exit 1
110+ ;;
111+ esac
0 commit comments