Skip to content

Commit

Permalink
QOLOE-514 github action basics
Browse files Browse the repository at this point in the history
  • Loading branch information
duttonw committed Sep 2, 2024
1 parent 2f8f858 commit fe7ea14
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2
updates:
- package-ecosystem: npm
versioning-strategy: increase
directory: "/"
target-branch: "develop"
schedule:
interval: daily
time: "19:00"
groups:
storybook:
patterns:
- "@storybook/*"
- storybook
- "@chromatic-com/storybook"
- "@whitespace/storybook-addon-html"
- "chromatic"
eslint:
patterns:
- "eslint*"
- "@stylistic/eslint-plugin-js"
- "esbuild-plugin-eslint"
esbuild:
patterns:
- "esbuild*"
open-pull-requests-limit: 10
reviewers:
- qld-gov-au/qld-online-dev-team
32 changes: 32 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# .github/release.yml
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes
# https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels

changelog:
categories:
- title: Breaking Changes 🛠
labels:
- Semver-Major
- breaking-change

- title: 🏕 Features
labels:
- '*'
exclude:
labels:
- dependencies
- bug
- Semver-Major
- breaking-change
authors:
- dependabot[bot]

- title: 🐛 Bug Fixes
labels:
- bug

- title: 👒 Dependencies
labels:
- dependencies
authors:
- dependabot[bot]
76 changes: 76 additions & 0 deletions .github/workflows/compile.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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: 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
#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
- uses: actions/upload-artifact@v4.3.1
with:
name: Package
path: ./dist
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Github Release Notes

on:
push:
tags:
- v*.*.*

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
actions: read
id-token: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Release
run: gh release create "${GITHUB_REF#refs/tags/}" --generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111 changes: 111 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
## See https://github.com/marella/material-symbols/blob/main/.github/workflows/update.yml where inspiration for this script came from
name: Version Increment

on:
#schedule:
# - cron: '23 1 * * MON' # Runs at 01:23 UTC on Monday
workflow_dispatch:
inputs:
force:
description: Force Update
default: '0'
dry:
description: Dry Run
default: '1'
bump:
type: choice
description: Bump Version
options:
- patch
- minor
- major

jobs:
update:
runs-on: ubuntu-latest
env:
HAVE_GIT_DEPLOY_KEY: ${{ secrets.DEPLOY_KEY != '' }}
steps:

- uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}

- uses: git-actions/set-user@v1

- 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


- uses: actions/setup-node@v4 #setup registry to github package repo
with:
node-version: 20

- name: npm ci (don't run prepare)
run: npm ci --ignore-scripts

- name: Update & Push git tags
if: ${{ env.HAVE_GIT_DEPLOY_KEY == 'true' }}
run: |
force="${{ github.event.inputs.force }}"
dry="${{ github.event.inputs.dry }}"
bump="${{ github.event.inputs.bump }}"
if [ "$bump" = "" ]; then
bump="patch"
fi
# Fetch the latest tags
git fetch --tags
# Get the latest tag
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
# Get the current commit hash
CURRENT_COMMIT=$(git rev-parse HEAD)
# Check if there are changes between the latest tag and the current commit
if git diff --quiet $LATEST_TAG $CURRENT_COMMIT; then
if [ "$force" != "1" ]; then
echo "No changes detected between the latest tag ($LATEST_TAG) and the current commit ($CURRENT_COMMIT)." >> $GITHUB_STEP_SUMMARY
exit 0
else
echo "Force flag set continuing: No changes detected between the latest tag ($LATEST_TAG) and the current commit ($CURRENT_COMMIT)." >> $GITHUB_STEP_SUMMARY
fi
else
echo "Changes detected between the latest tag ($LATEST_TAG) and the current commit ($CURRENT_COMMIT)." >> $GITHUB_STEP_SUMMARY
fi
# Bump Version
npm version "$bump"

dry="${{ github.event.inputs.dry }}"
# Push
if [ "$dry" = "1" ]; then
exit 0
fi
git push --follow-tags

- name: Git Commit - Is Skipped
if: ${{ env.HAVE_GIT_DEPLOY_KEY != 'true' }}
run: |
echo "### Deployment config not configured" >> $GITHUB_STEP_SUMMARY
echo "secrets.DEPLOY_KEY not existing, npm version can't be pushed" >> $GITHUB_STEP_SUMMARY
echo "If this is a fork, please setup your own personal service account to publish to your own repo" >> $GITHUB_STEP_SUMMARY
echo "## We recommend using a service account with the least permissions necessary." >> $GITHUB_STEP_SUMMARY
echo "[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)" >> $GITHUB_STEP_SUMMARY

0 comments on commit fe7ea14

Please sign in to comment.