@@ -7,6 +7,7 @@ name: Deploy SWA to Staging Environment
77
88on :
99 pull_request :
10+ types : [opened, synchronize, reopened, closed]
1011 branches : [main]
1112 push :
1213 branches : [staging]
@@ -25,6 +26,7 @@ permissions:
2526
2627jobs :
2728 build-and-test-frontend :
29+ if : github.event.action != 'closed'
2830 runs-on : ubuntu-latest
2931
3032 steps :
6062
6163 deploy-swa-staging :
6264 needs : build-and-test-frontend
65+ if : github.event.action != 'closed'
6366 runs-on : ubuntu-latest
6467 environment : staging
6568
@@ -110,3 +113,35 @@ jobs:
110113 echo "### SWA Staging Environment" >> $GITHUB_STEP_SUMMARY
111114 echo "Staging URL: https://${HOSTNAME}" >> $GITHUB_STEP_SUMMARY
112115 echo "Custom domain: https://sudoku-beta.xenobiasoft.com" >> $GITHUB_STEP_SUMMARY
116+
117+ delete-staging-environment :
118+ if : github.event_name == 'pull_request' && github.event.action == 'closed'
119+ runs-on : ubuntu-latest
120+ environment : staging
121+
122+ steps :
123+ - name : Azure Login
124+ uses : azure/login@v2
125+ with :
126+ creds : ${{ secrets.AZURE_CREDENTIALS }}
127+
128+ - name : Get SWA deployment token
129+ id : swa-token
130+ run : |
131+ TOKEN=$(az staticwebapp secrets list \
132+ --name ${{ env.AZURE_SWA_NAME }} \
133+ --query "properties.apiKey" \
134+ --output tsv)
135+ if [ -z "$TOKEN" ]; then
136+ echo "ERROR: Failed to retrieve SWA deployment token for ${{ env.AZURE_SWA_NAME }}" >&2
137+ exit 1
138+ fi
139+ echo "::add-mask::$TOKEN"
140+ echo "token=$TOKEN" >> $GITHUB_OUTPUT
141+
142+ - name : Delete SWA staging environment
143+ uses : Azure/static-web-apps-deploy@v1
144+ with :
145+ azure_static_web_apps_api_token : ${{ steps.swa-token.outputs.token }}
146+ action : " close"
147+ deployment_environment : ${{ env.SWA_DEPLOYMENT_ENV }}
0 commit comments