Files
actions/hetzner/action.yml
2024-09-26 08:29:21 +02:00

124 lines
4.1 KiB
YAML

name: "Enable Hetzner VMs"
author: "Igor Pecovnik"
inputs:
action-type:
required: true
machine-type:
required: true
machine-id:
required: false
machine-count:
required: true
runners-count:
required: true
key:
required: true
known_hosts:
required: true
hetzner_id:
required: true
github_token:
required: true
concurrency:
cancel-in-progress: false
runs:
using: "composite"
steps:
- name: Install SSH key for storage
if: ${{ github.repository_owner == 'Armbian' }}
uses: shimataro/ssh-key-action@v2
with:
key: ${{ inputs.key }}
known_hosts: ${{ inputs.known_hosts }}
if_key_exists: replace
- name: Install Homebrew
if: ${{ github.repository_owner == 'Armbian' }}
shell: bash
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> ${HOME}/.bash_profile
- name: Install CLI for Hetzner Cloud
if: ${{ github.repository_owner == 'Armbian' }}
shell: bash
env:
HCLOUD_TOKEN: ${{ inputs.hetzner_id }}
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install hcloud
hcloud server list
- name: "Kill runners"
if: ${{ github.repository_owner == 'Armbian' && inputs.action-type == 'enable' }}
env:
HCLOUD_TOKEN: ${{ inputs.hetzner_id }}
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS: 3650
shell: bash
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
machinenames=("Faerie" "November" "Raven" "Hammer" "Foxtrot" "Papa" "Chimera" "Panther")
machinename="${machinenames[${{ inputs.machine-id }}]}"
machinenameid=$(hcloud server list --output columns=id,name | grep ${machinename} | cut -d" " -f1 || true)
[[ -n "${machinenameid}" ]] && hcloud server delete "${machinenameid}" || true
- name: "Kill runners"
if: ${{ github.repository_owner == 'Armbian' && inputs.action-type == 'disable' }}
env:
HCLOUD_TOKEN: ${{ inputs.hetzner_id }}
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS: 3650
shell: bash
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# we will set fixed number and fixed machine names
machinenames=("Faerie" "November" "Raven" "Hammer" "Foxtrot" "Papa" "Chimera" "Panther")
for machinename in "${machinenames[@]}"
do
machinenameid=$(hcloud server list --output columns=id,name | grep ${machinename} | cut -d" " -f1 || true)
[[ -n "${machinenameid}" ]] && hcloud server delete "${machinenameid}" || true
done
- name: "Deploy runners"
if: ${{ inputs.action-type == 'enable' }}
env:
HCLOUD_TOKEN: ${{ inputs.hetzner_id }}
GH_TOKEN: ${{ inputs.github_token }}
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS: 3650
shell: bash
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
machinenames=("Faerie" "November" "Raven" "Hammer" "Foxtrot" "Papa" "Chimera" "Panther")
machinename="${machinenames[${{ inputs.machine-id }}]}"
echo -e '#!/bin/bash\n\
export STOP=${{ inputs.runners-count}} NAME=${machinename} GH_TOKEN=${{ env.GH_TOKEN }}\n\
git clone https://github.com/armbian/scripts\ncd scripts/generate-runners\n\
./deploy.sh" | \
hcloud server create --name ${machinename} --image ubuntu-22.04 --type ${{ inputs.machine-type }} --ssh-key TORRENT --user-data-from-file -
- name: Remove runners
if: ${{ inputs.action-type == 'disable' }}
env:
GH_TOKEN: ${{ inputs.github_token }}
shell: bash
run: |
# make sure all are down
sleep 60
RUNNERS=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/armbian/os/actions/runners?per_page=1000" | \
jq -r '.runners[] | select(.labels[].name=="temp")' | jq '.id')