release.yml 1.9 KB

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