Skip to content

Commit 64d0be3

Browse files
authored
ci(release): add patch option to release workflow (#2524)
Follow up on #2523. Add a corresponding input for workflow dispatch. If the release is triggered by pushing a branch, it will diff the new version number against the latest tag on master, determine if this is a patch release, and behave accordingly.
1 parent f513a51 commit 64d0be3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ on:
5151
description: 'Models to include in the release documentation'
5252
required: false
5353
type: string
54+
patch:
55+
description: 'Create a patch release. If true, only bug fixes will be included in generated documentation.'
56+
required: false
57+
type: boolean
58+
default: false
5459
outputs:
5560
version:
5661
description: 'Version number used for release'
@@ -528,6 +533,9 @@ jobs:
528533
if [[ "${{ inputs.developmode }}" == "false" ]]; then
529534
cmd="$cmd --releasemode"
530535
fi
536+
if [[ "${{ inputs.patch }}" == "true" ]]; then
537+
cmd="$cmd --patch"
538+
fi
531539
eval "$cmd"
532540
mv "doc/ReleaseNotes.pdf" "doc/release.pdf"
533541

.github/workflows/release_dispatch.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ on:
5252
description: 'Models to include in the release documentation'
5353
required: false
5454
type: string
55+
patch:
56+
description: 'Create a patch release. If true, only bug fixes will be included in generated documentation.'
57+
required: false
58+
type: boolean
59+
default: false
5560
jobs:
5661
set_options:
5762
name: Set release options
@@ -66,6 +71,7 @@ jobs:
6671
compiler_version: ${{ steps.set_compiler.outputs.compiler_version }}
6772
version: ${{ steps.set_version.outputs.version }}
6873
models: ${{ steps.set_models.outputs.models }}
74+
patch: ${{ steps.set_patch.outputs.patch }}
6975
steps:
7076
- name: Set branch
7177
id: set_branch
@@ -144,6 +150,37 @@ jobs:
144150
exit 1
145151
fi
146152
echo "models=$models" >> $GITHUB_OUTPUT
153+
- name: Set patch
154+
id: set_patch
155+
run: |
156+
# if patch was provided explicitly via workflow_dispatch, use it
157+
if [[ ("${{ github.event_name }}" == "workflow_dispatch") && (-n "${{ inputs.patch }}") ]]; then
158+
patch="${{ inputs.patch }}"
159+
echo "using patch setting $patch from workflow_dispatch"
160+
elif [[ ("${{ github.event_name }}" == "push") && ("${{ github.ref_name }}" != "master") ]]; then
161+
# if release was triggered by pushing a release branch, check the version against the latest
162+
# tag on master to determine if this is a patch release
163+
latest_tag=$(git ls-remote --tags origin "6.*" | awk -F/ '{print $3}' | sort -V | tail -n1)
164+
echo "latest version on master is $latest_tag"
165+
IFS='.' read -r -a latest_parts <<< "$latest_tag"
166+
IFS='.' read -r -a new_parts <<< "${{ steps.set_version.outputs.version }}"
167+
if [[ ${#latest_parts[@]} -ne 3 || ${#new_parts[@]} -ne 3 ]]; then
168+
echo "error: version number is not in major.minor.patch format"
169+
exit 1
170+
fi
171+
if [[ ${latest_parts[0]} -ne ${new_parts[0]} || ${latest_parts[1]} -ne ${new_parts[1]} ]]; then
172+
patch="false"
173+
echo "major or minor version has changed, not a patch release"
174+
elif [[ ${latest_parts[2]} -lt ${new_parts[2]} ]]; then
175+
patch="true"
176+
echo "patch version has changed, this is a patch release"
177+
fi
178+
else
179+
# otherwise exit with an error
180+
echo "error: this workflow should not have triggered for event ${{ github.event_name }} on branch ${{ github.ref_name }}"
181+
exit 1
182+
fi
183+
echo "patch=$patch" >> $GITHUB_OUTPUT
147184
make_dist:
148185
name: Make distribution
149186
uses: MODFLOW-ORG/modflow6/.github/workflows/release.yml@develop
@@ -164,6 +201,7 @@ jobs:
164201
run_tests: ${{ (github.event_name == 'workflow_dispatch' && inputs.run_tests == 'true') || github.event_name != 'workflow_dispatch' }}
165202
version: ${{ needs.set_options.outputs.version }}
166203
models: ${{ needs.set_options.outputs.models }}
204+
patch: ${{ (github.event_name == 'workflow_dispatch' && inputs.patch == 'true') || (github.event_name != 'workflow_dispatch' && needs.set_options.outputs.patch == 'true') }}
167205
pr:
168206
name: Draft release PR
169207
if: ${{ github.ref_name != 'master' && ((github.event_name == 'workflow_dispatch' && inputs.approve == 'true') || (github.event_name != 'workflow_dispatch' && !contains(github.ref_name, 'rc'))) }}

0 commit comments

Comments
 (0)