Update ci-cd.yml #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
workflow_dispatch: | |
push: | |
concurrency: | |
group: "${{ github.workflow }} @ ${{ github.head_ref || github.ref }}" | |
cancel-in-progress: true | |
permissions: | |
contents: write # publish a GitHub release | |
pages: write # deploy to GitHub Pages | |
issues: write # comment on released issues | |
pull-requests: write # comment on released pull requests | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
env: | |
DETECT_CHROMEDRIVER_VERSION: "true" | |
JEST_JUNIT_OUTPUT_DIR: test-results | |
NODE_OPTIONS: --max-old-space-size=4000 | |
steps: | |
- uses: actions/checkout@v4 | |
# - uses: wagoid/commitlint-github-action@v5 | |
# if: github.ref_name == 'develop' | |
- uses: actions/setup-node@v3 | |
with: | |
cache: "npm" | |
node-version-file: ".nvmrc" | |
- name: Info | |
run: | | |
cat <<EOF | |
Node version: $(node --version) | |
NPM version: $(npm --version) | |
GitHub ref: ${{ github.ref }} | |
GitHub head ref: ${{ github.head_ref }} | |
EOF | |
- name: Install Dependencies | |
run: npm ci | |
- name: Cache node_modules | |
id: cache-nodemodules | |
uses: actions/cache@v3 | |
with: | |
path: | |
node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} | |
- name: Cache src/generated | |
id: cache-generated | |
uses: actions/cache@v3 | |
with: | |
path: | |
src/generated | |
key: ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }} | |
- name: Cache static/microbit | |
id: cache-static | |
uses: actions/cache@v3 | |
with: | |
path: | |
static/microbit | |
key: ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }} | |
build: | |
needs: [setup] | |
env: | |
NODE_OPTIONS: --max-old-space-size=4000 | |
DETECT_CHROMEDRIVER_VERSION: "true" | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
cache: "npm" | |
node-version-file: ".nvmrc" | |
- name: Retrieve node_modules | |
uses: actions/cache@v3 | |
with: | |
path: | |
node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} | |
- name: Retrieve src/generated | |
uses: actions/cache@v3 | |
with: | |
path: | |
src/generated | |
key: ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }} | |
- name: Retireve static/microbit | |
uses: actions/cache@v3 | |
with: | |
path: | |
static/microbit | |
key: ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }} | |
- name: Run Build | |
env: | |
NODE_ENV: production | |
run: npm run build | |
- name: Cache Build Directory | |
uses: actions/cache@v3 | |
with: | |
path: | |
./build | |
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }} | |
- name: Cache Dist Directory | |
uses: actions/cache@v3 | |
with: | |
path: | |
./dist | |
key: ${{ runner.os }}-dist-${{ hashFiles('package-lock.json') }} | |
- name: Store Build Output | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-output | |
path: ./build | |
- name: Store Dist Output | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dist-output | |
path: ./dist | |
deploy-gh-pages: | |
needs: [build] | |
if: ${{ startsWith(github.ref, 'refs/heads/develop') }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Retrieve npm dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | |
node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} | |
- name: Retrieve Build Directory | |
uses: actions/cache@v3 | |
with: | |
path: | |
./build | |
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }} | |
- name: Deploy playground to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./build | |
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" |