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