-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (95 loc) · 3.33 KB
/
delete.yml
File metadata and controls
107 lines (95 loc) · 3.33 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: delete
on:
workflow_call:
inputs:
RESOURCE_GROUP_NAME:
type: string
VM_NAME:
type: string
VM_USERNAME:
type: string
SSH_KEY_BASENAME:
type: string
required: false
default: "id_rsa"
secrets:
ARM_CLIENT_ID:
required: true
ARM_CLIENT_SECRET:
required: true
ARM_TENANT_ID:
required: true
ARM_SUBSCRIPTION_ID:
required: true
GH_TOKEN:
description: Token with admin repo privilege
required: false
GH_APP_ID:
description: App id with admin privilege
required: false
GH_PRIVATE_KEY:
description: App private key with admin privilege
required: false
# permissions:
# id-token: write
# contents: read
jobs:
delete:
runs-on: ubuntu-latest
steps:
- name: Test secrets 1
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GH_APP_ID: ${{ secrets.GH_APP_ID }}
GH_PRIVATE_KEY: ${{ secrets.GH_PRIVATE_KEY }}
if: ${{ env.GH_TOKEN == '' && (env.GH_APP_ID == '' || env.GH_PRIVATE_KEY == '') }}
run: echo Error [GH_TOKEN] or [GH_APP_ID, GH_PRIVATE_KEY] are not defined >> /dev/stderr; false
- name: Test secrets 2
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GH_APP_ID: ${{ secrets.GH_APP_ID }}
GH_PRIVATE_KEY: ${{ secrets.GH_PRIVATE_KEY }}
if: ${{ env.GH_TOKEN != '' && ( env.GH_APP_ID != '' || env.GH_PRIVATE_KEY != '' ) }}
run: echo Error [GH_TOKEN] and [GH_APP_ID, GH_PRIVATE_KEY] are defined >> /dev/stderr; false
- name: Checkout
uses: actions/checkout@v4
with:
repository: Jason-Clark-FG/azure-github-runner
ref: main
- name: Download ssh key
uses: actions/download-artifact@v4
with:
name: ssh-${{ inputs.SSH_KEY_BASENAME }}
path: ~/.ssh
- name: Set ssh key permission
run: chmod 400 ~/.ssh/${{ inputs.SSH_KEY_BASENAME }}
- name: login to azure
uses: Azure/login@v2
with:
creds: '{"clientId":"${{ secrets.ARM_CLIENT_ID }}","clientSecret":"${{ secrets.ARM_CLIENT_SECRET }}","subscriptionId":"${{ secrets.ARM_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.ARM_TENANT_ID }}"}'
- name: Run script with gh token
if: ${{ env.GH_TOKEN != '' }}
env:
GITHUB_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
RUN_ID: ${{ github.run_id }}
RESOURCE_GROUP_NAME: ${{ inputs.RESOURCE_GROUP_NAME }}
VM_NAME: ${{ inputs.VM_NAME }}
VM_USERNAME: ${{ inputs.VM_USERNAME }}
run: ./main.sh --destroy
- uses: actions/create-github-app-token@v1
id: app-token
if: ${{ failure() && env.GH_TOKEN == '' }}
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_PRIVATE_KEY }}
- name: Run script with appid & pkey
if: ${{ steps.app-token.outcome == 'success' }}
env:
GITHUB_REPO: ${{ github.repository }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
RUN_ID: ${{ github.run_id }}
RESOURCE_GROUP_NAME: ${{ inputs.RESOURCE_GROUP_NAME }}
VM_NAME: ${{ inputs.VM_NAME }}
VM_USERNAME: ${{ inputs.VM_USERNAME }}
run: ./main.sh --destroy