|
| 1 | +name: Auto Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - main |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-version-and-release: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v3 |
| 18 | + with: |
| 19 | + fetch-depth: 0 # 获取完整历史以便比较 |
| 20 | + |
| 21 | + - name: Extract version |
| 22 | + id: get_version |
| 23 | + run: | |
| 24 | + VERSION=$(grep -oP "__version__ = '\K[^']+" ksyun/__init__.py) |
| 25 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 26 | + echo "tag=v$VERSION" >> $GITHUB_OUTPUT |
| 27 | + echo "Current version: $VERSION" |
| 28 | +
|
| 29 | + - name: Check if tag exists |
| 30 | + id: check_tag |
| 31 | + run: | |
| 32 | + if git rev-parse "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then |
| 33 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 34 | + echo "Tag v${{ steps.get_version.outputs.version }} already exists" |
| 35 | + else |
| 36 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 37 | + echo "Tag v${{ steps.get_version.outputs.version }} does not exist" |
| 38 | + fi |
| 39 | +
|
| 40 | + - name: Create tag and release |
| 41 | + if: steps.check_tag.outputs.exists == 'false' |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + run: | |
| 45 | + git config user.name "github-actions[bot]" |
| 46 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 47 | +
|
| 48 | + # 创建并推送 tag |
| 49 | + git tag -a ${{ steps.get_version.outputs.tag }} -m "Release ${{ steps.get_version.outputs.tag }}" |
| 50 | + git push origin ${{ steps.get_version.outputs.tag }} |
| 51 | +
|
| 52 | + # 使用 GitHub CLI 创建 release |
| 53 | + gh release create ${{ steps.get_version.outputs.tag }} \ |
| 54 | + --title "Release ${{ steps.get_version.outputs.tag }}" \ |
| 55 | + --notes "## Release ${{ steps.get_version.outputs.tag }} |
| 56 | +
|
| 57 | +Auto-generated release from version update in ksyun/__init__.py |
| 58 | + |
| 59 | +### Changes |
| 60 | +See commit history for details." \ |
| 61 | + --latest |
| 62 | + |
| 63 | + - name: Release created |
| 64 | + if: steps.check_tag.outputs.exists == 'false' |
| 65 | + run: | |
| 66 | + echo "✅ Successfully created release ${{ steps.get_version.outputs.tag }}" |
| 67 | +
|
| 68 | + - name: Skip release |
| 69 | + if: steps.check_tag.outputs.exists == 'true' |
| 70 | + run: | |
| 71 | + echo "⏭️ Skipped: Tag ${{ steps.get_version.outputs.tag }} already exists" |
0 commit comments