@@ -19,7 +19,6 @@ name: Deploy Static Site to Azure
1919# - "apps/my-static-app/**"
2020# To be sure that during a PR the preview will be triggered
2121
22-
2322on :
2423 workflow_call :
2524 inputs :
5958 type : string
6059 required : false
6160 default : " "
61+ outputs :
62+ bundle_name :
63+ description : The name of the bundle used for artifact storage
64+ value : ${{ jobs.build.outputs.bundle_name }}
6265
6366concurrency :
64- group : ${{ github.workflow }}-${{ github.ref }}-cd
67+ group : ${{ github.workflow }}-${{ github.ref }}-${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) && 'cd' || 'ci' }}
6568 cancel-in-progress : true
6669
6770env :
7174jobs :
7275 build :
7376 name : Build Artifact
74- runs-on : ubuntu-latest
77+ runs-on : ${{ inputs.use_labels && inputs.use_private_agent && (inputs.override_labels != '' && inputs.override_labels || inputs.environment) || inputs.use_private_agent && 'self-hosted' || 'ubuntu-latest' }}
78+ outputs :
79+ bundle_name : ${{ env.BUNDLE_NAME }}
7580
7681 steps :
7782 - name : Checkout
@@ -105,7 +110,7 @@ jobs:
105110 runs-on : ubuntu-latest
106111 needs : [build]
107112 if : ${{ !github.event.act }}
108- environment : ${{ inputs.environment }}-${{ github.event.action == 'closed' && 'cd' || 'ci' }}
113+ environment : ${{ inputs.environment }}-${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) && 'cd' || 'ci' }}
109114 permissions :
110115 id-token : write
111116 contents : read
@@ -142,20 +147,50 @@ jobs:
142147 RESOURCE_GROUP_NAME : ${{ inputs.resource_group_name }}
143148
144149 - name : Deploy Preview
150+ id : deploy_preview
145151 if : github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
146152 uses : Azure/static-web-apps-deploy@4d27395796ac319302594769cfe812bd207490b1 # v1
147153 with :
148154 azure_static_web_apps_api_token : ${{ steps.find_api_key.outputs.api_key }}
149155 repo_token : ${{ secrets.GITHUB_TOKEN }}
150156 action : " upload"
151157 app_location : " ./${{ env.OUTPUT_DIR }}"
158+ skip_app_build : true
159+
160+ - name : Delete old preview comments
161+ if : github.event_name == 'pull_request' && github.event.action != 'closed' && steps.deploy_preview.outcome == 'success'
162+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
163+ with :
164+ script : |
165+ const comments = await github.rest.issues.listComments({
166+ owner: context.repo.owner,
167+ repo: context.repo.repo,
168+ issue_number: context.issue.number,
169+ });
170+
171+ const botComments = comments.data.filter(comment =>
172+ comment.user.type === 'Bot' &&
173+ comment.body.includes('Azure Static Web Apps: Your stage site is ready!')
174+ );
175+
176+ // Keep only the most recent comment, delete all others
177+ if (botComments.length > 1) {
178+ const commentsToDelete = botComments.slice(0, -1);
179+ for (const comment of commentsToDelete) {
180+ await github.rest.issues.deleteComment({
181+ owner: context.repo.owner,
182+ repo: context.repo.repo,
183+ comment_id: comment.id,
184+ });
185+ }
186+ }
152187
153188 - name : Delete Preview and Deploy production
154189 if : github.event_name == 'pull_request' && github.event.action == 'closed'
155- uses : Azure/static-web-apps-deploy@v1
190+ uses : Azure/static-web-apps-deploy@4d27395796ac319302594769cfe812bd207490b1 # v1
156191 with :
157192 azure_static_web_apps_api_token : ${{ steps.find_api_key.outputs.api_key }}
158193 repo_token : ${{ secrets.GITHUB_TOKEN }}
159194 app_location : " ./${{ env.OUTPUT_DIR }}"
160195 action : " close"
161-
196+ skip_app_build : true
0 commit comments