|
1 | 1 | name: CI/CD |
2 | 2 |
|
3 | 3 | 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: |
6 | 5 | push: # Runs whenever a commit is pushed to the repository |
7 | | - branches: [master, develop, beta, hotfix/*] |
8 | 6 |
|
9 | 7 | concurrency: |
10 | 8 | group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" |
@@ -17,10 +15,13 @@ permissions: |
17 | 15 | pull-requests: write # comment on released pull requests |
18 | 16 |
|
19 | 17 | jobs: |
20 | | - ci-cd: |
| 18 | + setup: |
21 | 19 | runs-on: ubuntu-latest |
22 | 20 | env: |
23 | 21 | 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 |
24 | 25 | steps: |
25 | 26 | - uses: actions/checkout@v4 |
26 | 27 | - uses: wagoid/commitlint-github-action@v5 |
|
29 | 30 | with: |
30 | 31 | cache: "npm" |
31 | 32 | node-version-file: ".nvmrc" |
32 | | - |
33 | 33 | - name: Info |
34 | 34 | run: | |
35 | 35 | cat <<EOF |
@@ -38,48 +38,191 @@ jobs: |
38 | 38 | GitHub ref: ${{ github.ref }} |
39 | 39 | GitHub head ref: ${{ github.head_ref }} |
40 | 40 | 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 |
62 | 44 | 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 |
76 | 151 | 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 |
81 | 202 | 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 }}" |