|
1 | 1 | name: Publish Package |
2 | 2 |
|
3 | 3 | 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 |
8 | 9 |
|
9 | 10 | permissions: |
10 | | - contents: write |
11 | | - packages: write |
12 | | - issues: write |
13 | | - pull-requests: write |
| 11 | + contents: write # To push version bump commit and tag |
14 | 12 |
|
15 | 13 | jobs: |
16 | 14 | 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')) |
18 | 16 | runs-on: ubuntu-latest |
19 | 17 | 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 |
34 | 19 | id: version-type |
35 | 20 | 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 |
38 | 23 | echo "type=major" >> $GITHUB_OUTPUT |
39 | | - elif [[ "$COMMENT" == "/publish minor" ]]; then |
| 24 | + elif echo "$LABELS" | grep -q '"release-minor"'; then |
40 | 25 | echo "type=minor" >> $GITHUB_OUTPUT |
41 | | - elif [[ "$COMMENT" == "/publish patch" ]]; then |
| 26 | + elif echo "$LABELS" | grep -q '"release-patch"'; then |
42 | 27 | echo "type=patch" >> $GITHUB_OUTPUT |
43 | 28 | 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)." |
45 | 30 | exit 1 |
46 | 31 | fi |
47 | 32 |
|
48 | 33 | - name: Checkout |
49 | 34 | uses: actions/checkout@v3 |
50 | 35 | with: |
| 36 | + ref: "main" |
51 | 37 | fetch-depth: 0 |
52 | 38 | token: ${{ secrets.GITHUB_TOKEN }} |
53 | 39 |
|
@@ -100,25 +86,3 @@ jobs: |
100 | 86 | run: yarn publish |
101 | 87 | env: |
102 | 88 | 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