-
Notifications
You must be signed in to change notification settings - Fork 290
68 lines (55 loc) · 2.21 KB
/
create_release_draft.yml
File metadata and controls
68 lines (55 loc) · 2.21 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
name: Form a Draft Release on Staging Merge
permissions:
contents: write
on:
push:
branches:
- master
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract changelog content
id: changelog
run: |
# Extract the top version heading
version=$(grep -m1 '^## ' CHANGELOG.md | sed 's/^## //')
echo "Version found: $version"
echo "version=$version" >> $GITHUB_OUTPUT
# Extract lines under the top version block
awk '
/^## / {
if (seen++) exit;
next;
}
seen == 1 { print }
' CHANGELOG.md > body.txt
# Remove trailing empty lines from the end of the file
perl -0777 -pe 's/\n+\z//' body.txt > trimmed.txt && mv trimmed.txt body.txt
echo "Extracted changelog body:"
cat body.txt
- name: Create draft release
id: draft_release
run: |
version=${{ steps.changelog.outputs.version }}
# Find all draft releases except the current version's draft
old_drafts=$(gh release list --limit 100 --json tagName,isDraft | \
jq -r --arg version "$version" '.[] | select(.isDraft and (.tagName != $version)) | .tagName')
# Delete old draft releases (ignore errors if none)
for tag in $old_drafts; do
echo "Deleting old draft release with tag: $tag"
gh release delete "$tag" --yes || true
done
release_tag=$(gh release list --limit 100 --json isDraft,tagName | \
jq -r --arg version "$version" '.[] | select(.isDraft and (.tagName == $version)) | .tagName' | head -n1)
if [ -z "$release_tag" ]; then
echo "No draft release found, creating new one..."
gh release create "${version}" --target staging --draft --title "$version" --notes-file body.txt
else
echo "Updating existing draft release $release_tag..."
gh release edit "${version}" --target staging --title "$version" --notes-file body.txt
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}