-
Notifications
You must be signed in to change notification settings - Fork 1
98 lines (81 loc) · 2.95 KB
/
auto-release.yml
File metadata and controls
98 lines (81 loc) · 2.95 KB
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
name: Auto Release and Publish
on:
push:
branches:
- main
jobs:
release-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # 获取完整历史以便比较
- name: Extract version
id: get_version
run: |
VERSION=$(grep -oP "__version__ = '\K[^']+" ksyun/__init__.py)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag v${{ steps.get_version.outputs.version }} already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag v${{ steps.get_version.outputs.version }} does not exist"
fi
- name: Create tag and release
if: steps.check_tag.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# 创建并推送 tag
git tag -a ${{ steps.get_version.outputs.tag }} -m "${{ steps.get_version.outputs.tag }}"
git push origin ${{ steps.get_version.outputs.tag }}
# 创建 release notes
cat > release_notes.md << 'EOF'
## Release ${{ steps.get_version.outputs.tag }}
Auto-generated release from version update in ksyun/__init__.py
### Changes
See commit history for details.
EOF
# 使用 GitHub CLI 创建 release
gh release create ${{ steps.get_version.outputs.tag }} \
--title "${{ steps.get_version.outputs.tag }}" \
--notes-file release_notes.md \
--latest
- name: Set up Python
if: steps.check_tag.outputs.exists == 'false'
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install dependencies
if: steps.check_tag.outputs.exists == 'false'
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
if: steps.check_tag.outputs.exists == 'false'
run: python -m build
- name: Publish package to PyPI
if: steps.check_tag.outputs.exists == 'false'
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Success
if: steps.check_tag.outputs.exists == 'false'
run: |
echo "✅ Successfully created release ${{ steps.get_version.outputs.tag }} and published to PyPI"
- name: Skip release
if: steps.check_tag.outputs.exists == 'true'
run: |
echo "⏭️ Skipped: Tag ${{ steps.get_version.outputs.tag }} already exists"