Repository navigation
73 lines (65 loc) · 2.47 KB
/
Copy pathclose-preview.yml
File metadata and controls
73 lines (65 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Close preview environment
on:
workflow_dispatch:
inputs:
pr:
required: true
type: string
description: PR number
pull_request_target:
types: [closed]
permissions:
id-token: write
jobs:
close:
runs-on: ubuntu-latest
if: github.repository == 'microsoft/TypeScript-Website'
environment:
name: azure-preview
deployment: false
env:
AZURE_STATIC_WEB_APP_NAME: ${{ vars.AZURE_STATIC_WEB_APP_NAME }}
AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
steps:
- name: Log in to Azure
uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Close preview environment
env:
PR_NUMBER: ${{ inputs.pr || github.event.pull_request.number }}
run: |
set -euo pipefail
: "${AZURE_STATIC_WEB_APP_NAME:?Missing AZURE_STATIC_WEB_APP_NAME environment variable}"
: "${AZURE_RESOURCE_GROUP:?Missing AZURE_RESOURCE_GROUP environment variable}"
if [[ ! "$PR_NUMBER" =~ ^[1-9][0-9]*$ ]]; then
echo "::error::Invalid preview PR number"
exit 1
fi
get_preview_environment() {
az staticwebapp environment list \
--name "$AZURE_STATIC_WEB_APP_NAME" \
--resource-group "$AZURE_RESOURCE_GROUP" \
--query "[?name=='$PR_NUMBER'].name" --output tsv
}
environment="$(get_preview_environment)"
if [[ -z "$environment" ]]; then
echo "No preview environment exists for PR $PR_NUMBER"
exit 0
fi
# Avoid Azure CLI's subscription-scoped long-running-operation polling.
resource_id="/subscriptions/{subscriptionId}/resourceGroups/$AZURE_RESOURCE_GROUP"
resource_id+="/providers/Microsoft.Web/staticSites/$AZURE_STATIC_WEB_APP_NAME"
az rest --method delete --url "$resource_id/builds/$PR_NUMBER?api-version=2024-11-01"
for _ in {1..30}; do
environment="$(get_preview_environment)"
if [[ -z "$environment" ]]; then
echo "Deleted preview environment for PR $PR_NUMBER"
exit 0
fi
sleep 5
done
echo "::error::Timed out waiting for preview $PR_NUMBER to be deleted"
exit 1