Skip to content

Build and Test

Build and Test #12

Workflow file for this run

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Build and Test
on:
push:
pull_request:
concurrency:
group: compile-${{ github.workflow }}-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
env:
HAVE_CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN != '' }}
IS_CHROMATIC_DISABLED: ${{ vars.CHROMATIC_DISABLED == 'True' }}
strategy:
matrix:
node: [ '20' ]
name: Lint, Test, Build and Deploy on Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Install #run on lint step (Which is cached)
run: | # Install packages
npm install --prefer-offline --no-audit --ignore-scripts
# `npm rebuild` will run all those post-install scripts for us.
- name: rebuild and prepare
run: npm rebuild && npm run prepare --if-present
- name: Lint
run: |
echo "lint disabled at this time" #npm run lint
- name: Test
run: |
npm run test
- name: Integration Test
run: |
npm run test:integration
continue-on-error: true
- name: Build 🔧
run: | # build the files
npm run build
- uses: actions/upload-artifact@v4
with:
name: Package
path: ./dist
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
id: extract_branch
- name: display branch name
shell: bash
run: echo "${{ steps.extract_branch.outputs.branch }}"
- name: setup Publish with details for binary repo including package.json for reference
run: |
set -x
cp package.json ./dist
mkdir ./dist/.github
cp -r ./.binary-repo/* ./dist
cp -r ./.binary-repo/.github/* ./dist/.github
- name: Publish qgds-bootstrap5-release
uses: qld-gov-au/gha-publish-to-git@master
with:
repository: ${{ vars.TARGET_REPO }}
git_ref: '${{ github.ref }}'
branch: '${{ steps.extract_branch.outputs.branch }}'
github_token: '${{ secrets.GH_TOKEN }}'
github_pat: '${{ secrets.GH_PAT }}'
source_folder: dist
tag_branch: main
if: success()
- name: Publish to qld-gov-au/qgds-vanilla-cdn
uses: qld-gov-au/gha-cdn-version-tree-by-tag-builder@main
with:
repository: ${{ vars.TARGET_REPO_CDN }}
git_ref: '${{ github.ref }}'
branch: 'release'
github_token: '${{ secrets.GH_TOKEN }}'
github_pat: '${{ secrets.GH_PAT }}'
source_folder: dist
if: success()
- name: Build Storybook 🔧
run: | # build the Storybook files
npm run build-storybook
- name: Publish to Chromatic
if: ${{ github.actor != 'dependabot[bot]' && env.HAVE_CHROMATIC_PROJECT_TOKEN == 'true' && env.IS_CHROMATIC_DISABLED == 'false'}}
uses: chromaui/action@latest
# Options required to the GitHub Chromatic Action
with:
# 👇 Chromatic projectToken, refer to the manage page to obtain it.
token: ${{ secrets.GH_TOKEN }}
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
# 👇 tell Chromatic to rebuild the entire project when a file matching the pattern is changed https://www.chromatic.com/docs/github-actions/#enable-turbosnap
#externals: |
# *.sass
# public/**
onlyChanged: true # 👈 Required option to enable TurboSnap
storybookBuildDir: "storybook-static"
- name: Publish to Chromatic - Is Skipped
if: ${{ env.HAVE_CHROMATIC_PROJECT_TOKEN != 'true' }}
run: |
echo "### Chromatic not configured" >> $GITHUB_STEP_SUMMARY
echo "secrets.CHROMATIC_PROJECT_TOKEN not existing, chromatic did not publish" >> $GITHUB_STEP_SUMMARY
echo "If this is a fork, please setup your own personal chromatic at" >> $GITHUB_STEP_SUMMARY
echo "[chromatic setup](https://www.chromatic.com/setup)" >> $GITHUB_STEP_SUMMARY
- name: Package storybook files
uses: actions/upload-artifact@v4 #provide nice artifact
with:
name: Storybook
path: storybook-static