forked from qld-gov-au/qgds-bootstrap5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce CICD workflow versioning and package publishing
- Loading branch information
Showing
7 changed files
with
477 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: npm | ||
directory: "/" | ||
target-branch: "develop" | ||
schedule: | ||
interval: daily | ||
time: "19:00" | ||
groups: | ||
storybook: | ||
patterns: | ||
- "@storybook/*" | ||
- storybook | ||
open-pull-requests-limit: 10 | ||
reviewers: | ||
- qld-gov-au/qld-online-dev-team |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# .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 | ||
- title: 👒 Dependencies | ||
labels: | ||
- dependencies |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | ||
|
||
name: Publish NPM Github Package store | ||
|
||
on: | ||
|
||
push: | ||
#On versioned releases | ||
tags: | ||
- v*.*.* | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
inputs: | ||
force: | ||
type: choice | ||
description: Retry Publish Version | ||
options: | ||
- No | ||
- Yes | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node: [ '20' ] | ||
name: Lint, Test, Build and Deploy on Node ${{ matrix.node }} | ||
steps: | ||
- uses: actions/[email protected] | ||
|
||
- 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/[email protected] | ||
with: | ||
node-version: ${{ matrix.node }} | ||
cache: 'npm' | ||
#always-auth: 'true' | ||
#registry-url: 'https://nexus.tools.services.qld.gov.au/nexus/repository/npm_all/' | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: Install #run on lint step (Which is cached) | ||
run: | # Install packages per package-lock.json only | ||
npm ci | ||
- 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 | ||
|
||
|
||
|
||
publish-gpr: | ||
needs: build | ||
env: | ||
HAVE_DEPLOY_KEY: ${{ secrets.GITHUB_TOKEN != '' }} | ||
#When run on push tags, force is '', default for workflow_dispatch is No so you can't trigger without a double action | ||
DO_DEPLOYMENT: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.force == 'Yes' }} | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- 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 | ||
registry-url: https://npm.pkg.github.com/ | ||
# Defaults to the user or organization that owns the workflow file | ||
#scope: '@${username}' | ||
cache: 'npm' | ||
|
||
- name: npm config output (including .npmrc file) | ||
run: | | ||
npm -v | ||
node -v | ||
cat /home/runner/work/_temp/.npmrc | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- run: npm ci | ||
|
||
- name: Build 🔧 | ||
run: | # build the files | ||
npm run build | ||
|
||
- name: "Update package scope, export package name" | ||
id: package_details | ||
run: | | ||
echo "replacing npm scope to repo owner GITHUB_REPOSITORY_OWNER = $GITHUB_REPOSITORY_OWNER" | ||
temp_file=$(mktemp) | ||
package=${GITHUB_REPOSITORY_OWNER,,} | ||
awk -v scope="$package" '{ | ||
if ($0 ~ /"name": "@[a-zA-Z0-9_-]+\//) { | ||
sub(/@[a-zA-Z0-9_-]+\//, "@" scope "/") | ||
} | ||
}' package.json > "$temp_file" && mv "$temp_file" package.json | ||
echo "package.json updated" | ||
cat package.json | ||
echo "package=`npm pkg get name`" >> $GITHUB_STATE | ||
- uses: tobysmith568/npm-publish-latest-tag@v1 | ||
id: latest_tag | ||
with: | ||
package-json: ./package.json | ||
|
||
# - uses: actions/delete-package-versions@v5 | ||
# with: #Delete all except latest 3 package versions excluding major versions as per semver from a repo not having access to package | ||
## owner: 'github' | ||
# package-name: ${{ steps.package_details.outputs.package }} | ||
# package-type: 'npm' | ||
## token: ${{ secrets.GITHUB_PAT }} | ||
# min-versions-to-keep: 3 | ||
# ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$' | ||
# env: | ||
# NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
|
||
- name: Publish | ||
run: npm publish --tag ${{ steps.latest_tag.outputs.latest-tag }} | ||
if: ${{ env.HAVE_DEPLOY_KEY == 'true' && DO_DEPLOYMENT == 'true' }} | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | ||
|
||
name: Publish NPM Package | ||
|
||
on: | ||
push: | ||
#On versioned releases | ||
tags: | ||
- v*.*.* | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
inputs: | ||
force: | ||
type: choice | ||
description: Retry Publish Version | ||
options: | ||
- No | ||
- Yes | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node: [ '20' ] | ||
name: Lint, Test, Build and Deploy on Node ${{ matrix.node }} | ||
steps: | ||
- uses: actions/[email protected] | ||
|
||
- 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/[email protected] | ||
with: | ||
node-version: ${{ matrix.node }} | ||
cache: 'npm' | ||
#always-auth: 'true' | ||
#registry-url: 'https://nexus.tools.services.qld.gov.au/nexus/repository/npm_all/' | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: Install #run on lint step (Which is cached) | ||
run: | # Install packages per package-lock.json only | ||
npm ci | ||
- 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 | ||
|
||
publish-npm: | ||
needs: build | ||
env: | ||
HAVE_DEPLOY_KEY: ${{ secrets.npm_token != '' }} | ||
#When run on push tags, force is '', default for workflow_dispatch is No so you can't trigger without a double action | ||
DO_DEPLOYMENT: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.force == 'Yes' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- 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 | ||
with: | ||
node-version: 20 | ||
cache: 'npm' | ||
|
||
- name: npm config output (including .npmrc file) | ||
run: | | ||
npm -v | ||
node -v | ||
cat /home/runner/work/_temp/.npmrc | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- run: npm ci | ||
|
||
- name: Build 🔧 | ||
run: | # build the files | ||
npm run build | ||
# - name: "Update package scope, export package name" | ||
# id: package_details | ||
# run: | | ||
# echo "replacing npm scope to repo owner GITHUB_REPOSITORY_OWNER = $GITHUB_REPOSITORY_OWNER" | ||
# temp_file=$(mktemp) | ||
# package=${GITHUB_REPOSITORY_OWNER,,} | ||
# awk -v scope="$package" '{ | ||
# if ($0 ~ /"name": "@[a-zA-Z0-9_-]+\//) { | ||
# sub(/@[a-zA-Z0-9_-]+\//, "@" scope "/") | ||
# } | ||
# }' package.json > "$temp_file" && mv "$temp_file" package.json | ||
# echo "package.json updated" | ||
# cat package.json | ||
# echo "package=`npm pkg get name`" >> $GITHUB_STATE | ||
# | ||
# - uses: tobysmith568/npm-publish-latest-tag@v1 | ||
# id: latest_tag | ||
# with: | ||
# package-json: ./package.json | ||
# | ||
- name: Publish | ||
run: npm publish | ||
if: ${{ env.HAVE_DEPLOY_KEY == 'true' && DO_DEPLOYMENT == 'true' }} | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} | ||
|
||
- name: NPM Publish - Is Skipped | ||
if: ${{ env.HAVE_DEPLOY_KEY != 'true' }} | ||
run: | | ||
echo "### Deployment config not configured" >> $GITHUB_STEP_SUMMARY | ||
echo "secrets.npm_token not existing, npm publish 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 npmjs.org prefix" >> $GITHUB_STEP_SUMMARY | ||
echo "## We recommend using a service account with the least permissions necessary." >> $GITHUB_STEP_SUMMARY | ||
echo "[npm Access Tokens](https://www.npmjs.com/settings/duttonw/tokens)" >> $GITHUB_STEP_SUMMARY |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- v*.*.* | ||
|
||
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 }} |
Oops, something went wrong.