name: VPS manipulation on: workflow_dispatch: # push: jobs: Prepare: name: Prepare runs-on: ubuntu-latest env: HCLOUD_TOKEN: ${{ secrets.HETZNER_ONE }} GH_TOKEN: ${{ secrets.TEST }} steps: - name: Install SSH key for storage uses: shimataro/ssh-key-action@v2 with: key: ${{ secrets.KEY_TORRENTS }} known_hosts: ${{ secrets.KNOWN_HOSTS_TORRENTS }} if_key_exists: replace - name: Install Homebrew run: | sudo apt-get -y install wamerican /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 eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" brew install hcloud # generate machine MACHINE_NAME=$(shuf -n1 /usr/share/dict/american-english | sed "s/[^[:alnum:]-]//g" | sed 's/./\L&/g') hcloud server create --name ${MACHINE_NAME} --image ubuntu-22.04 --type cax11 --ssh-key TORRENT sleep 30 hcloud server list - name: Show machines run: | eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" COMMAND="git clone https://github.com/armbian/scripts; cd scripts/generate-runners; ./deploy.sh" hcloud server list SERVERS=($(hcloud server list --output columns=ipv4 | tail -1)) for i in $SERVERS do ssh-keygen -f "$HOME/.ssh/known_hosts" -R "$i" ssh -o StrictHostKeyChecking=no root@$i "export GH_TOKEN=${{ env.GH_TOKEN }}; $COMMAND" done - name: Delete runners run: | RUNNERS=$(gh api \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ /repos/${{ github.repository_owner }}/os/actions/runners \ | jq -r '.runners[] | .id' | xargs -n2 -d'\n' | sed -e 's/ /,/g') 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