auto-releases.yml 3.9 KB

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