-
Notifications
You must be signed in to change notification settings - Fork 116
205 lines (168 loc) · 6.24 KB
/
main.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: 自动发布
on:
- push
- workflow_dispatch
jobs:
metadata:
name: 根据metadata,修改package.json
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Python # Set Python version
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: pip install python-dotenv
- name: 修改package.json
run: python ./scripts/version.py
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "根据metadata自动修改package.json的版本"
add: "package.json"
check:
name: 检查是否有新版本
runs-on: ubuntu-latest
needs: [metadata]
# 手动触发时,diff-search会失败
# release对这个是依赖关系,所以不能是job级的If
# if: github.event_name == 'push'
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 50
- name: Check if version has been updated
if: github.event_name == 'push'
id: check
uses: EndBug/version-check@v2
with:
# 这个也需要通过历史commit判断,所以多checkout一些commit
diff-search: true
- name: Log when changed
if: github.event_name == 'push' && steps.check.outputs.changed == 'true'
run: >
echo "Version change found in commit ${{ steps.check.outputs.commit }}!
New version: ${{ steps.check.outputs.version }} (${{ steps.check.outputs.type }})"
- name: get-npm-version
if: github.event_name == 'workflow_dispatch'
id: package-version
uses: martinbeentjes/npm-get-version-action@main
outputs:
hasNewVersion: ${{ steps.check.outputs.changed || false }}
newVersion: ${{ steps.check.outputs.version || steps.package-version.outputs.current-version }}
release:
name: 自动release
runs-on: ubuntu-latest
needs: [check]
# EndBug的check version似乎只能检查最近的一个commit,所以需要允许用workflow_dispatch来主动触发
if: needs.check.outputs.hasNewVersion == 'true' || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 50
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
uses: pnpm/action-setup@v2
with:
# https://github.com/pnpm/action-setup/issues/40
version: 7
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: 打包userscript
run: pnpm run build:js
- name: 发布userscript
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.check.outputs.newVersion }}
files: ./dist/*.js
# 发布extension
- name: build extension
run: pnpm run build:crx
- name: Setup Python # Set Python version
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: pip install python-dotenv
# 生成并移动manifest.json、icon.png
- name: 生成manifest.json
run: |
python ./scripts/manifest.py
mv ./scripts/manifest.json ./dist/manifest.json
- name: zip
run: python ./scripts/zip.py
- name: 发布extension
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.check.outputs.newVersion }}
files: ./dist/*.zip
# 只能获取到version,获取不到具体的内容,
# 因为checkout默认只fetch 最新的commit,而需要从历史commit中提取message
- name: 自动生成release note
run: |
pnpm install -g conventional-changelog-cli
conventional-changelog -p conventionalcommits -o temp.md -r 1
conventional-changelog -p conventionalcommits -i ./docs/CHANGELOG.md -s -r 1 -a
cat temp.md
# - name: Conventional Changelog Action
# id: changelog
# uses: TriPSs/conventional-changelog-action@v3
# with:
# output-file: "false"
# preset: "conventionalcommits"
# # 如果有feat,就会minor,我还是希望手动控制
# skip-commit: "true"
# # Do not update the version file.(package.json)
# skip-version-file: "true"
# # Do not tag the release
# skip-tag: "true"
# - run: |
# echo "changelog: ${{ steps.changelog.outputs.changelog }}"
# echo "clean_changelog: ${{ steps.changelog.outputs.clean_changelog }}"
# echo "version: ${{ steps.changelog.outputs.version }}"
# echo "tag: ${{ steps.changelog.outputs.tag }}"
# echo "skipped: ${{ steps.changelog.outputs.skipped }}"
- name: 发布生成的release note
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.check.outputs.newVersion }}
body_path: temp.md
# body: ${{ steps.changelog.outputs.clean_changelog }}
sync:
name: 同步release到专门的repo中,方便第三方进行webhook
runs-on: ubuntu-latest
needs: [release]
steps:
- name: 同步release到专门的repo中,方便第三方进行webhook
uses: actions/github-script@v6
with:
# 自带的github-token不够权限,需要自己创建一个
github-token: ${{ secrets.TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'SSmJaE',
repo: 'MyUserScripts',
workflow_id: 'main.yml',
ref: 'master'
})