From 6aa2b0e24201ec718c5fc6942ff600c121cc7564 Mon Sep 17 00:00:00 2001 From: Lee Gordon <40238160+LeeGordon83@users.noreply.github.com> Date: Mon, 20 May 2024 13:55:11 +0100 Subject: [PATCH] FSR-1193 | May TA Update (#699) * FSR-1192 | Add defensive and cleanup measures to release creation GitHub action (#683) * Add defensive measures * don't push changes until after version bump and release note creation * delete release branch if it exists and any step fails * Refine the release notes to reflect findings from recent release creation * Rename script for clarity * FSR-0000 | allow git to decide merge strategy (#685) * fix for release date validation for release git hub action (#696) * release date validation temporary removal * Bump version number (8.3.0) * Add release notes (8.3.0) * Update CFF-8.3.0.md updated notes to include TA update ticket --------- Co-authored-by: Neil McLaughlin Co-authored-by: GitHub Actions --- .github/workflows/merge.yml | 33 ++++++++++++++++++++++++++------- .github/workflows/release.yml | 18 +++++++++++------- package-lock.json | 4 ++-- package.json | 2 +- release-docs/CFF-8.3.0.md | 30 ++++++++++++++++++++++++++++++ release-docs/template.njk | 7 ++++--- test/scripts.js | 27 +++++++++++++++++++++++++++ 7 files changed, 101 insertions(+), 20 deletions(-) create mode 100644 release-docs/CFF-8.3.0.md create mode 100644 test/scripts.js diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index af2bf9e1f..73fbfc822 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -34,9 +34,6 @@ jobs: with: node-version: '18' - - name: Install dependencies - run: npm install - - name: Setup version env vars run: | version=${{ github.event.inputs.version }} @@ -52,14 +49,36 @@ jobs: exit 1 fi + - name: Check PR's approved + run: | + function prCheck () { + REPO=$1 + BASE=$2 + STATE=$(gh pr list --repo $GITHUB_REPOSITORY_OWNER/$REPO --json title,mergeStateStatus,state,reviews --state OPEN --base $BASE --head $RELEASE_BRANCH --jq '.[] | select(.mergeStateStatus == "CLEAN" and .reviews[].state == "APPROVED") | .reviews[].state ') + if [ "$STATE" != "APPROVED" ]; then + echo "Error: PR for merging $GITHUB_REPOSITORY_OWNER/$REPO $RELEASE_BRANCH into $BASE needs to be ready to merge and approved. (STATE=$STATE)" >&2 + exit 1 + fi + } + prCheck flood-app master + prCheck flood-app development + prCheck flood-service master + prCheck flood-service development + env: + # create classic PAT and then run `gh secret set GH_WORKFLOW` + GH_TOKEN: ${{ secrets.GH_WORKFLOW }} + + - name: Install dependencies + run: npm install + - name: Merge release branch into master run: | git config --global user.email "actions@github.com" git config --global user.name "GitHub Actions" git switch $RELEASE_BRANCH git switch master - git merge --ff-only $RELEASE_BRANCH - git push + git merge --no-edit $RELEASE_BRANCH + git push origin master - name: Create GitHub Release run: gh release create $TAG_VERSION --title "Release $VERSION" --notes "[release notes](/$RELEASE_NOTES_FILE)" @@ -70,8 +89,8 @@ jobs: - name: Merge release branch into development run: | git switch development - git merge --ff-only $RELEASE_BRANCH - git push + git merge --no-edit $RELEASE_BRANCH + git push origin development - name: Trigger Merge Release Branch for flood-service run: gh workflow run --repo "$GITHUB_REPOSITORY_OWNER/flood-service" merge.yml -f version="$VERSION" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e7d3b0402..0d6cddb59 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,11 +32,6 @@ jobs: - name: Display inputs run: echo "${{ github.event.inputs.jira_release_id }} ${{ github.event.inputs.increment }} ${{ github.event.inputs.db_changes }} ${{ github.event.inputs.proposed_release_date }}" - - name: Validate date - run: | - date=$(date --date "${{ github.event.inputs.proposed_release_date }}" "+%d/%m/%Y") - echo FORMATTED_DATE=$(date --date $date "+%A %d %B %Y") >> "$GITHUB_ENV" - - name: Check PAT token is still valid run: | gh workflow list --repo "$GITHUB_REPOSITORY_OWNER/flood-service" @@ -79,7 +74,6 @@ jobs: git switch -c $RELEASE_BRANCH git add . git commit -m "Bump version number (${VERSION})" - git push origin $RELEASE_BRANCH env: FLOOD_APP_BING_KEY: "${{ secrets.FLOOD_APP_BING_KEY }}" FLOOD_APP_BING_KEY_LOCATION: "${{ secrets.FLOOD_APP_BING_KEY_LOCATION }}" @@ -104,10 +98,12 @@ jobs: --template "release-docs/template.njk" git add $release_notes_file git commit --no-verify -m "Add release notes (${VERSION})" - git push origin $RELEASE_BRANCH echo RELEASE_NOTES_FILE=$release_notes_file >> "$GITHUB_ENV" fi + - name: Push changes + run: git push origin $RELEASE_BRANCH + - name: Create Draft PRs run: | gh pr create --base master --title "Release $VERSION" --body "TBC" @@ -121,3 +117,11 @@ jobs: env: # use PAT token with repo scope (github.token didn't work) GH_TOKEN: ${{ secrets.GH_WORKFLOW }} + + - name: Clean up + if: ${{ failure() }} + run: | + if git ls-remote --exit-code origin "refs/heads/${RELEASE_BRANCH}"; then + echo "Action failed, removing created release branch" + git push --delete origin $RELEASE_BRANCH + fi diff --git a/package-lock.json b/package-lock.json index a9adfbfa6..51cb2a27c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flood-app", - "version": "8.2.0", + "version": "8.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "flood-app", - "version": "8.2.0", + "version": "8.3.0", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 11d8772fc..1baa06438 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flood-app", - "version": "8.2.0", + "version": "8.3.0", "description": "Flood risk app", "main": "index.js", "repository": "github:defra/flood-app", diff --git a/release-docs/CFF-8.3.0.md b/release-docs/CFF-8.3.0.md new file mode 100644 index 000000000..90d05a2f5 --- /dev/null +++ b/release-docs/CFF-8.3.0.md @@ -0,0 +1,30 @@ +# Check For Flooding Release + +* Version: 8.3.0 +* Proposed Release Date: 22/05/2024 +* Jira Release Overview: https://eaflood.atlassian.net/projects/FSR/versions/16850/tab/release-report-all-issues + +## Tickets + + * FSR-1193 | TA Update - 22 May 2024 + +## Instructions + +This release is for target area updates + + 1 - Update LFW_{STAGE}_99_LOAD_FLOOD_ALERT_AREAS jenkins job with the following properties update for the updated database name for production: + + DB_NAME=floodprdg + ###### OR ######## + DB_NAME=floodprdb + + 2 - Execute LFW_{STAGE}_99_LOAD_FLOOD_ALERT_AREAS + + 3 - Execute LFW_{STAGE}_04_UPDATE_FLOOD_APP_AND_SERVICE_PIPELINE + + +Execute smoke tests and forward results + +## Related Infrastructure Changes Required + +* None diff --git a/release-docs/template.njk b/release-docs/template.njk index af5bf1ac4..0293bc2a8 100644 --- a/release-docs/template.njk +++ b/release-docs/template.njk @@ -6,11 +6,12 @@ ## Sense Check +* Note that this is the definitive release notes for WebOps. The release notes in flood-service and flood-db are for CFF dev team use only. * Cross check the list of Jira tickets below with those in the Jira release linked to above and update where needed -* Add additional Jira tickets from the related release notes: - * [flood-service](https://github.com/DEFRA/flood-service/blob/release/{{ version }}/release-docs/CFF-{{ version }}.md) +* Add additional Jira tickets from the related release notes in the 'Release {{ version }}' PR's created in: + * [flood-service](https://github.com/DEFRA/flood-service) {% if dbChanges %} - * [flood-db](https://github.com/DEFRA/flood-db/blob/release{{ version }}/release-docs/CFF-{{ version }}.md) + * [flood-db](https://github.com/DEFRA/flood-db) {% endif %} * Add any required infrastructure changes such as redirects to the infrastructure changes section below * Once this sense check is done, delete this section diff --git a/test/scripts.js b/test/scripts.js new file mode 100644 index 000000000..2d2768c32 --- /dev/null +++ b/test/scripts.js @@ -0,0 +1,27 @@ +'use strict' + +const Lab = require('@hapi/lab') +const { expect } = require('@hapi/code') +const { describe, it } = exports.lab = Lab.script() + +async function executeNpmScript (scriptName) { + const util = require('util') + const exec = util.promisify(require('child_process').exec) + try { + const { stdout, stderr } = await exec(`npm run ${scriptName}`) + return { stdout, stderr } + } catch (error) { + return { stdout: '', stderr: error.stderr } + } +} +describe('scripts', () => { + it('should run help for create-release-notes successfully', async () => { + // this test is to check that all the necessary modules are installed following the accidental + // removal of nunjucks and yargs which wasn't picked up until the create release github action + // was run + const { stdout, stderr } = await executeNpmScript('create-release-notes -- --help') + + expect(stderr).to.be.empty() + expect(stdout).to.contain('node release-docs/lib/create-release-notes.js --help') + }) +})