generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (78 loc) · 2.88 KB
/
github-packages-publish.yml
File metadata and controls
89 lines (78 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Publish to GitHub Packages
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Optional semver bump to apply before publishing (patch, minor, major, prerelease)'
required: false
type: string
preid:
description: 'Prerelease identifier when version is prerelease (e.g., alpha, beta, rc)'
required: false
type: string
tag:
description: 'NPM dist-tag to publish under (e.g., latest, alpha, beta, next)'
required: false
default: 'latest'
type: string
permissions:
contents: write
packages: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node for GitHub Packages
uses: actions/setup-node@v6
with:
node-version: 20
registry-url: 'https://npm.pkg.github.com'
scope: '@nhsdigital'
- name: Install dependencies
run: npm ci
- name: Optionally bump version (manual dispatch only)
if: ${{ github.event_name == 'workflow_dispatch' && inputs.version != '' }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
if [ "${{ inputs.version }}" = "prerelease" ]; then
npm version prerelease --preid=${{ inputs.preid || 'alpha' }} -m "chore(release): %s"
else
npm version ${{ inputs.version }} -m "chore(release): %s"
fi
- name: Run tests
run: |
npm run lint
npm run test:components
npm run test:ssr-components
- name: Build
run: npm run build
- name: Publish to GitHub Packages
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ -n "${{ inputs.tag }}" ] && [ "${{ inputs.tag }}" != "latest" ]; then
npm publish --registry=https://npm.pkg.github.com --tag ${{ inputs.tag }}
else
npm publish --registry=https://npm.pkg.github.com
fi
- name: Push version bump (when version bumped)
if: ${{ github.event_name == 'workflow_dispatch' && inputs.version != '' }}
run: |
VERSION=$(node -p "require('./package.json').version")
git push origin HEAD
git tag v$VERSION
git push origin v$VERSION
- name: Summary
run: |
VERSION=$(node -p "require('./package.json').version")
echo "Published @nhsdigital/fdp-design-system@$VERSION to GitHub Packages" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Install with:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "npm install @nhsdigital/fdp-design-system --registry=https://npm.pkg.github.com" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY