-
-
Notifications
You must be signed in to change notification settings - Fork 56
121 lines (112 loc) · 3.99 KB
/
Copy pathrelease.yml
File metadata and controls
121 lines (112 loc) · 3.99 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
name: Release
on:
push:
tags:
- "*"
jobs:
release:
name: Create GitHub Release
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
attestations: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Setup node@26
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 26
package-manager-cache: false
- name: Setup pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Build
run: node --run build
- name: Determine release info
id: release
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
if echo "$COMMIT_MSG" | grep -qE '^release: [0-9]+\.[0-9]+\.[0-9]+$'; then
VERSION=$(echo "$COMMIT_MSG" | sed -E 's/^release: //')
echo "is_release=true" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
echo "prerelease=false" >> "$GITHUB_OUTPUT"
elif echo "$COMMIT_MSG" | grep -qE '^release: [0-9]+\.[0-9]+\.[0-9]+-(rc|beta|next)\.[0-9]+$'; then
VERSION=$(echo "$COMMIT_MSG" | sed -E 's/^release: //')
echo "is_release=true" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "is_release=false" >> "$GITHUB_OUTPUT"
fi
- name: Extract release notes from CHANGELOG.md
if: steps.release.outputs.is_release == 'true'
env:
TAG: ${{ steps.release.outputs.tag }}
run: |
{
echo "## What's Changed"
echo ""
awk -v tag="$TAG" '
BEGIN { found=0 }
/^## / {
if (found) { exit }
if ($0 ~ "^## " tag " ") { found=1; next }
}
found { print }
' CHANGELOG.md
} > release_notes.md
- name: Pack packages
if: steps.release.outputs.is_release == 'true'
run: |
for dir in packages/*/ plugins/*/; do
(cd "$dir" && pnpm pack)
done
- name: Attest packages
if: steps.release.outputs.is_release == 'true'
id: attest
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-path: |
packages/*/*.tgz
plugins/*/*.tgz
- name: Create GitHub Release
if: steps.release.outputs.is_release == 'true'
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.release.outputs.tag }}
PRERELEASE: ${{ steps.release.outputs.prerelease }}
VERSION: ${{ steps.release.outputs.version }}
ATTESTATION_ID: ${{ steps.attest.outputs.attestation-id }}
REPO: ${{ github.repository }}
run: |
if gh release view "$TAG" > /dev/null 2>&1; then
echo "Release $TAG already exists, skipping."
exit 0
fi
PRERELEASE_FLAG=""
if [ "$PRERELEASE" = "true" ]; then
PRERELEASE_FLAG="--prerelease"
fi
DATE=$(TZ=Asia/Shanghai date +%Y-%m-%d)
TITLE="v$VERSION ($DATE)"
{
cat release_notes.md
echo ""
echo "## Attestation"
echo ""
echo "https://github.com/$REPO/attestations/$ATTESTATION_ID"
} > final_release_notes.md
gh release create "$TAG" \
--title "$TITLE" \
--notes-file final_release_notes.md \
$PRERELEASE_FLAG \
packages/*/*.tgz plugins/*/*.tgz