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