Skip to content

Commit

Permalink
FSR-1193 | May TA Update (#699)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
3 people authored May 20, 2024
1 parent 8b128bb commit 6aa2b0e
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 20 deletions.
33 changes: 26 additions & 7 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 "[email protected]"
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)"
Expand All @@ -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"
Expand Down
18 changes: 11 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 }}"
Expand All @@ -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"
Expand All @@ -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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
30 changes: 30 additions & 0 deletions release-docs/CFF-8.3.0.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions release-docs/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions test/scripts.js
Original file line number Diff line number Diff line change
@@ -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')
})
})

0 comments on commit 6aa2b0e

Please sign in to comment.