Merge pull request #822 from qld-gov-au/dependabot/npm_and_yarn/devel… #3715
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
# 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 | |
strategy: | |
matrix: | |
node: [ '20'] | |
name: Build and Deploy on Node ${{ matrix.node }} | |
steps: | |
- run: echo ${{github.ref}} | |
- uses: actions/checkout@v4 | |
- name: Cache node modules | |
id: cache-npm | |
uses: actions/cache@v3 | |
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' | |
always-auth: 'true' | |
registry-url: 'https://nexus.tools.services.qld.gov.au/nexus/repository/npm_all/' | |
- name: npmrc #run on lint step (Which is cached) | |
run: | | |
npm -v | |
node -v | |
cat /home/runner/work/_temp/.npmrc | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NEXUSREADONLY2NPMTOKEN }} | |
- name: Install | |
run: | # Install packages | |
npm install --prefer-offline --no-audit --ignore-scripts | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NEXUSREADONLY2NPMTOKEN }} | |
# `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: | | |
npm run lint | |
- name: Test | |
run: | | |
npm run test | |
- name: Build 🔧 | |
run: | # build the files | |
npm run build | |
- name: Build storybook 🔧 | |
run: | # build the Storybook files | |
npm run build-storybook | |
- name: setup Package | |
run: | | |
ls -ltr | |
mkdir -p ./target/docs | |
cp -r ./storybook-static ./target/docs | |
cp -r ./dist/* ./target/. | |
- name: Extract branch name | |
shell: bash | |
run: echo "branch=$(echo ${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 | |
run: | | |
set -x | |
cp -r ./binary-repo/* ./dist | |
- name: "Set environment variables if TARGET_REPO and/or TARGET_CDN_REPO exists" | |
id: set-TARGET_REPO-exists | |
run: | | |
if [ -n "${{ vars.TARGET_REPO }}" ]; then | |
echo "TARGET_REPO=true" >> $GITHUB_ENV | |
else | |
echo "TARGET_REPO=false" >> $GITHUB_ENV | |
fi | |
if [ -n "${{ vars.TARGET_CDN_REPO }}" ]; then | |
echo "TARGET_CDN_REPO=true" >> $GITHUB_ENV | |
else | |
echo "TARGET_CDN_REPO=false" >> $GITHUB_ENV | |
fi | |
- name: Publish | |
uses: qld-gov-au/gha-publish-to-git@master | |
with: | |
#repository: qld-gov-au/formio-qld ### if forked, change to your own binary repo for output tracking | |
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() && env.TARGET_REPO == 'true' }} | |
- name: Publish to formio-qld-cdn | |
uses: qld-gov-au/gha-cdn-version-tree-by-tag-builder@main | |
with: | |
#repository: 'qld-gov-au/formio-qld-cdn' ### if forked, change to your own binary cdn repo for output making when tagged | |
repository: ${{ vars.TARGET_CDN_REPO }} | |
git_ref: '${{ github.ref }}' | |
branch: 'release' | |
github_token: '${{ secrets.GH_TOKEN }}' | |
github_pat: '${{ secrets.GH_PAT }}' | |
source_folder: dist | |
if: ${{ success() && env.TARGET_CDN_REPO == 'True' }} | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: Package ${{ matrix.node }} | |
path: ./target | |