Skip to content

✨ feat: test1

✨ feat: test1 #84

Workflow file for this run

# 推送到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=$(echo "${{ steps.gen_release_notes.outputs.result }}" | grep -E '^\- (init|feat|fix|docs|style|refactor|perf|test|build|ci|chore)(\(.+\))?: .{1,50}$')" >> "$GITHUB_OUTPUT"
# 创建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