Skip to content

Commit c199e7f

Browse files
committed
chore: changes trigger hook to be pull_request
1 parent 728a752 commit c199e7f

File tree

1 file changed

+14
-50
lines changed

1 file changed

+14
-50
lines changed
Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,39 @@
11
name: Publish Package
22

33
on:
4-
issue_comment:
5-
types: [created]
6-
pull_request_review_comment:
7-
types: [created]
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
# runs on main PRs targeting main
8+
- main
89

910
permissions:
10-
contents: write
11-
packages: write
12-
issues: write
13-
pull-requests: write
11+
contents: write # To push version bump commit and tag
1412

1513
jobs:
1614
publish:
17-
if: ${{ startsWith(github.event.comment.body, '/publish') }}
15+
if: github.event.pull_request.merged == true && (contains(github.event.pull_request.labels.*.name, 'release-major') || contains(github.event.pull_request.labels.*.name, 'release-minor') || contains(github.event.pull_request.labels.*.name, 'release-patch'))
1816
runs-on: ubuntu-latest
1917
steps:
20-
- name: Check if commenter has write access
21-
id: check_permissions
22-
uses: actions-cool/check-user-permission@v2
23-
with:
24-
require: "write"
25-
username: ${{ github.event.comment.user.login }}
26-
27-
- name: Fail if user doesn't have permissions
28-
if: steps.check_permissions.outputs.require-result != 'true'
29-
run: |
30-
echo "::error::Only users with write permissions can run this workflow."
31-
exit 1
32-
33-
- name: Extract version type
18+
- name: Determine version type from label
3419
id: version-type
3520
run: |
36-
COMMENT="${{ github.event.comment.body }}"
37-
if [[ "$COMMENT" == "/publish major" ]]; then
21+
LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}"
22+
if echo "$LABELS" | grep -q '"release-major"'; then
3823
echo "type=major" >> $GITHUB_OUTPUT
39-
elif [[ "$COMMENT" == "/publish minor" ]]; then
24+
elif echo "$LABELS" | grep -q '"release-minor"'; then
4025
echo "type=minor" >> $GITHUB_OUTPUT
41-
elif [[ "$COMMENT" == "/publish patch" ]]; then
26+
elif echo "$LABELS" | grep -q '"release-patch"'; then
4227
echo "type=patch" >> $GITHUB_OUTPUT
4328
else
44-
echo "Unknown version type. Use '/publish major', '/publish minor', or '/publish patch'"
29+
echo "::error::No valid release label found (release-major, release-minor, release-patch)."
4530
exit 1
4631
fi
4732
4833
- name: Checkout
4934
uses: actions/checkout@v3
5035
with:
36+
ref: "main"
5137
fetch-depth: 0
5238
token: ${{ secrets.GITHUB_TOKEN }}
5339

@@ -100,25 +86,3 @@ jobs:
10086
run: yarn publish
10187
env:
10288
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
103-
104-
- name: Comment on issue/PR
105-
uses: actions/github-script@v6
106-
with:
107-
github-token: ${{ secrets.GITHUB_TOKEN }}
108-
script: |
109-
const issueNumber = context.issue.number || context.payload.pull_request?.number;
110-
if (!issueNumber) {
111-
console.log("Could not determine issue/PR number");
112-
return;
113-
}
114-
115-
const newVersion = '${{ steps.bump-version.outputs.new_version }}';
116-
const releaseUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/v${newVersion}`;
117-
const npmUrl = `https://www.npmjs.com/package/@jam.dev/sdk/v/${newVersion}`;
118-
119-
await github.rest.issues.createComment({
120-
owner: context.repo.owner,
121-
repo: context.repo.repo,
122-
issue_number: issueNumber,
123-
body: `🎉 Version v${newVersion} has been published!\n\n- [GitHub Release](${releaseUrl})\n- [NPM Package](${npmUrl})`
124-
});

0 commit comments

Comments
 (0)