@@ -65,51 +65,28 @@ jobs:
65
65
git config --global user.name "github-actions[bot]"
66
66
git config --global user.email "github-actions[bot]@users.noreply.github.com"
67
67
68
+ - name : Get PR information
69
+ uses : potiuk/get-workflow-origin@v1_6
70
+ id : source-run-info
71
+ with :
72
+ token : ${{ github.token }}
73
+ sourceRunId : ${{ github.event.workflow_run.id }}
74
+
68
75
- name : Deploy to gh-pages
69
76
uses : peaceiris/actions-gh-pages@v3
70
77
with :
71
78
github_token : ${{ github.token }}
72
79
publish_dir : ./public
73
80
publish_branch : gh-pages
74
- destination_dir : ${{ github.event.workflow_run.pull_requests[0].number || 'main' }}/
75
-
76
- - name : Update or create preview comment
77
- uses : actions/github-script@v6
78
- if : github.event.workflow_run.event == 'pull_request'
81
+ destination_dir : ${{ steps.source-run-info.outputs.pullRequestNumber || 'main' }}/
82
+
83
+ - name : Create or update PR comment
84
+ if : steps.source-run-info.outputs.pullRequestNumber
85
+ uses : peter-evans/create-or-update-comment@v3
79
86
with :
80
- script : |
81
- const prNumber = ${{ github.event.workflow_run.pull_requests[0].number }};
82
- const owner = context.repo.owner;
83
- const repo = context.repo.repo;
84
- const commitSha = ${{ github.event.workflow_run.head_sha }};
85
- const baseUrl = `https://${owner}.github.io/${repo}/`;
86
- const previewUrl = `${baseUrl}${prNumber}/`;
87
- const body = `Preview the changes for PR #${prNumber} (${commitSha}) here: [${previewUrl}](${previewUrl})`;
88
-
89
- // Retrieve comments for the PR to check if the comment already exists
90
- const { data: comments } = await github.rest.issues.listComments({
91
- owner: owner,
92
- repo: repo,
93
- issue_number: prNumber,
94
- });
95
-
96
- // Look for an existing comment with the preview link
97
- const existingComment = comments.find(comment => comment.body.includes('Preview the changes for PR'));
98
-
99
- if (existingComment) {
100
- // Update the existing comment
101
- await github.rest.issues.updateComment({
102
- owner: owner,
103
- repo: repo,
104
- comment_id: existingComment.id,
105
- body: body,
106
- });
107
- } else {
108
- // Create a new comment
109
- await github.rest.issues.createComment({
110
- issue_number: prNumber,
111
- owner: owner,
112
- repo: repo,
113
- body: body,
114
- });
115
- }
87
+ token : ${{ secrets.GITHUB_TOKEN }}
88
+ issue-number : ${{ steps.source-run-info.outputs.pullRequestNumber }}
89
+ body : |
90
+ Preview the changes for PR #${{ steps.source-run-info.outputs.pullRequestNumber }} (${{ github.event.workflow_run.head_sha }}) here: https://gh.cp-algorithms.com/${{ steps.source-run-info.outputs.pullRequestNumber }}/
91
+ body-includes : ' Preview the changes for PR'
92
+ mode : replace
0 commit comments