Skip to content

Commit c983032

Browse files
author
Ron de las Alas
committed
ci: add main workflow
- add setup - cache dependencies and dependency outputs - add build job - add unit test job - add integration test job - add npm deploy - add gh pages deploy
1 parent 4ca0990 commit c983032

File tree

6 files changed

+19664
-44312
lines changed

6 files changed

+19664
-44312
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules/*
22
build/*
33
dist/*
4+
test/*
5+
src/examples/*

.github/workflows/ci-cd.yml

+190-47
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
name: CI/CD
22

33
on:
4-
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
5-
pull_request: # Runs whenever a pull request is created or updated
4+
workflow_dispatch:
65
push: # Runs whenever a commit is pushed to the repository
7-
branches: [master, develop, beta, hotfix/*]
86

97
concurrency:
108
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
@@ -17,10 +15,13 @@ permissions:
1715
pull-requests: write # comment on released pull requests
1816

1917
jobs:
20-
ci-cd:
18+
setup:
2119
runs-on: ubuntu-latest
2220
env:
2321
TRIGGER_DEPLOY: ${{ startsWith(github.ref, 'refs/heads/master') }}
22+
DETECT_CHROMEDRIVER_VERSION: "true"
23+
JEST_JUNIT_OUTPUT_DIR: test-results
24+
NODE_OPTIONS: --max-old-space-size=4000
2425
steps:
2526
- uses: actions/checkout@v4
2627
- uses: wagoid/commitlint-github-action@v5
@@ -29,7 +30,6 @@ jobs:
2930
with:
3031
cache: "npm"
3132
node-version-file: ".nvmrc"
32-
3333
- name: Info
3434
run: |
3535
cat <<EOF
@@ -38,48 +38,191 @@ jobs:
3838
GitHub ref: ${{ github.ref }}
3939
GitHub head ref: ${{ github.head_ref }}
4040
EOF
41-
42-
- name: Install Google Chrome
43-
uses: browser-actions/setup-chrome@v1
44-
with:
45-
chrome-version: beta
46-
id: setup-chrome
47-
48-
- name: Chrome Info
49-
run: |
50-
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
51-
${{ steps.setup-chrome.outputs.chrome-path }} --version
52-
53-
- name: Install dependencies
54-
run: npm ci
55-
56-
- name: Setup & Test
57-
run: |
58-
mkdir -p ./test/results
59-
npm test
60-
61-
- name: Generate release version
41+
- name: Install Dependencies
42+
run: npm install
43+
- name: Lint
6244
run: |
63-
export RELEASE_TIMESTAMP=$(date +'%Y%m%d%H%M%S')
64-
export VPKG=$($(npm bin)/json -f package.json version)
65-
export VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}
66-
67-
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
68-
69-
if [[ "${GITHUB_REF##*/}" == hotfix/* ]]; then
70-
echo "NPM_TAG=hotfix" >> $GITHUB_ENV
71-
else
72-
echo "NPM_TAG=latest" >> $GITHUB_ENV
73-
fi
74-
75-
- name: Build
45+
npm run test:lint -- --quiet --output-file test-results/eslint/results.xml --format junit
46+
- name: Store Lint Results
47+
uses: actions/upload-artifact@v3
48+
with:
49+
name: lint-output
50+
path: ./test-results/*
51+
- name: Cache node_modules
52+
id: cache-nodemodules
53+
uses: actions/cache@v3
54+
with:
55+
path:
56+
node_modules
57+
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
58+
- name: Cache src/generated
59+
id: cache-generated
60+
uses: actions/cache@v3
61+
with:
62+
path:
63+
src/generated
64+
key: ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }}
65+
- name: Cache static/microbit
66+
id: cache-static
67+
uses: actions/cache@v3
68+
with:
69+
path:
70+
static/microbit
71+
key: ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }}
72+
test-unit:
73+
needs: setup
74+
runs-on: ubuntu-latest
75+
env:
76+
JEST_JUNIT_OUTPUT_NAME: unit-results.xml
77+
JEST_JUNIT_OUTPUT_DIR: test-results/unit
78+
steps:
79+
- uses: actions/checkout@v4
80+
- name: Cache NPM dependencies
81+
uses: actions/cache@v3
82+
with:
83+
path:
84+
node_modules
85+
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
86+
- name: Run Unit Tests
87+
run: npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov --maxWorkers="2"
88+
- name: Store Unit Test Results
89+
uses: actions/upload-artifact@v3
90+
with:
91+
name: unit-test-output
92+
path: ./test-results/*
93+
build:
94+
needs: setup
95+
env:
96+
NODE_OPTIONS: --max-old-space-size=4000
97+
DETECT_CHROMEDRIVER_VERSION: "true"
98+
runs-on: ubuntu-latest
99+
steps:
100+
- uses: actions/checkout@v4
101+
- uses: actions/setup-node@v3
102+
with:
103+
cache: "npm"
104+
node-version-file: ".nvmrc"
105+
- name: Retrieve node_modules
106+
uses: actions/cache@v3
107+
with:
108+
path:
109+
node_modules
110+
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
111+
- name: Retrieve src/generated
112+
uses: actions/cache@v3
113+
with:
114+
path:
115+
src/generated
116+
key: ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }}
117+
- name: Retireve static/microbit
118+
uses: actions/cache@v3
119+
with:
120+
path:
121+
static/microbit
122+
key: ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }}
123+
- name: Run Build
124+
run: npm run build
125+
- name: Cache Build Directory
126+
uses: actions/cache@v3
127+
with:
128+
path:
129+
./build
130+
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
131+
- name: Cache Dist Directory
132+
uses: actions/cache@v3
133+
with:
134+
path:
135+
./dist
136+
key: ${{ runner.os }}-dist-${{ hashFiles('package-lock.json') }}
137+
- name: Store Build Output
138+
uses: actions/upload-artifact@v3
139+
with:
140+
name: build-output
141+
path: ./build
142+
test-integration:
143+
needs: build
144+
runs-on: ubuntu-latest
145+
env:
146+
JEST_JUNIT_OUTPUT_NAME: results.txt
147+
JEST_JUNIT_OUTPUT_DIR: test-results/integration
148+
steps:
149+
- uses: actions/checkout@v4
150+
- name: Install Chrome Dependencies
76151
run: |
77-
npm run build
78-
npm --no-git-tag-version version $RELEASE_VERSION
79-
80-
- name: Semantic release (configured to run dry if branch is other than 'master')
152+
sudo apt-get update
153+
sudo apt-get install -y libgconf-2-4 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm-dev libnss3-dev libxss-dev libasound2
154+
- name: Retrieve npm dependencies
155+
uses: actions/cache@v3
156+
with:
157+
path:
158+
node_modules
159+
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
160+
- name: Retrieve Build
161+
uses: actions/cache@v3
162+
with:
163+
path:
164+
./build
165+
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
166+
- uses: browser-actions/setup-chrome@v1
167+
with:
168+
chrome-version: stable
169+
id: setup-chrome
170+
- run: |
171+
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
172+
${{ steps.setup-chrome.outputs.chrome-path }} --version
173+
- name: Run Integration Tests
174+
run: npm run test:integration -- --reporters="default" --reporters="jest-junit"
175+
- name: Store Integration Test Results
176+
uses: actions/upload-artifact@v3
177+
with:
178+
name: integration-test-output
179+
path: ./test-results/*
180+
deploy-npm:
181+
needs: [test-integration, test-unit]
182+
runs-on: ubuntu-latest
183+
steps:
184+
- uses: actions/checkout@v4
185+
- name: Retrieve npm dependencies
186+
uses: actions/cache@v3
187+
with:
188+
path:
189+
node_modules
190+
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
191+
- name: Retrieve Dist Directory
192+
uses: actions/cache@v3
193+
with:
194+
path:
195+
./dist
196+
key: ${{ runner.os }}-dist-${{ hashFiles('package-lock.json') }}
197+
- run: |
198+
if [[ ${{contains(github.ref, 'hotfix')}} ]]; then
199+
sed -e "s|hotfix/REPLACE|${{ github.ref_name }}|" --in-place release.config.js
200+
fi
201+
- name: Semantic Release
81202
env:
82-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
83-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84-
run: |
85-
npx --no -- semantic-release $([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "--dry-run")
203+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
204+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
205+
run: npx --no -- semantic-release
206+
deploy-gh-pages:
207+
needs: [test-integration, test-unit]
208+
runs-on: ubuntu-latest
209+
steps:
210+
- uses: actions/checkout@v4
211+
- name: Retrieve npm dependencies
212+
uses: actions/cache@v3
213+
with:
214+
path:
215+
node_modules
216+
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
217+
- name: Retrieve Build Directory
218+
uses: actions/cache@v3
219+
with:
220+
path:
221+
./build
222+
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
223+
- name: Deploy playground to GitHub Pages
224+
uses: peaceiris/actions-gh-pages@v3
225+
with:
226+
github_token: ${{ secrets.GITHUB_TOKEN }}
227+
publish_dir: ./build
228+
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ npm-*
2323

2424
# Downloaded during "npm install"
2525
/static/microbit
26+
27+
# for act
28+
.secrets

0 commit comments

Comments
 (0)