forked from armbian/os
-
-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (126 loc) · 4.09 KB
/
enable-hetzner-runners.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Enable Hetzner Runners (admin)
on:
schedule:
- cron: '10 8 * * *'
workflow_dispatch:
inputs:
period:
type: choice
description: 'Availability time'
options:
- 50m
- 110m
- 170m
- 230m
default: 110m
machine:
type: choice
description: 'Machine type'
options:
- cax21
- cax31
- cax41
default: 'cax31'
machine_count:
type: choice
description: 'Number of machines'
options:
- "1"
- "2"
- "4"
- "8"
default: '4'
runners_count:
type: choice
description: 'Runners per machine'
options:
- "1"
- "2"
- "4"
- "8"
- "16"
default: '4'
concurrency:
group: hetzner-runner
cancel-in-progress: true
jobs:
Teamcheck:
permissions:
actions: write
name: "Check ORG Team Membership"
if: ${{ github.repository_owner == 'Armbian' }}
runs-on: ubuntu-latest
steps:
- name: "Check membership"
uses: armbian/actions/team-check@main
with:
ORG_MEMBERS: ${{ secrets.ORG_MEMBERS }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TEAM: "Release manager"
Prepare:
needs: Teamcheck
name: "Enable cloud runners"
outputs:
matrix: ${{steps.machine-number.outputs.matrix}}
runs-on: ubuntu-latest
steps:
- name: "Delete dangling cloud runners"
run: |
for runner in $(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/armbian/os/actions/runners | jq -r '.runners[] | .id'); do
gh api --method DELETE -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/armbian/os/actions/runners/$runner
done
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: "Enable cloud runners"
id: machine-number
run: |
echo "matrix=$(for x in $(seq -w 0 $(( ${{ github.event.inputs.machine_count || 4 }} - 1 ))); do echo ${x}; done|jq -cnR '[inputs | select(length>0)]' | jq -c)" >> $GITHUB_OUTPUT
Enable:
name: "Cloud VM"
runs-on: ubuntu-latest
needs: Prepare
if: ${{ needs.Prepare.outputs.matrix != '[]' && needs.Prepare.outputs.matrix != '' }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
node: ${{fromJson(needs.Prepare.outputs.matrix)}}
steps:
- name: Enable Hetzner Virtual Machines
if: ${{ github.repository_owner == 'Armbian' }}
uses: armbian/actions/hetzner@1.1
with:
action-type: enable
machine-type: "${{ github.event.inputs.machine || 'cax31' }}"
machine-id: "${{ matrix.node }}"
runners-count: "${{ github.event.inputs.runners_count || '4' }}"
machine-count: "${{ github.event.inputs.machine_count || '4' }}"
key: ${{ secrets.KEY_TORRENTS }}
known_hosts: ${{ secrets.KNOWN_HOSTS_TORRENTS }}
hetzner_id: ${{ secrets.HETZNER_ONE }}
github_token: ${{ secrets.ACCESS_TOKEN }}
sleeping:
name: "Sleeping"
needs: Enable
runs-on: ubuntu-latest
steps:
- name: Sleeping "${{ github.event.inputs.period }}"
run: sleep "${{ github.event.inputs.period || '110m' }}"
stop:
#if: always()
name: "Disable cloud runners"
needs: sleeping
runs-on: ubuntu-latest
steps:
- name: Enable Hetzner Virtual Machines
if: ${{ always() && github.repository_owner == 'Armbian' }}
uses: armbian/actions/hetzner@1.1
with:
action-type: disable
machine-type: "${{ github.event.inputs.machine || 'cax21' }}"
runners-count: "${{ github.event.inputs.runners_count || '2' }}"
machine-count: "${{ github.event.inputs.machine_count || '2' }}"
key: ${{ secrets.KEY_TORRENTS }}
known_hosts: ${{ secrets.KNOWN_HOSTS_TORRENTS }}
hetzner_id: ${{ secrets.HETZNER_ONE }}
github_token: ${{ secrets.ACCESS_TOKEN }}