diff --git a/hetzner_off/action.yml b/hetzner_off/action.yml index b95596a..187eeb5 100644 --- a/hetzner_off/action.yml +++ b/hetzner_off/action.yml @@ -51,4 +51,42 @@ runs: hcloud server delete $(hcloud server list --output columns=id,name | grep ${machinename} | cut -d" " -f1) i=$(( i + 1 )) [[ $i == ${{ inputs.machine-count }} ]] && break - done \ No newline at end of file + done + + - name: Remove runners + env: + GH_TOKEN: ${{ inputs.github_token }} + shell: bash + run: | + + # for some reason last added doesn't show up + #RUNNERS=$(gh api \ + #-H "Accept: application/vnd.github+json" \ + #-H "X-GitHub-Api-Version: 2022-11-28" \ + #"/orgs/${{ github.repository_owner }}/actions/runners?per_page=1000" | \ + #jq -r '.runners[] | select(.labels[].name=="temp")' | jq '.id') + + # get all runners that have label "temp" + RUNNERS=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/repos/${{ github.repository_owner }}/os/actions/runners?per_page=1000" | \ + jq -r '.runners[] | select(.labels[].name=="temp")' | jq '.id') + + # remove them + # while IFS= read -r id; do + #gh api \ + #--method DELETE \ + #-H "Accept: application/vnd.github+json" \ + #-H "X-GitHub-Api-Version: 2022-11-28" \ + #/orgs/${{ github.repository_owner }}/actions/runners/${id} + #done <<< $RUNNERS + + # remove them + while IFS= read -r id; do + gh api \ + --method DELETE \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${{ github.repository_owner }}/os/actions/runners/${id} + done <<< $RUNNERS \ No newline at end of file diff --git a/hetzner_on/action.yml b/hetzner_on/action.yml index 088e3b6..1ffb870 100644 --- a/hetzner_on/action.yml +++ b/hetzner_on/action.yml @@ -51,8 +51,18 @@ runs: machinenames=("Faerie" "November" "Raven" "Hammer" "Foxtrot" "Papa" "Chimera" "Panther") for machinename in "${machinenames[@]}" do + hcloud server delete $(hcloud server list --output columns=id,name | grep ${machinename} | cut -d" " -f1) || true hcloud server create --name ${machinename} --image ubuntu-22.04 --type ${{ inputs.machine-type }} --ssh-key TORRENT - sleep 30 + i=$(( i + 1 )) + [[ $i == ${{ inputs.machine-count }} ]] && break + done + + # make sure all are up + sleep 20 + + i=0 + for machinename in "${machinenames[@]}" + do IP=$(hcloud server list --output columns=ipv4,name | grep ${machinename} | cut -d" " -f1) ssh-keygen -f "$HOME/.ssh/known_hosts" -R "${IP}" || true ssh -o StrictHostKeyChecking=no root@${IP} "export STOP=${{ inputs.runners-count}} NAME=${machinename} GH_TOKEN=${{ env.GH_TOKEN }}; $COMMAND"