release-cycle.yml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. name: Release Cycle
  2. on:
  3. push:
  4. branches:
  5. - release-v*
  6. workflow_dispatch: {}
  7. concurrency: ${{ github.workflow }}-${{ github.ref }}
  8. jobs:
  9. state:
  10. name: Check state
  11. permissions:
  12. pull-requests: read
  13. runs-on: ubuntu-latest
  14. steps:
  15. - uses: actions/checkout@v3
  16. - name: Set up environment
  17. uses: ./.github/actions/setup
  18. - id: state
  19. name: Get state
  20. uses: actions/github-script@v6
  21. env:
  22. TRIGGERING_ACTOR: ${{ github.triggering_actor }}
  23. with:
  24. result-encoding: string
  25. script: await require('./scripts/release/workflow/state.js')({ github, context, core })
  26. outputs:
  27. # Job Flags
  28. start: ${{ steps.state.outputs.start }}
  29. changesets: ${{ steps.state.outputs.changesets }}
  30. promote: ${{ steps.state.outputs.promote }}
  31. publish: ${{ steps.state.outputs.publish }}
  32. merge: ${{ steps.state.outputs.merge }}
  33. # Global variables
  34. is_prerelease: ${{ steps.state.outputs.is_prerelease }}
  35. start:
  36. needs: state
  37. name: Start new release candidate
  38. permissions:
  39. contents: write
  40. actions: write
  41. if: needs.state.outputs.start == 'true'
  42. runs-on: ubuntu-latest
  43. steps:
  44. - uses: actions/checkout@v3
  45. - name: Set up environment
  46. uses: ./.github/actions/setup
  47. - run: bash scripts/git-user-config.sh
  48. - id: start
  49. name: Create branch with release candidate
  50. run: bash scripts/release/workflow/start.sh
  51. - name: Re-run workflow
  52. uses: actions/github-script@v6
  53. env:
  54. REF: ${{ steps.start.outputs.branch }}
  55. with:
  56. script: await require('./scripts/release/workflow/rerun.js')({ github, context })
  57. promote:
  58. needs: state
  59. name: Promote to final release
  60. permissions:
  61. contents: write
  62. actions: write
  63. if: needs.state.outputs.promote == 'true'
  64. runs-on: ubuntu-latest
  65. steps:
  66. - uses: actions/checkout@v3
  67. - name: Set up environment
  68. uses: ./.github/actions/setup
  69. - run: bash scripts/git-user-config.sh
  70. - name: Exit prerelease state
  71. if: needs.state.outputs.is_prerelease == 'true'
  72. run: bash scripts/release/workflow/exit-prerelease.sh
  73. - name: Re-run workflow
  74. uses: actions/github-script@v6
  75. with:
  76. script: await require('./scripts/release/workflow/rerun.js')({ github, context })
  77. changesets:
  78. needs: state
  79. name: Changesets PR
  80. permissions:
  81. contents: write
  82. pull-requests: write
  83. if: needs.state.outputs.changesets == 'true'
  84. runs-on: ubuntu-latest
  85. steps:
  86. - uses: actions/checkout@v3
  87. with:
  88. fetch-depth: 0 # To get all tags
  89. - name: Set up environment
  90. uses: ./.github/actions/setup
  91. - name: Set release title
  92. uses: actions/github-script@v6
  93. with:
  94. result-encoding: string
  95. script: await require('./scripts/release/workflow/set-changesets-pr-title.js')({ core })
  96. - name: Create PR
  97. uses: changesets/action@v1
  98. env:
  99. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  100. PRERELEASE: ${{ needs.state.outputs.is_prerelease }}
  101. with:
  102. version: npm run version
  103. title: ${{ env.TITLE }}
  104. commit: ${{ env.TITLE }}
  105. body: | # Wait for support on this https://github.com/changesets/action/pull/250
  106. This is an automated PR for releasing ${{ github.repository }}
  107. Check [CHANGELOG.md](${{ github.repository }}/CHANGELOG.md)
  108. publish:
  109. needs: state
  110. name: Publish to npm
  111. environment: npm
  112. permissions:
  113. contents: write
  114. if: needs.state.outputs.publish == 'true'
  115. runs-on: ubuntu-latest
  116. steps:
  117. - uses: actions/checkout@v3
  118. - name: Set up environment
  119. uses: ./.github/actions/setup
  120. - id: pack
  121. name: Pack
  122. run: bash scripts/release/workflow/pack.sh
  123. env:
  124. PRERELEASE: ${{ needs.state.outputs.is_prerelease }}
  125. - name: Tag
  126. run: npx changeset tag
  127. - name: Publish
  128. run: bash scripts/release/workflow/publish.sh
  129. env:
  130. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
  131. TARBALL: ${{ steps.pack.outputs.tarball }}
  132. TAG: ${{ steps.pack.outputs.tag }}
  133. - name: Push tags
  134. run: git push --tags
  135. - name: Create Github Release
  136. uses: actions/github-script@v6
  137. env:
  138. PRERELEASE: ${{ needs.state.outputs.is_prerelease }}
  139. with:
  140. script: await require('./scripts/release/workflow/github-release.js')({ github, context })
  141. merge:
  142. needs: state
  143. name: Release PR back to master
  144. permissions:
  145. contents: write
  146. pull-requests: write
  147. if: needs.state.outputs.merge == 'true'
  148. runs-on: ubuntu-latest
  149. steps:
  150. - uses: actions/checkout@v3
  151. with:
  152. fetch-depth: 0 # All branches
  153. - name: Set up environment
  154. uses: ./.github/actions/setup
  155. - run: bash scripts/git-user-config.sh
  156. - name: Create branch to merge
  157. run: bash scripts/release/workflow/prepare-release-merge.sh
  158. - name: Create PR back to master
  159. uses: actions/github-script@v6
  160. with:
  161. script: |
  162. await github.rest.pulls.create({
  163. owner: context.repo.owner,
  164. repo: context.repo.repo,
  165. head: 'merge/${{ github.ref_name }}',
  166. base: 'master',
  167. title: '${{ format('Merge {0} branch', github.ref_name) }}'
  168. });