Skip to content

Commit df491f2

Browse files
committed
handle backported stable releases
1 parent 12c55ec commit df491f2

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

.github/workflows/create-release-and-upload-assets.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ jobs:
1919
version: ${{ steps.set-vars.outputs.version }}
2020
rpm_version: ${{ steps.set-vars.outputs.rpm_version }}
2121
is_prerelease: ${{ steps.set-vars.outputs.is_prerelease }}
22+
target_branch: ${{ steps.set-vars.outputs.target_branch }}
2223
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
2327
- id: set-vars
2428
run: |
2529
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
@@ -35,10 +39,20 @@ jobs:
3539
else
3640
IS_PRERELEASE=false
3741
fi
42+
# Detect target branch: if tag version matches VERSION.txt, use main
43+
# otherwise use stable-X.Y branch for backport releases
44+
MAJOR_MINOR=$(echo "$VERSION" | grep -oP '^\d+\.\d+')
45+
CURRENT=$(cat VERSION.txt | grep -oP '^\d+\.\d+')
46+
if [[ "$MAJOR_MINOR" == "$CURRENT" ]]; then
47+
TARGET_BRANCH="main"
48+
else
49+
TARGET_BRANCH="stable-${MAJOR_MINOR}"
50+
fi
3851
echo "version=${VERSION}" >> $GITHUB_OUTPUT
3952
echo "rpm_version=${RPM_VERSION}" >> $GITHUB_OUTPUT
4053
echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT
41-
echo "Version: $VERSION, RPM Version: $RPM_VERSION, Pre-release: $IS_PRERELEASE"
54+
echo "target_branch=${TARGET_BRANCH}" >> $GITHUB_OUTPUT
55+
echo "Version: $VERSION, RPM Version: $RPM_VERSION, Pre-release: $IS_PRERELEASE, Target: $TARGET_BRANCH"
4256
4357
create-release:
4458
needs: setup
@@ -69,7 +83,7 @@ jobs:
6983
- uses: actions/checkout@v4
7084
with:
7185
fetch-depth: 0
72-
ref: main
86+
ref: ${{ needs.setup.outputs.target_branch }}
7387
- name: git fetch --all
7488
run: |
7589
git fetch --all
@@ -91,7 +105,7 @@ jobs:
91105
echo "${{ needs.setup.outputs.version }}" > VERSION.txt
92106
git add VERSION.txt
93107
git diff --quiet && git diff --staged --quiet || git commit -m "${COMMIT_MSG}"
94-
git push origin main
108+
git push origin ${{ needs.setup.outputs.target_branch }}
95109
- name: Update debian changelog
96110
env:
97111
EMAIL: furlongm@gmail.com
@@ -101,7 +115,7 @@ jobs:
101115
skip-checks: true
102116
run: |
103117
gbp dch --new-version=${{ needs.setup.outputs.version }}-1 --release --distribution=stable --spawn-editor=never --commit --commit-msg="${COMMIT_MSG}"
104-
git push origin main
118+
git push origin ${{ needs.setup.outputs.target_branch }}
105119
106120
build-and-upload-deb-assets:
107121
needs: [setup, create-release, update-version-and-changelog]
@@ -123,8 +137,8 @@ jobs:
123137
- uses: actions/checkout@v4
124138
with:
125139
fetch-depth: 0
126-
# For stable releases, use main (has updated changelog); for pre-releases, use the tag
127-
ref: ${{ needs.setup.outputs.is_prerelease == 'false' && 'main' || github.ref }}
140+
# For stable releases, use target branch (has updated changelog); for pre-releases, use the tag
141+
ref: ${{ needs.setup.outputs.is_prerelease == 'false' && needs.setup.outputs.target_branch || github.ref }}
128142
- name: git fetch --all
129143
run: |
130144
git config --global --add safe.directory /__w/patchman/patchman
@@ -151,7 +165,7 @@ jobs:
151165
EMAIL: furlongm@gmail.com
152166
VERSION: ${{ needs.setup.outputs.version }}
153167
run: |
154-
# VERSION.txt and changelog already updated on main by update-version-and-changelog job
168+
# VERSION.txt and changelog already updated on target branch by update-version-and-changelog job
155169
# Recreate tag to include those commits
156170
git tag --delete v${VERSION}
157171
git tag v${VERSION}
@@ -181,7 +195,7 @@ jobs:
181195
- uses: actions/checkout@v4
182196
with:
183197
fetch-depth: 0
184-
ref: ${{ needs.setup.outputs.is_prerelease == 'false' && 'main' || github.ref }}
198+
ref: ${{ needs.setup.outputs.is_prerelease == 'false' && needs.setup.outputs.target_branch || github.ref }}
185199
- name: git fetch --all
186200
run: |
187201
git config --global --add safe.directory /__w/patchman/patchman

0 commit comments

Comments
 (0)