11name : CI/CD
22
33on :
4- workflow_dispatch :
5- push :
4+ pull_request : # Runs whenever a pull request is created or updated (including from another fork)
5+ push : # Runs whenever a commit is pushed to the repository...
6+ branches : [master, develop, hotfix/*] # ...on any of these branches
7+ workflow_dispatch : # Allows you to run this workflow manually from the Actions tab
68concurrency :
79 group : " ${{ github.workflow }} @ ${{ github.head_ref || github.ref }}"
810 cancel-in-progress : true
@@ -14,7 +16,7 @@ permissions:
1416 pull-requests : write # comment on released pull requests
1517
1618jobs :
17- setup :
19+ ci-cd :
1820 runs-on : ubuntu-latest
1921 env :
2022 DETECT_CHROMEDRIVER_VERSION : " true"
@@ -38,93 +40,16 @@ jobs:
3840 run : npm ci
3941 - name : Lint
4042 run : npm run test:lint
41- - name : Cache node_modules
42- id : cache-nodemodules
43- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
44- with :
45- path :
46- node_modules
47- key : ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
48- - name : Cache src/generated
49- id : cache-generated
50- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
51- with :
52- path :
53- src/generated
54- key : ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }}
55- - name : Cache static/microbit
56- id : cache-static
57- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
58- with :
59- path :
60- static/microbit
61- key : ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }}
62- test-unit :
63- needs : setup
64- runs-on : ubuntu-latest
65- env :
66- JEST_JUNIT_OUTPUT_NAME : unit-results.xml
67- JEST_JUNIT_OUTPUT_DIR : test-results/unit
68- steps :
69- - uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
70- - name : Cache NPM dependencies
71- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
72- with :
73- path :
74- node_modules
75- key : ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
7643 - name : Run Unit Tests
44+ env :
45+ JEST_JUNIT_OUTPUT_NAME : unit-results.xml
46+ JEST_JUNIT_OUTPUT_DIR : test-results/unit
7747 run : npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov --maxWorkers="2"
78- - name : Store Unit Test Results
79- uses : actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
80- with :
81- name : unit-test-output
82- path : ./test-results/*
83- build :
84- needs : [setup, test-unit]
85- env :
86- NODE_OPTIONS : --max-old-space-size=4000
87- runs-on : ubuntu-latest
88- steps :
89- - uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
90- - uses : actions/setup-node@26961cf329f22f6837d5f54c3efd76b480300ace # v4
91- with :
92- cache : " npm"
93- node-version-file : " .nvmrc"
94- - name : Retrieve node_modules
95- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
96- with :
97- path :
98- node_modules
99- key : ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
100- - name : Retrieve src/generated
101- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
102- with :
103- path :
104- src/generated
105- key : ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }}
106- - name : Retireve static/microbit
107- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
108- with :
109- path :
110- static/microbit
111- key : ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }}
11248 - name : Run Build
11349 env :
50+ NODE_OPTIONS : --max-old-space-size=4000
11451 NODE_ENV : production
11552 run : npm run build
116- - name : Cache Build Directory
117- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
118- with :
119- path :
120- ./build
121- key : ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
122- - name : Cache Dist Directory
123- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
124- with :
125- path :
126- ./dist
127- key : ${{ runner.os }}-dist-${{ hashFiles('package-lock.json') }}
12853 - name : Store Build Output
12954 uses : actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
13055 with :
@@ -135,55 +60,21 @@ jobs:
13560 with :
13661 name : dist-output
13762 path : ./dist
138- test-integration :
139- needs : build
140- runs-on : ubuntu-latest
141- env :
142- JEST_JUNIT_OUTPUT_NAME : results.txt
143- JEST_JUNIT_OUTPUT_DIR : test-results/integration
144- steps :
145- - uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
146- - name : Retrieve npm dependencies
147- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
148- with :
149- path :
150- node_modules
151- key : ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
152- - name : Retrieve Build
153- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
154- with :
155- path :
156- ./build
157- key : ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
15863 - run : |
15964 for F in chrome chromium chromedriver; do
16065 which $F && $F --version || echo Not found: $F
16166 done
16267 - name : Run Integration Tests
68+ env :
69+ JEST_JUNIT_OUTPUT_NAME : results.txt
70+ JEST_JUNIT_OUTPUT_DIR : test-results/integration
16371 run : npm run test:integration -- --reporters="default" --reporters="jest-junit"
164- - name : Store Integration Test Results
72+ - name : Store Test Results
73+ if : always() # Even if tests fail
16574 uses : actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
16675 with :
167- name : integration-test-output
168- path : ./test-results/*
169- deploy-npm :
170- needs : [test-integration, test-unit]
171- if : (github.ref == 'refs/heads/master') || (github.ref == 'refs/heads/develop') || (github.ref == 'refs/heads/beta') || startsWith(github.ref, 'refs/heads/hotfix')
172- runs-on : ubuntu-latest
173- steps :
174- - uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
175- - name : Retrieve npm dependencies
176- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
177- with :
178- path :
179- node_modules
180- key : ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
181- - name : Retrieve Dist Directory
182- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
183- with :
184- path :
185- ./dist
186- key : ${{ runner.os }}-dist-${{ hashFiles('package-lock.json') }}
76+ name : test-output
77+ path : ./test-results/* # Both unit and integration test results
18778 - run : |
18879 if [[ ${{contains(github.ref, 'hotfix')}} ]]; then
18980 sed -e "s|hotfix/REPLACE|${{ github.ref_name }}|" --in-place release.config.js
@@ -193,26 +84,9 @@ jobs:
19384 NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
19485 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
19586 run : npx --no -- semantic-release
196- deploy-gh-pages :
197- needs : [test-integration, test-unit]
198- if : (!(startsWith(github.ref, 'refs/heads/dependabot/') || startsWith(github.ref, 'refs/heads/renovate/')))
199- runs-on : ubuntu-latest
200- steps :
201- - uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
202- - name : Retrieve npm dependencies
203- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
204- with :
205- path :
206- node_modules
207- key : ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
208- - name : Retrieve Build Directory
209- uses : actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
210- with :
211- path :
212- ./build
213- key : ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
21487 - name : Deploy playground to GitHub Pages
21588 uses : peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847 # v3
89+ if : github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
21690 with :
21791 github_token : ${{ secrets.GITHUB_TOKEN }}
21892 publish_dir : ./build
0 commit comments