-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FSR-1170 | Add release workflow (#650)
* FSR-1170 | Add release workflow
- Loading branch information
1 parent
e6c7aa5
commit 88e69f8
Showing
6 changed files
with
421 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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: Install dependencies | ||
run: npm install | ||
|
||
- 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: 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 | ||
- 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 --ff-only $RELEASE_BRANCH | ||
git push | ||
- 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 }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
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 | ||
|
||
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: 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" | ||
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})" | ||
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 }}" | ||
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})" | ||
git push origin $RELEASE_BRANCH | ||
echo RELEASE_NOTES_FILE=$release_notes_file >> "$GITHUB_ENV" | ||
fi | ||
- 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 }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.