Skip to content

Merge pull request #297 from DEFRA/fix/DF-648-form-status #236

Merge pull request #297 from DEFRA/fix/DF-648-form-status

Merge pull request #297 from DEFRA/fix/DF-648-form-status #236

Workflow file for this run

name: Publish Engine Plugin
on:
workflow_dispatch:
inputs:
version_bump:
description: 'Type of version bump to perform'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
npm_tag:
description: 'Custom npm tag (only needed for non-standard branches; release branches will use their major version tag automatically)'
required: false
default: 'beta'
type: string
dry_run:
description: 'Dry run (no actual publishing)'
required: false
default: true
type: boolean
push:
branches:
- main
- 'release/v[0-9]*'
concurrency:
group: publish-engine-plugin-${{ github.ref }}
permissions:
contents: write
packages: write
jobs:
determine-path:
name: Determine Workflow Path
runs-on: ubuntu-24.04
outputs:
workflow-path: ${{ steps.check-path.outputs.workflow-path }}
version-bump: ${{ steps.check-path.outputs.version-bump }}
npm-tag: ${{ steps.check-path.outputs.npm-tag }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Determine workflow path
id: check-path
run: bash .github/scripts/publish/determine-workflow-path.sh "${{ github.event_name }}" "${{ github.event.inputs.version_bump }}" "${{ github.event.inputs.npm_tag }}"
build:
name: Build
needs: [determine-path]
if: needs.determine-path.outputs.workflow-path != 'skip'
runs-on: ubuntu-24.04
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache dependencies
uses: actions/cache@v4
id: npm-install-cache
with:
enableCrossOsArchive: true
key: npm-install-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
path: node_modules
- name: Cache build
uses: actions/cache@v4
with:
enableCrossOsArchive: true
key: npm-build-${{ runner.os }}-${{ github.sha }}
path: |
.server
.public
- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: 'npm'
node-version-file: .nvmrc
- name: Install dependencies
if: steps.npm-install-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Run build
run: npm run build
publish:
name: Publish
needs: [determine-path, build]
if: needs.determine-path.outputs.workflow-path != 'skip'
runs-on: ubuntu-24.04
environment: production
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ github.ref }}
- name: Display workflow path
run: |
echo "⭐ Executing ${{ needs.determine-path.outputs.workflow-path }} workflow path"
echo "Version bump type: ${{ needs.determine-path.outputs.version-bump }}"
echo "NPM Tag: ${{ needs.determine-path.outputs.npm-tag || '<auto-detect>' }}"
- name: Restore dependencies
uses: actions/cache/restore@v4
with:
enableCrossOsArchive: true
key: npm-install-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
path: node_modules
- name: Restore build artifacts
uses: actions/cache/restore@v4
with:
enableCrossOsArchive: true
key: npm-build-${{ runner.os }}-${{ github.sha }}
path: |
.server
.public
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org
scope: '@defra'
- name: Determine version bump details
id: version-details
run: bash .github/scripts/publish/version-bump-details.sh "${{ github.ref_name }}" "${{ needs.determine-path.outputs.version-bump }}"
- name: Update package version
run: |
echo "Bumping version: $VERSION_TYPE"
npm version $VERSION_TYPE --git-tag-version false --save
- name: Commit and push updates
run: |
git config user.name github-actions
git config user.email github-actions@github.com
NEW_VERSION=$(npm pkg get version | tr -d \")
git commit -am "v$NEW_VERSION [skip ci]" && git push
- name: Publish to npm with appropriate dist-tag
run: bash .github/scripts/publish/publish-to-npm.sh "${{ github.ref_name }}" "${{ needs.determine-path.outputs.workflow-path }}" "${{ needs.determine-path.outputs.npm-tag }}" "${{ github.event.inputs.dry_run }}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
generate-docs:
name: Generate and Publish Documentation
needs: [publish]
if: needs.determine-path.outputs.workflow-path != 'skip' && (startsWith(github.ref, 'refs/heads/release/v') || github.ref == 'refs/heads/main')
runs-on: ubuntu-24.04
permissions:
contents: read
pages: write
id-token: write
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Restore dependencies
uses: actions/cache/restore@v4
with:
enableCrossOsArchive: true
key: npm-install-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
path: node_modules
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Generate and process documentation
run: bash .github/scripts/docs/generate-and-publish-docs.sh "${{ github.ref_name }}" "$(npm pkg get version | tr -d \")"
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './docs-site'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4