Skip to content

Commit e2589f3

Browse files
committed
CI: Add release workflow
This github actions workflow will create a draft release for PRs that updates the version file. The commit message subject line must be Release microcom <version> The commit message body will be used as release description. The release is converted from draft to an actual release, and the commit thereby tagged once the PR is merged. Signed-off-by: Jonas Rebmann <[email protected]>
1 parent 84d6c97 commit e2589f3

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
name: Build test
32
on:
43
push:

.github/workflows/release-pr.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Draft Release
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, closed]
6+
paths:
7+
- VERSION
8+
branches: [main]
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
validate-release-commit:
16+
if: >
17+
!(github.event.pull_request.merged == true &&
18+
!contains(join(github.event.pull_request.labels.*.name), 'release'))
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout merge
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Get release commit info
29+
id: version
30+
run: |
31+
ver=$(cat VERSION)
32+
if ! echo "$ver" | grep -Eq '^[0-9]{4}\.[0-9]{2}\.[0-9]+$'; then
33+
echo "Invalid version format: $ver"
34+
exit 1
35+
fi
36+
37+
echo "version=$ver" >> $GITHUB_OUTPUT
38+
39+
headline="$(git show --format=%s ${{github.event.pull_request.head.sha}})"
40+
if ! echo "$headline" | grep -Eq "^[Rr]elease microcom $ver$"; then
41+
echo "Invalid commit headline: $headline"
42+
exit 1
43+
fi
44+
45+
body="$(
46+
git show -s --format=%b ${{github.event.pull_request.head.sha}} \
47+
| sed -E '/^Signed-off-by: /d'
48+
)"
49+
50+
echo 'body<<EOF' >> $GITHUB_OUTPUT
51+
echo "$body" >> $GITHUB_OUTPUT
52+
echo 'EOF' >> $GITHUB_OUTPUT
53+
54+
- name: Install Dependencies
55+
run: sudo apt install -y libreadline6-dev autoconf automake
56+
57+
- name: Build release packages
58+
run: |
59+
autoreconf -i
60+
./configure
61+
make dist
62+
63+
# DRAFT release on pr creation and update
64+
- name: Create or update release draft
65+
if: github.event.pull_request.merged == false
66+
uses: softprops/action-gh-release@v2
67+
with:
68+
draft: true
69+
tag_name: v${{steps.version.outputs.version}}
70+
name: microcom ${{steps.version.outputs.version}}
71+
body: ${{steps.version.outputs.body}}
72+
files: |
73+
microcom-*.tar.gz
74+
microcom-*.tar.xz
75+
76+
# PUBLISH release on merge
77+
- name: Publish release on merge
78+
if: github.event.pull_request.merged == true
79+
uses: softprops/action-gh-release@v2
80+
with:
81+
draft: false
82+
tag_name: v${{steps.version.outputs.version}}
83+
files: |
84+
microcom-*.tar.gz
85+
microcom-*.tar.xz
86+
87+
- run: gh pr edit "$NUMBER" --add-label "$LABELS"
88+
if: github.event.pull_request.merged == false
89+
env:
90+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
91+
GH_REPO: ${{github.repository}}
92+
NUMBER: ${{github.event.pull_request.number}}
93+
LABELS: release
94+
95+
- run: gh pr comment "$NUMBER" --body "Release published!"
96+
if: github.event.pull_request.merged == true
97+
env:
98+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
99+
GH_REPO: ${{github.repository}}
100+
NUMBER: ${{github.event.pull_request.number}}
101+
LABELS: release

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2023.09.0

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([microcom], [2023.09.0], [[email protected]])
1+
AC_INIT([microcom], [m4_esyscmd_s(cat VERSION)], [[email protected]])
22
AC_CONFIG_AUX_DIR([build-aux])
33
AC_CONFIG_MACRO_DIR([m4])
44
AM_INIT_AUTOMAKE([dist-xz])

0 commit comments

Comments
 (0)