-
Notifications
You must be signed in to change notification settings - Fork 18
61 lines (52 loc) · 1.87 KB
/
clear-resource-group.yml
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
name: Clear Resource Group
on:
workflow_dispatch:
schedule:
# Run every day at 4:30 AM (KST)
- cron: "30 19 * * *"
permissions:
contents: read
id-token: write
issues: write
pull-requests: write
jobs:
clear-resource-group:
name: "Clearing Resource Groups"
if: github.repository_owner == 'aliencube'
runs-on: ubuntu-latest
env:
AZURE_CLIENT_ID: ${{ vars.AZM_CLIENT_ID }}
AZURE_TENANT_ID: ${{ vars.AZM_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZM_SUBSCRIPTION_ID }}
AZURE_RESOURCE_GROUPS: ${{ vars.AZM_RESOURCE_GROUPS }}
AZURE_APP_NAME: ${{ vars.AZM_APP_NAME }}
PAU_ON_RESET_RESOURCE_GROUP_REQUEST_URL: ${{ secrets.PAU_ON_RESET_RESOURCE_GROUP_REQUEST_URL }}
PAU_API_KEY: ${{ secrets.PAU_API_KEY }}
steps:
- name: Azure login (Federated Credentials)
if: env.AZURE_CLIENT_ID != ''
uses: azure/login@v2
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: Delete all resource groups
shell: pwsh
run: |
$excludes = "${{ env.AZURE_RESOURCE_GROUPS }}" -split ','
$groups = az group list --query "[].name" | ConvertFrom-Json
$groups | ForEach-Object {
$name = $_
if ($excludes -notcontains $name) {
az group delete -g $name -y --no-wait
}
}
- name: Delete all apps
shell: pwsh
run: |
$apps = az ad app list --query "[?displayName != '${{ env.AZURE_APP_NAME }}'].{id: id, displayName:displayName, appId: appId}" | ConvertFrom-Json
$apps | ForEach-Object {
$id = $_.id
az ad app delete --id $id
}