release.yml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. # 验证输出文件
  55. if [ ! -f "output/xibo.psfu.gz" ]; then
  56. echo "错误:字体文件生成失败"
  57. exit 1
  58. fi
  59. # 显示文件信息
  60. ls -la output/xibo.psfu.gz
  61. - name: 创建 GitHub Release
  62. if: steps.version-check.outputs.version != '0'
  63. uses: ncipollo/release-action@v1
  64. with:
  65. generateReleaseNotes: true
  66. tag: "v${{ steps.version-check.outputs.version }}"
  67. artifacts: "output/xibo.psfu.gz,output/xibo.psf,output/xibo.txt"
  68. - name: 删除标签(如果失败)
  69. if: (cancelled() || failure()) && steps.push-tag.outputs.tag_name != ''
  70. run: |
  71. git config user.name "${GITHUB_ACTOR}"
  72. git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
  73. git push --delete origin "${{ steps.push-tag.outputs.tag_name }}"
  74. git tag -d "${{ steps.push-tag.outputs.tag_name }}"