Skip to content

Migrate scratch-gui to GitHub Actions #19

Migrate scratch-gui to GitHub Actions

Migrate scratch-gui to GitHub Actions #19

Workflow file for this run

name: CI/CD
on:
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
pull_request: # Runs whenever a pull request is created or updated
push: # Runs whenever a commit is pushed to the repository
branches: [master, develop, beta, hotfix/*]
concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || 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:
TRIGGER_DEPLOY: ${{ startsWith(github.ref, 'refs/heads/master') }}
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.event_name == 'pull_request'
- 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: Cache node modules
id: cache-nodemodules
uses: actions/cache@v3
env:
cache-name: ${{ secrets.CACHE_NAME }}
with:
# caching node_modules
path:
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- name: Cache microbit
id: cache-microbit
uses: actions/cache@v3
with:
path:
static/microbit
key: ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }}
- name: Cache node modules
id: cache-generated
uses: actions/cache@v3
with:
path:
src/generated
key: ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }}
- name: Install Dependencies
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
run: npm ci
# - name: Lint
# run: |
# npm run test:lint -- --quiet --output-file test-results/eslint-results.xml --format junit
# - name: Store Lint Artifacts
# uses: actions/upload-artifact@v3
# with:
# name: test-output
# path: ./test-results/*
# test-unit:
# needs: setup
# runs-on: ubuntu-latest
# env:
# JEST_JUNIT_OUTPUT_NAME: unit-results.xml
# steps:
# - uses: actions/checkout@v4
# - name: Cache NPM dependencies
# uses: actions/cache@v3
# with:
# path:
# node_modules
# src/generated
# static/microbit
# key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
# - name: Run Unit Tests
# run: npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov --maxWorkers="2"
build:
needs: setup
env:
NODE_ENV: production
NODE_OPTIONS: --max-old-space-size=4000
DETECT_CHROMEDRIVER_VERSION: "true"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Retrieve Node Modules
uses: actions/cache@v3
with:
path:
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- name: Retrieve Microbit
uses: actions/cache@v3
with:
path:
static/microbit
key: ${{ runner.os }}-microbit-${{ hashFiles('package-lock.json') }}
- name: Retrieve Generated
uses: actions/cache@v3
with:
path:
src/generated
key: ${{ runner.os }}-generated-${{ hashFiles('package-lock.json') }}
- run: npm run build
# - name: Setup & Test
# run: |
# mkdir -p ./test/results
# npm test
# - name: Generate release version
# run: |
# export RELEASE_TIMESTAMP=$(date +'%Y%m%d%H%M%S')
# export VPKG=$($(npm bin)/json -f package.json version)
# export VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}
# echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
# if [[ "${GITHUB_REF##*/}" == hotfix/* ]]; then
# echo "NPM_TAG=hotfix" >> $GITHUB_ENV
# else
# echo "NPM_TAG=latest" >> $GITHUB_ENV
# fi
# - name: Build
# run: |
# npm run build
# npm --no-git-tag-version version $RELEASE_VERSION
# - name: Semantic release (configured to run dry if branch is other than 'master')
# env:
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# npx --no -- semantic-release $([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "--dry-run")