generated from openziti/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 2
85 lines (77 loc) · 3.09 KB
/
release-drafter.yml
File metadata and controls
85 lines (77 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Release Drafter
on:
push:
branches:
- main
- 'v*'
permissions:
contents: read
jobs:
update_release_draft:
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "main" or "v*" branches
- name: Compute next patch version for major branch
id: next_version
if: ${{ startsWith(github.ref, 'refs/heads/v') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
major="${GITHUB_REF_NAME#v}"
last="$(gh release list --repo "${GITHUB_REPOSITORY}" --exclude-drafts --json tagName --jq '.[].tagName' \
| grep -E "^v${major}\\.[0-9]+\\.[0-9]+$" \
| sort -V \
| tail -n 1 || true)"
if [ -z "${last}" ]; then
echo "No previous v${major}.*.* releases found; cannot compute next patch version." >&2
exit 1
fi
ver="${last#v}"
IFS='.' read -r maj min patch <<< "${ver}"
next_patch=$((patch + 1))
echo "version=${maj}.${min}.${next_patch}" >> "$GITHUB_OUTPUT"
- uses: release-drafter/release-drafter@v6
id: release_drafter
if: ${{ startsWith(github.ref, 'refs/heads/v') }}
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
with:
config-name: release-drafter-template.yml
commitish: refs/heads/${{ github.ref_name }}
version: ${{ steps.next_version.outputs.version }}
# disable-autolabeler: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: release-drafter/release-drafter@v6
id: release_drafter_main
if: ${{ github.ref == 'refs/heads/main' }}
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
with:
config-name: release-drafter-template.yml
commitish: refs/heads/${{ github.ref_name }}
# disable-autolabeler: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Validate drafted version matches major branch
if: ${{ startsWith(github.ref, 'refs/heads/v') }}
shell: bash
run: |
set -euo pipefail
branch_major="${GITHUB_REF_NAME#v}"
drafted_major='${{ steps.release_drafter.outputs.major_version }}'
if [ -z "${drafted_major}" ]; then
echo "release-drafter did not output major_version" >&2
exit 1
fi
if [ "${drafted_major}" != "${branch_major}" ]; then
echo "Drafted release major v${drafted_major} does not match branch ${GITHUB_REF_NAME}." >&2
echo "Ensure the branch has an initial v${branch_major}.x.y release and that PR labels don't request a major bump." >&2
exit 1
fi