Skip to content

Commit 9230af0

Browse files
author
Rajat
committed
Release automation
1 parent 15ce169 commit 9230af0

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Release From PR Comment
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
release:
9+
if: |
10+
github.event.issue.pull_request &&
11+
github.event.action == 'created' &&
12+
startsWith(github.event.comment.body, '/release ')
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: read
17+
issues: read
18+
steps:
19+
- name: Ensure commenter is allowed
20+
if: |
21+
github.event.comment.author_association != 'OWNER'
22+
run: |
23+
echo "Only OWNER can trigger releases."
24+
exit 1
25+
26+
- name: Validate PR merged to main and parse version
27+
id: guard
28+
uses: actions/github-script@v7
29+
with:
30+
script: |
31+
const { owner, repo } = context.repo;
32+
const prNumber = context.payload.issue.number;
33+
const comment = context.payload.comment.body.trim();
34+
const match = comment.match(/^\/release\s+(\d+\.\d+\.\d+)$/);
35+
if (!match) {
36+
core.setFailed("Invalid command. Use: /release <major.minor.patch>");
37+
return;
38+
}
39+
const version = match[1];
40+
const pr = await github.rest.pulls.get({
41+
owner,
42+
repo,
43+
pull_number: prNumber,
44+
});
45+
if (!pr.data.merged) {
46+
core.setFailed("PR is not merged.");
47+
return;
48+
}
49+
if (pr.data.base.ref !== "main") {
50+
core.setFailed("PR was not merged into main.");
51+
return;
52+
}
53+
core.setOutput("version", version);
54+
55+
- name: Checkout main
56+
uses: actions/checkout@v4
57+
with:
58+
ref: main
59+
fetch-depth: 0
60+
61+
- name: Setup Node
62+
uses: actions/setup-node@v4
63+
with:
64+
node-version: 23.x
65+
66+
- name: Setup pnpm
67+
uses: pnpm/action-setup@v4
68+
with:
69+
version: 10
70+
71+
- name: Configure git
72+
run: |
73+
git config user.name "github-actions[bot]"
74+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
75+
76+
- name: Run release script
77+
env:
78+
VERSION: ${{ steps.guard.outputs.version }}
79+
run: |
80+
pnpm release "$VERSION"

0 commit comments

Comments
 (0)