|
22 | 22 | permissions: |
23 | 23 | contents: read |
24 | 24 | issues: write |
25 | | - pull-requests: read |
| 25 | + pull-requests: write |
26 | 26 |
|
27 | 27 | env: |
28 | 28 | DOCKER_BUILDKIT: 1 |
|
62 | 62 |
|
63 | 63 | - run: kamal deploy -d preview |
64 | 64 |
|
| 65 | + - name: Comment preview URL on PR |
| 66 | + uses: actions/github-script@v7 |
| 67 | + with: |
| 68 | + github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} |
| 69 | + script: | |
| 70 | + const branch = '${{ github.ref_name }}'; |
| 71 | + const previewUrl = 'https://${{ env.KAMAL_APP_DOMAIN }}'; |
| 72 | + const body = `## Preview deployment ready\n\n**Preview URL:** [${previewUrl}](${previewUrl})`; |
| 73 | +
|
| 74 | + const { data: prs } = await github.rest.pulls.list({ |
| 75 | + owner: context.repo.owner, |
| 76 | + repo: context.repo.repo, |
| 77 | + state: 'open', |
| 78 | + head: `${context.repo.owner}:${branch}` |
| 79 | + }); |
| 80 | +
|
| 81 | + if (prs.length === 0) return; |
| 82 | +
|
| 83 | + const issue_number = prs[0].number; |
| 84 | + const { data: comments } = await github.rest.issues.listComments({ |
| 85 | + owner: context.repo.owner, |
| 86 | + repo: context.repo.repo, |
| 87 | + issue_number |
| 88 | + }); |
| 89 | +
|
| 90 | + const previewComment = comments.find( |
| 91 | + c => c.user.type === 'Bot' && c.body.startsWith('## Preview deployment ready') |
| 92 | + ); |
| 93 | +
|
| 94 | + if (previewComment) { |
| 95 | + await github.rest.issues.updateComment({ |
| 96 | + owner: context.repo.owner, |
| 97 | + repo: context.repo.repo, |
| 98 | + comment_id: previewComment.id, |
| 99 | + body |
| 100 | + }); |
| 101 | + } else { |
| 102 | + await github.rest.issues.createComment({ |
| 103 | + owner: context.repo.owner, |
| 104 | + repo: context.repo.repo, |
| 105 | + issue_number, |
| 106 | + body |
| 107 | + }); |
| 108 | + } |
| 109 | +
|
65 | 110 | comment-preview-on-pr: |
66 | 111 | runs-on: ubuntu-latest |
67 | | - if: github.event_name == 'pull_request_target' && github.event.action != 'closed' |
| 112 | + if: github.event_name == 'pull_request_target' |
68 | 113 | permissions: |
69 | 114 | contents: read |
70 | 115 | issues: write |
|
88 | 133 | - name: Comment preview URL on PR |
89 | 134 | uses: actions/github-script@v7 |
90 | 135 | with: |
91 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
| 136 | + github-token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} |
92 | 137 | script: | |
93 | | - const previewUrl = 'https://website-${BRANCH_SLUG}.fairdataihub.org'; |
| 138 | + const previewUrl = 'https://${{ env.KAMAL_APP_DOMAIN }}'; |
94 | 139 | const issue_number = context.payload.pull_request.number; |
95 | 140 |
|
96 | 141 | const body = `## Preview deployment ready\n\n**Preview URL:** [${previewUrl}](${previewUrl})`; |
|
0 commit comments