Skip to content

Commit bc12ebc

Browse files
felickzCopilot
andauthored
refactor: make release.yml a pure reusable workflow with bump support (#86)
- Remove workflow_dispatch from release.yml (moved to self-release.yml) - Add `bump` input (patch/minor/major) that auto-increments from the latest GitHub release tag - Support both `version` (explicit) and `bump` (auto) with clear priority: version wins if both are set, with a warning - Add resolve-version job that handles the logic before release - Existing callers passing `version` continue to work unchanged self-release.yml changes: - Add workflow_dispatch with patch/minor/major bump choice - Uses patch-release-me to bump .release.yml and open a PR - Push path unchanged: reads .release.yml, passes version to reusable Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a9d17cf commit bc12ebc

2 files changed

Lines changed: 93 additions & 38 deletions

File tree

.github/workflows/release.yml

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,79 @@
22
name: GitHub - Release
33

44
on:
5-
workflow_dispatch:
6-
inputs:
7-
bump:
8-
type: choice
9-
description: "The type of version bump to perform"
10-
options:
11-
- patch
12-
- minor
13-
- major
145
workflow_call:
156
inputs:
167
version:
17-
description: "The version to release"
18-
required: true
8+
description: "Explicit version to release (e.g., 2.3.0). Takes priority over bump."
9+
required: false
10+
type: string
11+
default: ''
12+
bump:
13+
description: "Auto-bump from latest release tag (patch/minor/major). Ignored if version is set."
14+
required: false
1915
type: string
16+
default: ''
2017
prerelease:
2118
description: "Create as a pre-release (skips major/minor tag updates)"
2219
required: false
2320
type: boolean
2421
default: false
2522

2623
jobs:
27-
release-next:
24+
resolve-version:
2825
runs-on: ubuntu-latest
29-
# If the workflow was triggered by workflow_dispatch
30-
if: ${{ github.event_name == 'workflow_dispatch' }}
26+
outputs:
27+
version: ${{ steps.resolve.outputs.version }}
28+
steps:
29+
- name: Resolve version
30+
id: resolve
31+
env:
32+
GH_TOKEN: ${{ github.token }}
33+
INPUT_VERSION: ${{ inputs.version }}
34+
INPUT_BUMP: ${{ inputs.bump }}
35+
run: |
36+
if [ -n "$INPUT_VERSION" ] && [ -n "$INPUT_BUMP" ]; then
37+
echo "::warning::Both 'version' and 'bump' were provided. Using explicit 'version' ($INPUT_VERSION)."
38+
fi
3139
32-
permissions:
33-
contents: write
34-
pull-requests: write
40+
if [ -n "$INPUT_VERSION" ]; then
41+
echo "Using explicit version: $INPUT_VERSION"
42+
echo "version=$INPUT_VERSION" >> "$GITHUB_OUTPUT"
43+
exit 0
44+
fi
3545
36-
steps:
37-
- name: "Checkout"
38-
uses: actions/checkout@v6
46+
if [ -z "$INPUT_BUMP" ]; then
47+
echo "::error::Either 'version' or 'bump' input is required."
48+
exit 1
49+
fi
3950
40-
- name: "Patch Release Me"
41-
uses: 42ByteLabs/patch-release-me@6cd166a460bc205b93c29acb6fef2aa275dc0502 # 0.6.5
42-
with:
43-
mode: ${{ github.event.inputs.bump }}
51+
# Look up latest release tag and increment
52+
LATEST=$(gh api /repos/$GITHUB_REPOSITORY/releases/latest --jq '.tag_name' 2>/dev/null || echo "")
53+
if [ -z "$LATEST" ]; then
54+
echo "::warning::No existing releases found. Defaulting to 0.1.0"
55+
echo "version=0.1.0" >> "$GITHUB_OUTPUT"
56+
exit 0
57+
fi
4458
45-
- name: "Create Release"
46-
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
47-
with:
48-
token: ${{ github.token }}
49-
commit-message: "[chore]: Create release for ${{ github.event.inputs.version }}"
50-
title: "[chore]: Create release for ${{ github.event.inputs.version }}"
51-
branch: chore-release-${{ github.event.inputs.version }}
52-
base: ${{ github.event.before }}
53-
labels: version
54-
body: |
55-
This is an automated PR to create a new release. The release will be created once this PR is merged.
59+
# Strip leading 'v' if present
60+
LATEST="${LATEST#v}"
61+
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST"
62+
63+
case "$INPUT_BUMP" in
64+
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
65+
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
66+
patch) PATCH=$((PATCH + 1)) ;;
67+
*) echo "::error::Invalid bump type '$INPUT_BUMP'. Must be patch, minor, or major."; exit 1 ;;
68+
esac
69+
70+
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
71+
echo "Bumped $LATEST -> $NEW_VERSION ($INPUT_BUMP)"
72+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
5673
5774
release:
75+
needs: resolve-version
5876
runs-on: ubuntu-latest
59-
# If the workflow was triggered by a workflow call and the version is not null
60-
if: ${{ github.event_name == 'workflow_call' && inputs.version != '' }}
77+
if: ${{ needs.resolve-version.outputs.version != '' }}
6178

6279
permissions:
6380
contents: write
@@ -68,7 +85,7 @@ jobs:
6885
id: version
6986
uses: peter-murray/semver-action@5a07021b987a48fb9129231397615329ad74703c # v1.0.1
7087
with:
71-
version: ${{ inputs.version }}
88+
version: ${{ needs.resolve-version.outputs.version }}
7289

7390
# Tags :: ${Full}, v${Major}, v${Major}.${Minor}, v${Major}.${Minor}.${Patch}
7491
- name: "GitHub Release"

.github/workflows/self-release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,51 @@ name: "Self - Release"
33
on:
44
push:
55
branches: ["main"]
6+
workflow_dispatch:
7+
inputs:
8+
bump:
9+
type: choice
10+
description: "The type of version bump to perform"
11+
options:
12+
- patch
13+
- minor
14+
- major
615

716
permissions:
817
contents: write
918
pull-requests: write
1019

1120
jobs:
21+
# Manual version bump: creates a PR with the bumped version in .release.yml
22+
release-next:
23+
if: ${{ github.event_name == 'workflow_dispatch' }}
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: write
27+
pull-requests: write
28+
steps:
29+
- name: "Checkout"
30+
uses: actions/checkout@v6
31+
32+
- name: "Patch Release Me"
33+
uses: 42ByteLabs/patch-release-me@6cd166a460bc205b93c29acb6fef2aa275dc0502 # 0.6.5
34+
with:
35+
mode: ${{ github.event.inputs.bump }}
36+
37+
- name: "Create Release PR"
38+
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
39+
with:
40+
token: ${{ github.token }}
41+
commit-message: "[chore]: Create release for ${{ github.event.inputs.bump }}"
42+
title: "[chore]: Create release (${{ github.event.inputs.bump }} bump)"
43+
branch: chore-release-${{ github.event.inputs.bump }}
44+
labels: version
45+
body: |
46+
This is an automated PR to create a new release. The release will be created once this PR is merged.
47+
48+
# Automatic release: triggered when .release.yml version changes on push to main
1249
fetch-release:
50+
if: ${{ github.event_name == 'push' }}
1351
runs-on: ubuntu-latest
1452
outputs:
1553
release: ${{ steps.version-changes.outputs.release }}

0 commit comments

Comments
 (0)