release.yml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. name: 自动发行版本
  2. on:
  3. workflow_dispatch:
  4. push:
  5. branches:
  6. - master
  7. jobs:
  8. release:
  9. runs-on: ubuntu-latest
  10. permissions:
  11. contents: write
  12. pages: write
  13. id-token: write
  14. name: 发行新版本
  15. steps:
  16. - name: 检出代码
  17. uses: actions/checkout@v4
  18. with:
  19. fetch-depth: 0
  20. - name: 检查版本
  21. id: version-check
  22. run: |
  23. VERSION=$(./scripts/is-newer-version.bash)
  24. echo "version=${VERSION}" >> $GITHUB_OUTPUT
  25. if [ "$VERSION" != "0" ]; then
  26. echo "检测到新版本: $VERSION"
  27. else
  28. echo "没有新版本需要发行"
  29. fi
  30. - name: 推送标签
  31. if: steps.version-check.outputs.version != '0'
  32. id: push-tag
  33. run: |
  34. tag="v${{ steps.version-check.outputs.version }}"
  35. git config user.name "${GITHUB_ACTOR}"
  36. git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
  37. git tag -a "${tag}" -m "Release ${tag}"
  38. git push origin "${tag}"
  39. echo "tag_name=${tag}" >> $GITHUB_OUTPUT
  40. - name: 配置环境
  41. if: steps.version-check.outputs.version != '0'
  42. run: |
  43. # 安装 Python 依赖
  44. python3 -m pip install --upgrade pip
  45. pip3 install -r requirements.txt
  46. # 安装构建依赖
  47. sudo apt-get update
  48. sudo apt-get install -y build-essential wget tar gzip
  49. - name: 编译字体
  50. if: steps.version-check.outputs.version != '0'
  51. run: |
  52. # 运行构建脚本
  53. bash build.bash
  54. - name: 创建 GitHub Release
  55. if: steps.version-check.outputs.version != '0'
  56. uses: ncipollo/release-action@v1
  57. with:
  58. generateReleaseNotes: true
  59. tag: "v${{ steps.version-check.outputs.version }}"
  60. artifacts: "output/*"
  61. - name: 删除标签(如果失败)
  62. if: (cancelled() || failure()) && steps.push-tag.outputs.tag_name != ''
  63. run: |
  64. git config user.name "${GITHUB_ACTOR}"
  65. git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
  66. git push --delete origin "${{ steps.push-tag.outputs.tag_name }}"
  67. git tag -d "${{ steps.push-tag.outputs.tag_name }}"