Skip to content

Merge Release Branch and Create Release #18

Merge Release Branch and Create Release

Merge Release Branch and Create Release #18

Workflow file for this run

name: Merge Release Branch and Create Release
on:
workflow_dispatch:
inputs:
version:
type: string
description: version for release
jobs:
merge_release_branch_and_create_release:
runs-on: ubuntu-latest
steps:
- name: Display inputs
run: echo "${{ github.event.inputs.version }}"
- name: Check PAT token is still valid
run: |
gh workflow list --repo "$GITHUB_REPOSITORY_OWNER/flood-service"
env:
# if this fails the create/regenerate classic PAT and then populate it using `gh secret set GH_WORKFLOW`
GH_TOKEN: ${{ secrets.GH_WORKFLOW }}
- name: Checkout code
uses: actions/checkout@v4
with:
ref: development
fetch-depth: 0
- name: Set up Node.js environment
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Setup version env vars
run: |
version=${{ github.event.inputs.version }}
echo VERSION=$version >> "$GITHUB_ENV"
echo RELEASE_BRANCH="release/$version" >> "$GITHUB_ENV"
echo TAG_VERSION="v$version" >> "$GITHUB_ENV"
echo RELEASE_NOTES_FILE="./release-docs/CFF-${version}.md" >> "$GITHUB_ENV"
- name: Check branch exists
run: |
if ! git ls-remote --exit-code origin "refs/heads/${RELEASE_BRANCH}"; then
echo "Error: Branch ${RELEASE_BRANCH} does not exist." >&2
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[-1].state == "APPROVED") | .reviews[-1].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 --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)"
env:
# create classic PAT and then run `gh secret set GH_WORKFLOW`
GH_TOKEN: ${{ secrets.GH_WORKFLOW }}
- name: Merge release branch into development
run: |
git switch development
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"
env:
# use PAT token with repo scope (github.token didn't work)
GH_TOKEN: ${{ secrets.GH_WORKFLOW }}