-
Notifications
You must be signed in to change notification settings - Fork 26
162 lines (145 loc) · 5.72 KB
/
Copy pathdraft-release.yml
File metadata and controls
162 lines (145 loc) · 5.72 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Draft-release
on:
push:
branches:
- master
permissions:
contents: write
jobs:
check-tag:
name: Check commit, tag and readme
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.readme.outputs.tag_name }}
changelog: ${{ steps.readme.outputs.changelog }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: master
- name: Get stable tag and changelog from readme.txt
id: readme
run: |
STABLE_TAG=$(grep -E '^Stable tag:' readme.txt | sed -E 's/^Stable tag:[[:space:]]*//' | tr -d '\r')
echo "stable_tag=$STABLE_TAG" >> $GITHUB_OUTPUT
echo "tag_name=${STABLE_TAG}" >> $GITHUB_OUTPUT
# Extract latest changelog block (first version block under == Changelog ==)
CHANGELOG_BLOCK=$(awk '
/== Changelog ==/ { in_changelog=1; next }
in_changelog && /^= [0-9]+\.[0-9]+\.[0-9]+/ {
if (count++) exit
print
next
}
in_changelog && count>0 { print }
' readme.txt)
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG_BLOCK" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "Stable tag: $STABLE_TAG"
echo "Tag name: $STABLE_TAG"
echo "Latest changelog:"
echo "$CHANGELOG_BLOCK"
- name: Verify commit message matches readme stable tag
run: |
COMMIT_MSG=$(echo "${{ github.event.head_commit.message }}" | head -1)
STABLE_TAG="${{ steps.readme.outputs.stable_tag }}"
EXPECTED_MSG="Final version bump to v${STABLE_TAG} for public release."
echo "Commit message: $COMMIT_MSG"
echo "Expected (case-insensitive): $EXPECTED_MSG"
# Case-insensitive comparison: commit message must match "Final version bump to v{stable_tag} for public release."
COMMIT_LOWER=$(echo "$COMMIT_MSG" | tr '[:upper:]' '[:lower:]')
EXPECTED_LOWER=$(echo "$EXPECTED_MSG" | tr '[:upper:]' '[:lower:]')
if [ "$COMMIT_LOWER" != "$EXPECTED_LOWER" ]; then
echo "::error::Commit message does not match. Expected: '$EXPECTED_MSG' (case-insensitive), got: '$COMMIT_MSG'"
exit 1
fi
echo "Commit message matches. Proceeding with pre-release."
- name: Check if tag already exists
run: |
set -e
TAG_NAME="${{ steps.readme.outputs.tag_name }}"
if git ls-remote --exit-code origin "refs/tags/$TAG_NAME" >/dev/null 2>&1; then
echo "::error::Tag $TAG_NAME already exists on remote. Update the Stable tag in readme.txt and try again."
exit 1
fi
echo "Tag $TAG_NAME does not exist; continuing."
create-draft-release:
name: Create tag and draft release
runs-on: ubuntu-latest
needs: check-tag
if: success()
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: master
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
TAG_NAME="${{ needs.check-tag.outputs.tag_name }}"
git tag -a "$TAG_NAME" -m "Pre-release $TAG_NAME"
git push origin "$TAG_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create draft release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-tag.outputs.tag_name }}
name: v${{ needs.check-tag.outputs.tag_name }}
body: |
Changelogs for the release of v${{ needs.check-tag.outputs.tag_name }}
```
${{ needs.check-tag.outputs.changelog }}
```
draft: true
latest: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Build
id: build
uses: wpeverest/action-build@4.0.2
with:
generate-zip: true
- name: Upload release asset to draft
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-tag.outputs.tag_name }}
files: ${{ steps.build.outputs.zip_path }}
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cleanup release and tag on failure
if: failure()
run: |
TAG_NAME="${{ needs.check-tag.outputs.tag_name }}"
REPO="${{ github.repository }}"
echo "Job failed; deleting release and tag $TAG_NAME..."
# Delete the release (by tag) - ignore 404 if release was not created yet
RELEASE_ID=$(curl -sS -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${REPO}/releases/tags/${TAG_NAME}" | jq -r '.id // empty')
if [ -n "$RELEASE_ID" ]; then
curl -sS -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${REPO}/releases/${RELEASE_ID}" || true
echo "Deleted release $RELEASE_ID"
fi
# Delete the tag (ignore 404 if tag was not pushed)
curl -sS -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${REPO}/git/refs/tags/${TAG_NAME}" || true
echo "Cleanup finished for tag $TAG_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}