Skip to content

Commit 19f99d5

Browse files
committed
update workflows to allow prereleases
1 parent 67a0163 commit 19f99d5

1 file changed

Lines changed: 87 additions & 41 deletions

File tree

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

Lines changed: 87 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,63 @@ on:
33
push:
44
tags:
55
- 'v*'
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to build (e.g. 4.0.9-rc1)'
10+
required: true
11+
12+
permissions:
13+
contents: write
614

715
jobs:
16+
setup:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
version: ${{ steps.set-vars.outputs.version }}
20+
is_prerelease: ${{ steps.set-vars.outputs.is_prerelease }}
21+
steps:
22+
- id: set-vars
23+
run: |
24+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
25+
VERSION="${{ inputs.version }}"
26+
else
27+
VERSION="${GITHUB_REF#refs/tags/v}"
28+
fi
29+
# Pre-release if version contains -, e.g. 4.0.9-rc1, 4.0.9-dev1
30+
if [[ "$VERSION" == *-* ]]; then
31+
IS_PRERELEASE=true
32+
else
33+
IS_PRERELEASE=false
34+
fi
35+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
36+
echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT
37+
echo "Version: $VERSION, Pre-release: $IS_PRERELEASE"
38+
839
create-release:
40+
needs: setup
941
runs-on: ubuntu-latest
1042
outputs:
1143
upload_url: ${{ steps.create_release.outputs.upload_url }}
1244
steps:
1345
- uses: actions/checkout@v4
1446
with:
1547
fetch-depth: 0
16-
ref: main
17-
- name: git fetch --all
18-
run: |
19-
git fetch --all
2048
- name: Create release
2149
id: create_release
2250
uses: softprops/action-gh-release@v2
2351
with:
24-
tag_name: ${{ github.ref_name }}
25-
name: Release ${{ github.ref_name }}
52+
tag_name: v${{ needs.setup.outputs.version }}
53+
name: Release v${{ needs.setup.outputs.version }}
2654
draft: false
27-
prerelease: false
55+
prerelease: ${{ needs.setup.outputs.is_prerelease }}
56+
generate_release_notes: ${{ needs.setup.outputs.is_prerelease }}
2857
env:
2958
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
3060
update-version-and-changelog:
31-
needs: create-release
61+
needs: [setup, create-release]
62+
if: needs.setup.outputs.is_prerelease == 'false'
3263
runs-on: ubuntu-latest
3364
steps:
3465
- uses: actions/checkout@v4
@@ -53,7 +84,7 @@ jobs:
5384
auto-commit to update version
5485
skip-checks: true
5586
run: |
56-
echo "${{ github.ref }}" | cut -dv -f2 > VERSION.txt
87+
echo "${{ needs.setup.outputs.version }}" > VERSION.txt
5788
git add VERSION.txt
5889
git diff --quiet && git diff --staged --quiet || git commit -m "${COMMIT_MSG}"
5990
git push origin main
@@ -65,10 +96,13 @@ jobs:
6596
auto-commit to update debian changelog
6697
skip-checks: true
6798
run: |
68-
gbp dch --new-version=$(cat VERSION.txt)-1 --release --distribution=stable --spawn-editor=never --commit --commit-msg="${COMMIT_MSG}"
99+
gbp dch --new-version=${{ needs.setup.outputs.version }}-1 --release --distribution=stable --spawn-editor=never --commit --commit-msg="${COMMIT_MSG}"
69100
git push origin main
101+
70102
build-and-upload-deb-assets:
71-
needs: [create-release, update-version-and-changelog]
103+
needs: [setup, create-release, update-version-and-changelog]
104+
# For pre-releases, update-version-and-changelog is skipped, so use always()
105+
if: always() && needs.create-release.result == 'success'
72106
runs-on: ubuntu-latest
73107
container:
74108
image: debian:trixie
@@ -85,41 +119,51 @@ jobs:
85119
- uses: actions/checkout@v4
86120
with:
87121
fetch-depth: 0
88-
ref: main
122+
# For stable releases, use main (has updated changelog); for pre-releases, use the tag
123+
ref: ${{ needs.setup.outputs.is_prerelease == 'false' && 'main' || github.ref }}
89124
- name: git fetch --all
90125
run: |
91126
git config --global --add safe.directory /__w/patchman/patchman
92127
git fetch --all
93-
- name: Get version
128+
- name: Build deb packages (pre-release)
129+
if: needs.setup.outputs.is_prerelease == 'true'
130+
env:
131+
EMAIL: furlongm@gmail.com
132+
VERSION: ${{ needs.setup.outputs.version }}
94133
run: |
95-
export version=$(echo "${{ github.ref }}" | cut -dv -f2)
96-
echo "version=${version}" >> $GITHUB_ENV
97-
- name: Build deb packages
134+
echo "${VERSION}" > VERSION.txt
135+
# Generate changelog for pre-release
136+
cat > debian/changelog << EOF
137+
patchman (${VERSION}-1) unstable; urgency=medium
138+
139+
* Pre-release ${VERSION}
140+
141+
-- Marcus Furlong <furlongm@gmail.com> $(date -R)
142+
EOF
143+
dpkg-buildpackage -us -uc -b
144+
- name: Build deb packages (stable)
145+
if: needs.setup.outputs.is_prerelease == 'false'
98146
env:
99147
EMAIL: furlongm@gmail.com
100-
COMMIT_MSG: |
101-
auto-commit
102-
skip-checks: true
148+
VERSION: ${{ needs.setup.outputs.version }}
103149
run: |
104-
export version=$(echo "${{ github.ref }}" | cut -dv -f2)
105-
echo "${version}" > VERSION.txt
106-
git add VERSION.txt
107-
git diff --quiet && git diff --staged --quiet || git commit -m "${COMMIT_MSG}"
108-
gbp dch --new-version=${version}-1 --release --distribution=stable --spawn-editor=never --commit --commit-msg="${COMMIT_MSG}"
109-
git tag --delete v${version}
110-
git tag v${version}
111-
gbp buildpackage --git-upstream-tree=${{ github.ref }} -uc -us
150+
# Changelog already committed to main by update-version-and-changelog job
151+
echo "${VERSION}" > VERSION.txt
152+
gbp buildpackage --git-upstream-tree=v${VERSION} -uc -us
112153
- name: Upload deb assets
113154
uses: softprops/action-gh-release@v2
114155
with:
115-
tag_name: ${{ github.ref_name }}
156+
tag_name: v${{ needs.setup.outputs.version }}
116157
files: |
117-
../python3-patchman_${{ env.version }}-1_all.deb
118-
../patchman-client_${{ env.version }}-1_all.deb
158+
../python3-patchman_${{ needs.setup.outputs.version }}-1_all.deb
159+
../patchman-client_${{ needs.setup.outputs.version }}-1_all.deb
160+
body: ""
119161
env:
120162
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
163+
121164
build-and-upload-rpm-assets:
122-
needs: [create-release, update-version-and-changelog]
165+
needs: [setup, create-release, update-version-and-changelog]
166+
if: always() && needs.create-release.result == 'success'
123167
runs-on: ubuntu-latest
124168
container:
125169
image: quay.io/centos/centos:stream10
@@ -131,30 +175,32 @@ jobs:
131175
- uses: actions/checkout@v4
132176
with:
133177
fetch-depth: 0
134-
ref: main
178+
ref: ${{ needs.setup.outputs.is_prerelease == 'false' && 'main' || github.ref }}
135179
- name: git fetch --all
136180
run: |
137181
git config --global --add safe.directory /__w/patchman/patchman
138182
git fetch --all
139-
- name: Get version
140-
run: |
141-
export version=$(echo "${{ github.ref }}" | cut -dv -f2)
142-
echo "version=${version}" >> $GITHUB_ENV
143183
- name: Build rpm packages
184+
env:
185+
VERSION: ${{ needs.setup.outputs.version }}
144186
run: |
187+
echo "${VERSION}" > VERSION.txt
145188
python3 setup.py bdist_rpm --python=/usr/bin/python3
146189
rpmbuild -bb patchman-client.spec
147190
- name: Upload rpm assets
148191
uses: softprops/action-gh-release@v2
149192
with:
150-
tag_name: ${{ github.ref_name }}
193+
tag_name: v${{ needs.setup.outputs.version }}
151194
files: |
152-
dist/patchman-${{ env.version }}-1.noarch.rpm
153-
dist/noarch/patchman-client-${{ env.version }}-1.noarch.rpm
195+
dist/patchman-${{ needs.setup.outputs.version }}-1.noarch.rpm
196+
dist/noarch/patchman-client-${{ needs.setup.outputs.version }}-1.noarch.rpm
197+
body: ""
154198
env:
155199
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
200+
156201
upload-package-to-pypi:
157-
needs: update-version-and-changelog
202+
needs: [setup, create-release]
203+
if: needs.setup.outputs.is_prerelease == 'false'
158204
runs-on: ubuntu-latest
159205
steps:
160206
- uses: actions/checkout@v4
@@ -164,7 +210,7 @@ jobs:
164210
python-version: '3.x'
165211
- name: Set version
166212
run: |
167-
echo "${{ github.ref }}" | cut -dv -f2 > VERSION.txt
213+
echo "${{ needs.setup.outputs.version }}" > VERSION.txt
168214
- name: Install dependencies
169215
run: |
170216
python3 -m pip install --upgrade pip

0 commit comments

Comments
 (0)