RELEASE: Build release to test #113
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'RELEASE: Build release' | |
| run-name: 'RELEASE: Build release to ${{inputs.environment}}' | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: Environment | |
| required: true # For UI consistency with other required options | |
| type: choice | |
| options: | |
| - test | |
| - production | |
| release_type: | |
| description: 'Release type' | |
| required: true | |
| type: choice | |
| options: | |
| - major | |
| - minor | |
| - patch | |
| - premajor | |
| - preminor | |
| - prepatch | |
| - prerelease | |
| preid: | |
| description: "Prerelease label (for example: 'beta')" | |
| type: string | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| build-release: | |
| name: Build release | |
| runs-on: Ubuntu-22.04 | |
| environment: ${{ inputs.environment == 'production' && 'production' || null }} | |
| env: | |
| RELEASE_TYPE: ${{inputs.release_type}} | |
| PREID: ${{inputs.preid}} | |
| steps: | |
| - name: Log inputs in the action summary | |
| run: | | |
| # Output the inputs in the summary before anything | |
| { | |
| echo "## Inputs" | |
| echo '|Input|Value|' | |
| echo '|-----|-----|' | |
| echo "|release_type|\`$RELEASE_TYPE\`|" | |
| echo "|preid|\`$PREID\`|" | |
| } >> $GITHUB_STEP_SUMMARY | |
| - name: Checkout | |
| uses: actions/checkout@v6.0.2 | |
| - name: Setup Node | |
| uses: actions/setup-node@v6.4.0 | |
| with: | |
| node-version-file: .nvmrc | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Update package version and CHANGELOG | |
| run: | | |
| npm version --no-git-tag-version --workspace govuk-frontend "$RELEASE_TYPE" --preid "$PREID" | |
| # After `npm version` runs, the `postversion` lifecycle hook script from the govuk-frontend package | |
| # will be run which then updates the CHANGELOG. | |
| # Save the new version number for access in future steps | |
| echo "PACKAGE_VERSION=$(npm run get-version --silent --workspace govuk-frontend)" >> $GITHUB_ENV | |
| - name: Generate release notes | |
| uses: actions/github-script@v9.0.0 | |
| with: | |
| script: | | |
| const { generateReleaseNotes } = await import('${{ github.workspace }}/shared/github-scripts/changelog-release-helper.mjs') | |
| generateReleaseNotes(process.env.PACKAGE_VERSION, { actor: '${{ github.actor }}', runId: '${{ github.run_id }}' }) | |
| - name: Build release | |
| run: npm run build:release | |
| - name: Output PR content in action summary | |
| run: | | |
| { | |
| echo '## PR body' | |
| cat release-notes-body | |
| echo '' | |
| echo '## Files in archive' | |
| echo '```diff' | |
| git diff | |
| echo '```' | |
| } >> $GITHUB_STEP_SUMMARY | |
| - name: Upload CHANGELOG as artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| path: CHANGELOG.md | |
| archive: false # Saves having to decompress the CHANGELOG | |
| - name: Create pull request | |
| if: inputs.environment == 'production' | |
| env: | |
| GH_TOKEN: ${{ secrets.CI_PAT }} | |
| run: | | |
| git config --global user.name '${{ github.actor }}' | |
| git config --global user.email '${{ github.actor }}@digital.cabinet-office.gov.uk' | |
| git add . | |
| git commit -m "Release ${{ inputs.version }}" | |
| git checkout -b release-${{ inputs.version }} | |
| git push -u origin release-${{ inputs.version }} | |
| gh pr create --base "${{ github.ref_name }}" --head release-${{ inputs.version }} --title "Release ${{ inputs.version }}" --body-file "release-notes-body" |