|
| 1 | +--- |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + |
| 5 | +jobs: |
| 6 | + release-tag: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + |
| 9 | + steps: |
| 10 | + - id: parse-version |
| 11 | + uses: actions/github-script@v7 |
| 12 | + with: |
| 13 | + script: | |
| 14 | + // Sanity-check that this was called from an appropriate merge event and |
| 15 | + // extract the version number embedded in the branch name. |
| 16 | + if (context.eventName !== 'pull_request') { |
| 17 | + core.setFailed('Workflow requires pull_request events') |
| 18 | + process.exit() |
| 19 | + } |
| 20 | +
|
| 21 | + if (!context.payload.pull_request.merged || context.payload.pull_request.state !== 'closed') { |
| 22 | + core.setFailed('Workflow should only be called on merged and closed PRs') |
| 23 | + process.exit() |
| 24 | + } |
| 25 | +
|
| 26 | + if (context.payload.pull_request.user.type !== 'bot') { |
| 27 | + core.setFailed('Workflow should only be called for bot-generated release PRs') |
| 28 | + process.exit() |
| 29 | + } |
| 30 | +
|
| 31 | + // This regex needs to kept in-sync with the pattern in create-release-pr.yaml |
| 32 | + const regex = /^automation-create-release-(.*)$/i |
| 33 | + const parsed_version = context.payload.pull_request.head.label.match(regex) |
| 34 | +
|
| 35 | + if (!parsed_version || !parsed_version[1].length) { |
| 36 | + core.setFailed('Workflow not called from an appropriate branch name') |
| 37 | + process.exit() |
| 38 | + } |
| 39 | +
|
| 40 | + github.rest.repos.createRelease({ |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + tag_name: `v${new_version}`, |
| 44 | + target_commitish: context.payload.pull_request.merge_commit_sha, |
| 45 | + name: `Release ${new_version}`, |
| 46 | + draft: true, |
| 47 | + generate_release_notes: true, |
| 48 | + body: `Automatically generated after merging #${context.payload.number}.` |
| 49 | + }) |
0 commit comments