blob: 7b68c18f3d3118b68a7b6c6a289bdc773a3dc902 [file] [log] [blame]
Marc Kupietzae4079a2026-09-01 06:57:17 +02001# Creates a GitHub release whenever a version tag is pushed, using the
2# corresponding section of NEWS.md as release notes.
3on:
4 push:
5 tags:
6 - 'v*'
7 workflow_dispatch:
8 inputs:
9 tag:
10 description: 'Existing version tag to (re-)generate the release for, e.g. v1.3.0'
11 required: true
12
13name: release
14
15jobs:
16 release:
17 runs-on: ubuntu-latest
18
19 permissions:
20 contents: write
21
22 steps:
23 - name: Determine tag
24 id: tag
25 shell: bash
26 run: |
27 set -euo pipefail
28 TAG="${{ github.event.inputs.tag || github.ref_name }}"
29 echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
30 echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
31
32 - uses: actions/checkout@v4
33 with:
34 ref: ${{ steps.tag.outputs.tag }}
35
36 - name: Extract release notes from NEWS.md
37 id: notes
38 shell: bash
39 run: |
40 set -euo pipefail
41 VERSION="${{ steps.tag.outputs.version }}"
42
43 # Print everything between the level 1 NEWS.md heading that mentions
44 # this version and the next level 1 heading, then strip the blank
45 # lines at both ends.
46 awk -v ver="$VERSION" '
47 /^# / {
48 if (found) exit
49 line = $0
50 gsub(/[^0-9A-Za-z.]+/, " ", line)
51 split(line, tok, " ")
52 for (i in tok) if (tok[i] == ver) found = 1
53 next
54 }
55 found { print }
56 ' NEWS.md | sed -e '/./,$!d' | tac | sed -e '/./,$!d' | tac > release-notes.md
57
58 if [ ! -s release-notes.md ]; then
59 echo "::error::No NEWS.md section found for version ${VERSION}."
60 exit 1
61 fi
62
63 echo "Release notes for ${VERSION}:"
64 cat release-notes.md
65
66 DESCRIPTION_VERSION="$(grep '^Version:' DESCRIPTION | sed -e 's/^Version:[[:space:]]*//')"
67 if [ "$DESCRIPTION_VERSION" != "$VERSION" ]; then
68 echo "::warning::Tag version ${VERSION} does not match DESCRIPTION version ${DESCRIPTION_VERSION}."
69 fi
70
71 # x.y.z is a regular (CRAN) release, everything else a pre-release
72 if echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
73 echo "title=RKorAPClient v${VERSION} (CRAN-Release)" >> "$GITHUB_OUTPUT"
74 echo "prerelease=" >> "$GITHUB_OUTPUT"
75 else
76 echo "title=RKorAPClient v${VERSION}" >> "$GITHUB_OUTPUT"
77 echo "prerelease=--prerelease" >> "$GITHUB_OUTPUT"
78 fi
79
80 - name: Create or update the release
81 shell: bash
82 env:
83 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84 run: |
85 set -euo pipefail
86 TAG="${{ steps.tag.outputs.tag }}"
87
88 if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
89 echo "Release ${TAG} already exists, updating it."
90 gh release edit "$TAG" \
91 --repo "$GITHUB_REPOSITORY" \
92 --title "${{ steps.notes.outputs.title }}" \
93 --notes-file release-notes.md
94 else
95 gh release create "$TAG" \
96 --repo "$GITHUB_REPOSITORY" \
97 --title "${{ steps.notes.outputs.title }}" \
98 --notes-file release-notes.md \
99 ${{ steps.notes.outputs.prerelease }}
100 fi