-
Notifications
You must be signed in to change notification settings - Fork 22
113 lines (104 loc) · 4.54 KB
/
release-drafter.yaml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Release Drafter
on:
push:
branches:
# we only want to draft release notes for the base version,
# e.g. for releases/v0.18, we draft v0.18.0 for all RCs
# this means that we explicitly don't want to draft release notes for releases/v0.18.0 or releases/v0.18.1
- 'releases/v[0-9]+.[0-9]+'
permissions:
contents: read
# The release-drafter action adds PR titles to the release notes once these are merged to main.
# A draft release is kept up-to-date listing the changes for the next minor or patch release version for that branch.
jobs:
release-version:
name: Release Version
uses: ./.github/workflows/release-version.yaml
with:
# the draft release notes do not need to be done by release candidate
# instead we can continously maintain them throughout the candidates
release_candidate: false
permissions:
contents: read
repository-projects: read
update_release_draft:
needs: release-version
permissions:
contents: write
runs-on: ubuntu-latest
env:
RELEASE_VERSION: ${{ needs.release-version.outputs.version }}
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.OCMBOT_APP_ID }}
private_key: ${{ secrets.OCMBOT_PRIV_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Setup Release with gh
env:
COLLAPSE_THRESHOLD: 5
REF: ${{ github.ref }}
REPO: ${{ github.repository }}
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
# generate the release notes based on the last previous tag.
# match only a valid semver tag.
# also do not match for the cutoff tag for the release branch.
# Example: If we are in releases/v0.18, we don't want to match v0.18 as the cutoff tag.
# Instead we want to match the one before that, which would be v0.17.
# That would generate us the notes from
# v0.17 to HEAD, which is what we want.
#
# Implementors Note:
# ##*\/ removes everything before the last / in the ref,
# e.g. refs/heads/releases/v0.18 -> v0.18
previous_tag=$(git describe HEAD --abbrev=0 --tags --match "v*" --exclude "${REF##*\/}")
if [[ -z $previous_tag ]]; then
echo "No previous tag found, cannot generate release notes"
exit 1
fi
echo "Generating release notes for ${{env.RELEASE_VERSION}} starting from ${previous_tag} to HEAD"
notes=$(\
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${REPO}/releases/generate-notes \
-f "tag_name=${{env.RELEASE_VERSION}}" \
-f "target_commitish=${{ github.ref }}" \
-f "previous_tag_name=${previous_tag}" \
-f "configuration_file_path=.github/config/release.yml" \
-q .body \
)
if [[ -z "${notes}" ]]; then
echo "No release notes generated from API, failed"
exit 1
fi
echo "Auto-Collapsing release notes to reduce size"
echo "${notes}" > $RUNNER_TEMP/release_notes.md
bash hack/collapse/auto_collapse.sh $RUNNER_TEMP/release_notes.md $RUNNER_TEMP/release_notes_processed.md ${{ env.COLLAPSE_THRESHOLD }}
notes=$(cat $RUNNER_TEMP/release_notes_processed.md)
echo "Release Notes generated for ${{env.RELEASE_VERSION}}:"
echo "${notes}"
echo "Verifying if release ${{env.RELEASE_VERSION}} already exists"
if [[ -z $(gh release list -R ${REPO} --json name -q '.[] | select(.name == "${{env.RELEASE_VERSION}}")') ]]; then
echo "Release ${{env.RELEASE_VERSION}} does not exist yet, creating from scratch"
gh release create ${{env.RELEASE_VERSION}} \
--title "${{env.RELEASE_VERSION}}" \
--notes "${notes}" \
--draft \
--latest=false \
--target ${{ github.ref }} \
-R ${REPO}
else
echo "Release ${{env.RELEASE_VERSION}} already exists, updating existing..."
gh release edit ${{env.RELEASE_VERSION}} \
--notes "${notes}" \
-R ${REPO}
fi