Skip to content

Commit c858905

Browse files
committed
Add workflow to create new tag after merge
1 parent 6f118a6 commit c858905

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

.github/workflows/create-new-tag.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
})

.github/workflows/create-release-pr.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ jobs:
8888
with:
8989
path: caller
9090
add-paths: ${{ inputs.changelog }}
91-
branch: automation-create-release-${{ steps.get-next-version.outputs.next_version }}
9291
commit-message: ${{ steps.bump-changelog.outputs.commit_message }}
9392
title: ${{ steps.bump-changelog.outputs.pr_title }}
9493
body-path: ${{ steps.bump-changelog.outputs.pr_bodyfile }}
94+
# This branch name format needs to be kept in-sync with the parser in
95+
# create-new-tag.yaml
96+
branch: automation-create-release-${{ steps.get-next-version.outputs.next_version }}

0 commit comments

Comments
 (0)