Skip to content

Commit 522209a

Browse files
fergusbissetclaude
andcommitted
Add GitHub Packages publish workflow
- Alternative to npm public registry while waiting for npm org access - Uses GITHUB_TOKEN (automatic, no secret setup needed) - Supports same version bump and tagging features as npm workflow Install from GitHub Packages: npm install @nhsdigital/fdp-design-system --registry=https://npm.pkg.github.com 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent bb6f4b2 commit 522209a

File tree

1 file changed

+89
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)