-
Notifications
You must be signed in to change notification settings - Fork 13
141 lines (114 loc) · 3.91 KB
/
release.yml
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
# https://github.com/sveltejs/kit/blob/32afba695088b946aefe96da75b36de9b0667fbe/.github/workflows/release.yml
name: 'Release'
on:
push:
branches: ['main']
jobs:
changesets:
# prevents this action from running on forks
if: github.repository == 'difizen/libro'
name: Changesets
uses: difizen/actions/.github/workflows/release-changesets.yml@main
secrets:
BOT_APP_ID: ${{ secrets.BOT_APP_ID }}
BOT_PRIVATE_KEY: ${{ secrets.BOT_PRIVATE_KEY }}
permissions:
pull-requests: write
contents: write
ci:
needs: [changesets]
if: |
needs.changesets.outputs.should-release == 'true'
name: Prerelease CI
uses: ./.github/workflows/ci.yml
permissions:
contents: read
actions: read
publish:
needs: [ci]
if: |
needs.ci.result == 'success'
name: Publish
uses: difizen/actions/.github/workflows/release-publish.yml@main
with:
node-version: '20'
python-version: '3.8'
permissions:
contents: write
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# 新增的 release-notes Job
release-notes:
needs: [publish]
if: |
needs.publish.result == 'success'
name: Generate Release Notes
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up git
run: |
git fetch --prune --unshallow
git fetch --tags
- name: Get latest tag
id: get_tag
run: |
# 获取最新的符合 @difizen/libro-xxx@ 格式的 tag
LATEST_TAG=$(git describe --tags --abbrev=0)
# 输出最新的 tag
echo "Latest tag: $LATEST_TAG"
# 提取版本号(移除最后一个 '@' 之前的部分)
VERSION=${LATEST_TAG##*@}
# 输出提取的版本号
echo "Extracted version: $VERSION"
# 将版本号设置为输出变量供后续步骤使用
echo "::set-output name=latest_version::$VERSION"
- name: Check if tag exists
id: check_tag
run: |
TAG_EXISTS=$(git tag -l "${{ steps.get_tag.outputs.latest_version }}")
if [ -z "$TAG_EXISTS" ]; then
echo "Tag does not exist"
echo "::set-output name=tag_exists::false"
else
echo "Tag already exists"
echo "::set-output name=tag_exists::true"
fi
- name: Install dependencies
if: steps.check_tag.outputs.tag_exists == 'false'
run: npm install
- name: Extract Changeset Content
if: steps.check_tag.outputs.tag_exists == 'false'
id: extract_changesets
run: |
COMMIT_CONTENT=""
for file in .changeset/*.md; do
echo "Processing $file"
CONTENT=$(awk '/^---$/{p++} p==2' "$file")
COMMIT_CONTENT+="$CONTENT"$'\n'
done
echo "::set-output name=release_notes::$COMMIT_CONTENT"
- name: Generate Snapshot
if: steps.check_tag.outputs.tag_exists == 'false'
id: generate_snapshot
run: |
# 获取 changeset 的快照
SNAPSHOT=$(npx changeset status --snapshot)
echo "::set-output name=snapshot::$SNAPSHOT"
- name: Generate GitHub Release
if: steps.check_tag.outputs.tag_exists == 'false'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag.outputs.latest_version }} # 使用最近的 tag 作为 tag 名
release_name: Release ${{ steps.get_tag.outputs.latest_version }} # 使用最近的 tag 作为 release 名
body: |
## Changes:
${{ steps.extract_changesets.outputs.release_notes }}
## Packages affected:
${{ steps.generate_snapshot.outputs.snapshot }}
draft: false # 直接发布而非草稿