Skip to content

Create Release Branch and Pull Requests #24

Create Release Branch and Pull Requests

Create Release Branch and Pull Requests #24

Workflow file for this run

name: Create Release Branch and Pull Requests
on:
workflow_dispatch:
inputs:
jira_release_id:
type: string
description: id of release in Jira (from URL)
proposed_release_date:
type: string
description: Proposed release date (dd/mm/yyyy)
db_changes:
type: boolean
description: Release includes DB changes?
increment:
type: choice
description: Release increment
options:
- major
- minor
- patch
env:
TZ: 'Europe/London'
jobs:
create_release_branch_and_draft_pr:
runs-on: ubuntu-latest
steps:
- 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: 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: Install dependencies
run: npm install
- name: Bump version
run: |
npm version --no-git-tag-version ${{ github.event.inputs.increment }}
version=$(jq -r '.version' package.json)
echo VERSION=$version >> "$GITHUB_ENV"
echo RELEASE_BRANCH="release/$version" >> "$GITHUB_ENV"
- name: Check branch doesn't already exist
run: |
if git ls-remote --exit-code origin "refs/heads/${RELEASE_BRANCH}"; then
echo "Error: Branch ${RELEASE_BRANCH} already exists." >&2
exit 1
fi
- name: Create release branch
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git switch -c $RELEASE_BRANCH
git add .
git commit -m "Bump version number (${VERSION})"
env:
FLOOD_APP_BING_KEY: "${{ secrets.FLOOD_APP_BING_KEY }}"
FLOOD_APP_BING_KEY_LOCATION: "${{ secrets.FLOOD_APP_BING_KEY_LOCATION }}"
FLOOD_APP_BING_KEY_MAP: "${{ secrets.FLOOD_APP_BING_KEY_MAP }}"
FLOOD_APP_BING_URL: "${{ secrets.FLOOD_APP_BING_URL }}"
FLOOD_APP_NRW_STATION_URL: "${{ secrets.FLOOD_APP_NRW_STATION_URL }}"
FLOOD_APP_SESSION_PASSWORD: "${{ secrets.FLOOD_APP_SESSION_PASSWORD }}"
- name: Create release notes from template (if it exists)
run: |
template_file="release-docs/template.njk"
if [ -e "$template_file" ]; then
release_notes_file="release-docs/CFF-${VERSION}.md"
temp_file=$(mktemp)
git log --oneline --pretty=%s origin/master...$RELEASE_BRANCH --grep '^FSR-' > $temp_file
npm run create-release-notes -- \
--file $temp_file \
--date "$FORMATTED_DATE" \
--release "$VERSION" \
--output $release_notes_file \
--id "${{ github.event.inputs.jira_release_id }}" \
--template "release-docs/template.njk"
git add $release_notes_file
git commit --no-verify -m "Add release notes (${VERSION})"
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"
gh pr create --base development --title "Release $VERSION" --body "TBC"
env:
# create classic PAT and then run `gh secret set GH_WORKFLOW`
GH_TOKEN: ${{ secrets.GH_WORKFLOW }}
- name: Trigger release creation for flood-service
run: gh workflow run --repo "$GITHUB_REPOSITORY_OWNER/flood-service" release.yml -f increment="${{ github.event.inputs.increment }}" -f proposed_release_date="${{ github.event.inputs.proposed_release_date }}" -f jira_release_id="${{ github.event.inputs.jira_release_id }}"
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