🧪 test: 测试changelog #89
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 推送到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 |