@@ -17,6 +17,9 @@ permissions:
17
17
pull-requests : write
18
18
actions : read
19
19
20
+ concurrency :
21
+ group : preview-site
22
+
20
23
jobs :
21
24
deploy :
22
25
if : github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
@@ -128,26 +131,45 @@ jobs:
128
131
uses : Azure/static-web-apps-deploy@v1
129
132
with :
130
133
azure_static_web_apps_api_token : ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PREVIEW }}
131
- repo_token : ${{ secrets.GITHUB_TOKEN }}
134
+ # Unsetting the repo token so we can control commenting ourselves.
135
+ # repo_token: ${{ secrets.GITHUB_TOKEN }}
132
136
action : " upload"
133
137
app_location : " site"
134
138
skip_app_build : true
135
139
production_branch : v2
136
140
deployment_environment : ${{ fromJson(steps.get-info.outputs.result).pr }}
137
141
138
142
- name : Comment on PR
139
- # azure/static-web-apps-deploy seems to comment itself when the event is pull_request_target
140
- if : ${{ steps.get-info.outputs.result != 'null' && github.event_name != 'pull_request_target' }}
143
+ if : ${{ steps.get-info.outputs.result != 'null' }}
141
144
uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
142
145
env :
143
146
PR_NUMBER : ${{ fromJson(steps.get-info.outputs.result).pr }}
144
147
SITE_URL : ${{ steps.deploy.outputs.static_web_app_url }}
145
148
with :
146
149
github-token : ${{ secrets.GITHUB_TOKEN }}
147
150
script : |
151
+ const prefix = "Azure Static Web Apps: Your stage site is ready!";
152
+ const comments = await github.paginate(github.rest.issues.listComments, {
153
+ owner: context.repo.owner,
154
+ repo: context.repo.repo,
155
+ issue_number: +process.env.PR_NUMBER,
156
+ per_page: 100,
157
+ });
158
+
159
+ for (const comment of comments) {
160
+ if (comment.user?.login === "github-actions[bot]" && comment.body?.startsWith(prefix)) {
161
+ console.log(`Deleting comment ${comment.id}`);
162
+ await github.rest.issues.deleteComment({
163
+ owner: context.repo.owner,
164
+ repo: context.repo.repo,
165
+ comment_id: comment.id,
166
+ });
167
+ }
168
+ }
169
+
148
170
await github.rest.issues.createComment({
149
171
owner: context.repo.owner,
150
172
repo: context.repo.repo,
151
- issue_number: process.env.PR_NUMBER,
152
- body: `Azure Static Web Apps: Your stage site is ready! Visit it here: ${process.env.SITE_URL}`
173
+ issue_number: + process.env.PR_NUMBER,
174
+ body: `${prefix} Visit it here: ${process.env.SITE_URL}`
153
175
});
0 commit comments