Skip to content

Commit

Permalink
Merge pull request #2 from duttonw/main
Browse files Browse the repository at this point in the history
Add CICD pipeline to publish to github package with skeleton for npmjs
  • Loading branch information
duttonw authored May 1, 2024
2 parents f2506b4 + 710d355 commit 3c5d3e0
Show file tree
Hide file tree
Showing 14 changed files with 680 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .github/dependabot.yml
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
19 changes: 19 additions & 0 deletions .github/releases.yml
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
59 changes: 59 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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: Build

on:
push:
pull_request:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- 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: 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

- run: npm run build

- run: npm run test

- uses: actions/[email protected]
with:
name: Tokens
path: ./dist
148 changes: 148 additions & 0 deletions .github/workflows/githubPackage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# 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:
# Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:
# When main is updated (latest)
push:
# branches:
# - 'main'
#On versioned releases
tags:
- v*.*.*

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- 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: 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

- run: npm run build
- run: npm run test
- uses: actions/[email protected]
with:
name: Tokens
path: ./dist


publish-gpr:
needs: build
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 install
- run: npm ci

- 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)
awk -v scope="$GITHUB_REPOSITORY_OWNER" '{
if ($0 ~ /"name": "@[a-zA-Z0-9_-]+\//) {
sub(/@[a-zA-Z0-9_-]+\//, "@" scope "/")
}
print
}' 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}}

- run: npm publish --tag ${{ steps.latest_tag.outputs.latest-tag }}
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
35 changes: 35 additions & 0 deletions .github/workflows/npmjsPackage.yml.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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:
tags:
- v*.*.*


jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
16 changes: 16 additions & 0 deletions .github/workflows/release.yml
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 }}
93 changes: 93 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
## 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


- run: npm ci

- name: Update
run: |
force="${{ github.event.inputs.force }}"
dry="${{ github.event.inputs.dry }}"
bump="${{ github.event.inputs.bump }}"
if [ "$bump" = "" ]; then
bump="patch"
fi
# Bump Version
npm version "$bump"
- name: Push git tags
if: ${{ env.HAVE_GIT_DEPLOY_KEY == 'true' }}
run: |
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
Loading

0 comments on commit 3c5d3e0

Please sign in to comment.