auto-releases.yml 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # 当分支 main 有 push 事件并且 tag 为 v* 时触发,使用 GitHub Actions 执行以下步骤:
  2. # 读取 tag 内容,例如 v0.0.12,作为 Releases title
  3. # 读取仓库内的 /doc/guide/changelog.md 和 /doc/guide/changelog_en.md 中第一个二级标题与第二个二级标题之间的内容
  4. # 将两个内容合并为一个字符串,中间使用 --- 分隔
  5. # 组成内容示例为:
  6. # - 新增了一个功能。
  7. # ---
  8. # - Add a new feature.
  9. # 将合并的内容作为 Releases describe
  10. # Set as the latest release 并发布本次 Release
  11. name: Auto releases
  12. on:
  13. push:
  14. branches:
  15. - main
  16. tags:
  17. - 'v*'
  18. jobs:
  19. release-please:
  20. runs-on: ubuntu-latest
  21. steps:
  22. - uses: actions/checkout@v2
  23. # 读取 tag 内容,例如 v0.0.12,作为 Releases title
  24. - name: Get tag
  25. id: tag
  26. run: |
  27. echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
  28. # echo ::set-output name=tag::${GITHUB_REF#refs/*/}
  29. # 读取仓库内的 /doc/guide/changelog.md 中第一个二级标题与第二个二级标题之间的内容,包括换行,如
  30. # ## 0.0.12
  31. # - 新增了一个功能。
  32. # ## 0.0.11
  33. # 只取第一个二级标题与第二个二级标题之间的内容,结果为:
  34. # - 新增了一个功能。
  35. - name: Get changelog
  36. id: changelog
  37. run: |
  38. echo changelog=$(awk '/^## /{n++}{if(n==2){exit}}1' doc/guide/changelog.md | sed -n '/^## /{n;p;}') >> $GITHUB_OUTPUT
  39. # echo ::set-output name=changelog::$(awk '/^## /{n++}{if(n==2){exit}}1' doc/guide/changelog.md | sed -n '/^## /{n;p;}')
  40. # 读取仓库内的 /doc/guide/changelog_en.md 中第一个二级标题与第二个二级标题之间的内容,包括换行,如
  41. # ## 0.0.12
  42. # - Add a new feature.
  43. # ## 0.0.11
  44. # 只取第一个二级标题与第二个二级标题之间的内容,结果为:
  45. # - Add a new feature.
  46. - name: Get changelog_en
  47. id: changelog_en
  48. run: |
  49. echo changelog_en=$(awk '/^## /{n++}{if(n==2){exit}}1' doc/guide/changelog_en.md | sed -n '/^## /{n;p;}') >> $GITHUB_OUTPUT
  50. # echo ::set-output name=changelog_en::$(awk '/^## /{n++}{if(n==2){exit}}1' doc/guide/changelog_en.md | sed -n '/^## /{n;p;}')
  51. # 将两个内容合并为一个字符串,中间使用 --- 分隔
  52. - name: Get body
  53. id: body
  54. run: |
  55. echo body=${{ steps.changelog.outputs.changelog }}\\n---\\n${{ steps.changelog_en.outputs.changelog_en }} >> $GITHUB_OUTPUT
  56. # echo ::set-output name=body::"${{ steps.changelog.outputs.changelog }}\n---\n${{ steps.changelog_en.outputs.changelog_en }}"
  57. # 组成内容示例为:
  58. # - 新增了一个功能。
  59. # ---
  60. # - Add a new feature.
  61. # 此处打印一下上述步骤中的输出内容 body,用来检查输出内容是否正确
  62. - name: Log outputs
  63. run: |
  64. cat $GITHUB_OUTPUT
  65. echo $GITHUB_OUTPUT
  66. # 将合并的内容作为 Releases describe,并作为 latest release 发布本次 Release
  67. - name: Release
  68. uses: actions/create-release@v1
  69. env:
  70. GITHUB_TOKEN: ${{ secrets.STDF_GITHUB_TOKEN }}
  71. with:
  72. tag_name: ${{ steps.tag.outputs.tag }}
  73. release_name: ${{ steps.tag.outputs.tag }}
  74. body: ${{ steps.body.outputs.body }}
  75. draft: false
  76. prerelease: false