-
Notifications
You must be signed in to change notification settings - Fork 1
152 lines (140 loc) · 4.77 KB
/
release_pypi.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
# 推送到pypi
name: release_to pypi
# 只在setup.py更新时触发
on:
push:
# 排除v开头的分支
branches-ignore:
- 'v*'
jobs:
release_to:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11.0
cache: pip
# 读取setup.py setup方法的版本号
- name: Get version
id: get_version
run: |
echo "version=$(python setup.py --version)" >> "$GITHUB_OUTPUT"
# 获取pypi的该项目的版本号
- name: Get pypi version
id: get_pypi_version
run: |
echo "version=$(curl -s https://pypi.org/pypi/music-tool-kit/json | python -c "import sys, json; print(json.load(sys.stdin)['info']['version'])")" >> "$GITHUB_OUTPUT"
# 如果version和curr_version相同退出工作流
- name: Check version
env:
version: ${{ steps.get_version.outputs.version }}
curr_version: ${{ steps.get_pypi_version.outputs.version }}
run: |
if [ $version == $curr_version ]; then
echo "version is same, exit"
exit 1
fi
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
continue-on-error: true
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
# 生成发行说明
# - name: Generate Release Notes
# id: gen_release_notes
# uses: actions/github-script@v3
# env:
# GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
# with:
# script: |
# const compareCommits = await github.repos.compareCommits({
# owner: context.repo.owner,
# repo: context.repo.repo,
# base: context.payload.before,
# head: context.payload.after
# });
# # 根据分类生成发行说明
# const commits = compareCommits.data.commits.map(commit => `- ${commit.commit.message}`);
# return commits.join('\n');
# # 将发行说明写入文件 该文件会在后面的步骤中使用
# - name: build changelog
# id: build_changelog
# run: |
# echo "changelog=${{ steps.gen_release_notes.outputs.result }}" >> "$GITHUB_OUTPUT"
# 生成changelog再release
- name: Build Changelog
id: build_changelog
uses: mikepenz/[email protected]
with:
fromTag: v0.4.0
configurationJson: |
{
"template": "#{{CHANGELOG}}\n\n<details>\n<summary>Uncategorized</summary>\n\n#{{UNCATEGORIZED}}\n</details>",
"categories": [
{
"title": "## 🚀 Features",
"labels": ["feat"]
},
{
"title": "## 🐛 Fixes",
"labels": ["fix"]
},
{
"title": "## 📝 Documentation",
"labels": ["docs"]
},
{
"title": "## 🎨 Style",
"labels": ["style"]
},
{
"title": "## 🧰 Refactor",
"labels": ["refactor"]
},
{
"title": "## 🚨 Perf",
"labels": ["perf"]
},
{
"title": "## 🧪 Tests",
"labels": ["test"]
},
{
"title": "## 📦 Build",
"labels": ["build"]
},
{
"title": "## 📦 CI",
"labels": ["ci"]
},
{
"title": "## 📦 Chore",
"labels": ["chore"]
}
]
}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
# 创建release
- name: Create Release
id: create_release
continue-on-error: true
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.version }}
release_name: v${{ steps.get_version.outputs.version }}
body: ${{steps.build_changelog.outputs.changelog}}
draft: false
prerelease: false