1
0

release.yml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. name: 自动发行版本
  2. on:
  3. push:
  4. branches:
  5. - master
  6. jobs:
  7. test:
  8. uses: ./.github/workflows/test.yml
  9. release:
  10. needs: test
  11. runs-on: ubuntu-latest
  12. permissions:
  13. contents: write
  14. pages: write
  15. id-token: write
  16. name: 发行新版本
  17. steps:
  18. - name: 检出代码
  19. uses: actions/checkout@v4
  20. with:
  21. fetch-depth: 0
  22. - name: 检查版本
  23. id: version-check
  24. run: |
  25. VERSION=$(./scripts/is-newer-version.bash)
  26. echo "version=${VERSION}" >> $GITHUB_OUTPUT
  27. if [ "$VERSION" != "0" ]; then
  28. echo "检测到新版本: $VERSION"
  29. else
  30. echo "没有新版本需要发行"
  31. fi
  32. - name: 推送标签
  33. if: steps.version-check.outputs.version != '0'
  34. id: push-tag
  35. run: |
  36. tag="v${{ steps.version-check.outputs.version }}"
  37. git config user.name "${GITHUB_ACTOR}"
  38. git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
  39. git tag -a "${tag}" -m "Release ${tag}"
  40. git push origin "${tag}"
  41. echo "tag_name=${tag}" >> $GITHUB_OUTPUT
  42. - name: 准备发行文件
  43. if: steps.version-check.outputs.version != '0'
  44. run: |
  45. mkdir -p ../release
  46. cp -v clean_trash.sh ../release/clean_trash
  47. # 确保脚本具有执行权限
  48. chmod +x ../release/clean_trash
  49. - name: 创建 GitHub Release
  50. if: steps.version-check.outputs.version != '0'
  51. uses: ncipollo/release-action@v1
  52. with:
  53. generateReleaseNotes: true
  54. tag: "v${{ steps.version-check.outputs.version }}"
  55. artifacts: "../release/clean_trash"
  56. - name: 删除标签(如果失败)
  57. if: (cancelled() || failure()) && steps.push-tag.outputs.tag_name != ''
  58. run: |
  59. git config user.name "${GITHUB_ACTOR}"
  60. git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
  61. git push --delete origin "${{ steps.push-tag.outputs.tag_name }}"
  62. git tag -d "${{ steps.push-tag.outputs.tag_name }}"