|
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') |
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 |
34 | | - id: version-type |
35 | | - run: | |
36 | | - COMMENT="${{ github.event.comment.body }}" |
37 | | - if [[ "$COMMENT" == "/publish major" ]]; then |
38 | | - echo "type=major" >> $GITHUB_OUTPUT |
39 | | - elif [[ "$COMMENT" == "/publish minor" ]]; then |
40 | | - echo "type=minor" >> $GITHUB_OUTPUT |
41 | | - elif [[ "$COMMENT" == "/publish patch" ]]; then |
42 | | - echo "type=patch" >> $GITHUB_OUTPUT |
43 | | - else |
44 | | - echo "Unknown version type. Use '/publish major', '/publish minor', or '/publish patch'" |
45 | | - exit 1 |
46 | | - fi |
47 | | -
|
48 | 18 | - name: Checkout |
49 | 19 | uses: actions/checkout@v3 |
50 | 20 | with: |
| 21 | + ref: "main" |
51 | 22 | fetch-depth: 0 |
52 | 23 | token: ${{ secrets.GITHUB_TOKEN }} |
53 | 24 |
|
|
72 | 43 | - name: Bump version |
73 | 44 | id: bump-version |
74 | 45 | run: | |
75 | | - VERSION_TYPE="${{ steps.version-type.outputs.type }}" |
| 46 | + # Defaulting to patch release, as trigger no longer specifies type |
| 47 | + VERSION_TYPE="patch" |
76 | 48 | yarn version --"$VERSION_TYPE" --no-git-tag-version |
77 | 49 | NEW_VERSION=$(node -p "require('./package.json').version") |
78 | 50 | echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
@@ -100,25 +72,3 @@ jobs: |
100 | 72 | run: yarn publish |
101 | 73 | env: |
102 | 74 | 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