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
This commit is contained in:
Ron de las Alas committed 2023-11-13 18:13:49 -05:00
1 parent 4ca0990634
commit c9830328bd
6 files changed
+7854 -32502

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
node_modules/*
build/*
dist/*
test/*
src/examples/*
+190 -47
View File
@@ -1,10 +1,8 @@
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
workflow_dispatch:
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 }}"
@@ -17,10 +15,13 @@ permissions:
pull-requests: write # comment on released pull requests
jobs:
ci-cd:
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
@@ -29,7 +30,6 @@ jobs:
with:
cache: "npm"
node-version-file: ".nvmrc"
- name: Info
run: |
cat <<EOF
@@ -38,48 +38,191 @@ jobs:
GitHub ref: ${{ github.ref }}
GitHub head ref: ${{ github.head_ref }}
EOF
- name: Install Google Chrome
uses: browser-actions/setup-chrome@v1
- name: Install Dependencies
run: npm install
- name: Lint
run: |
npm run test:lint -- --quiet --output-file test-results/eslint/results.xml --format junit
- name: Store Lint Results
uses: actions/upload-artifact@v3
with:
chrome-version: beta
name: lint-output
path: ./test-results/*
- 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') }}
test-unit:
needs: setup
runs-on: ubuntu-latest
env:
JEST_JUNIT_OUTPUT_NAME: unit-results.xml
JEST_JUNIT_OUTPUT_DIR: test-results/unit
steps:
- uses: actions/checkout@v4
- name: Cache NPM dependencies
uses: actions/cache@v3
with:
path:
node_modules
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"
- name: Store Unit Test Results
uses: actions/upload-artifact@v3
with:
name: unit-test-output
path: ./test-results/*
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
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
test-integration:
needs: build
runs-on: ubuntu-latest
env:
JEST_JUNIT_OUTPUT_NAME: results.txt
JEST_JUNIT_OUTPUT_DIR: test-results/integration
steps:
- uses: actions/checkout@v4
- name: Install Chrome Dependencies
run: |
sudo apt-get update
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
- name: Retrieve npm dependencies
uses: actions/cache@v3
with:
path:
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
- name: Retrieve Build
uses: actions/cache@v3
with:
path:
./build
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
- uses: browser-actions/setup-chrome@v1
with:
chrome-version: stable
id: setup-chrome
- name: Chrome Info
run: |
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
${{ steps.setup-chrome.outputs.chrome-path }} --version
- name: Install dependencies
run: npm ci
- 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')
- run: |
echo Installed chromium version: ${{ steps.setup-chrome.outputs.chrome-version }}
${{ steps.setup-chrome.outputs.chrome-path }} --version
- name: Run Integration Tests
run: npm run test:integration -- --reporters="default" --reporters="jest-junit"
- name: Store Integration Test Results
uses: actions/upload-artifact@v3
with:
name: integration-test-output
path: ./test-results/*
deploy-npm:
needs: [test-integration, test-unit]
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 Dist Directory
uses: actions/cache@v3
with:
path:
./dist
key: ${{ runner.os }}-dist-${{ hashFiles('package-lock.json') }}
- run: |
if [[ ${{contains(github.ref, 'hotfix')}} ]]; then
sed -e "s|hotfix/REPLACE|${{ github.ref_name }}|" --in-place release.config.js
fi
- name: Semantic Release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx --no -- semantic-release $([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "--dry-run")
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx --no -- semantic-release
deploy-gh-pages:
needs: [test-integration, test-unit]
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 }}"
+3
View File
@@ -23,3 +23,6 @@ npm-*
# Downloaded during "npm install"
/static/microbit
# for act
.secrets
+7658 -32454
View File
File diff suppressed because it is too large. Load diff
-1
View File
@@ -14,7 +14,6 @@
"build": "npm run clean && webpack --colors --bail",
"clean": "rimraf ./build && mkdirp build && rimraf ./dist && mkdirp dist",
"deploy": "touch build/.nojekyll && gh-pages -t -d build -m \"[skip ci] Build for $(git log --pretty=format:%H -n1)\"",
"prepare": "husky install",
"prepublish": "node scripts/prepublish.mjs",
"prune": "./prune-gh-pages.sh",
"i18n:push": "tx-push-src scratch-editor interface translations/en.json",
+1
View File
@@ -9,6 +9,7 @@ module.exports = {
process: true
},
rules: {
'no-warning-comments': 'off',
'import/no-mutable-exports': 'error',
'import/no-commonjs': 'error',
'import/no-amd': 'error',