Skip to content

Teardown VM and remove self-hosted runner #73

Teardown VM and remove self-hosted runner

Teardown VM and remove self-hosted runner #73

name: Teardown VM and remove self-hosted runner
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 3"
jobs:
teardown-aws-vm:
runs-on: ubuntu-latest
env:
AWS_RUNNER_NAME: stellar-aws
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials using EASE lab account
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: us-west-1
- name: Get public IP address
run: echo ip=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${{ env.AWS_RUNNER_NAME }}" --query "Reservations[*].Instances[*].PublicIpAddress" --output text) >> $GITHUB_OUTPUT
id: get-ip
# - name: Check runner health
# run: |
# ssh -o StrictHostKeyChecking=no ubuntu@${{ steps.get-ip.outputs.ip }} "
# echo 'Checking Instance connection and space/usage'
# df -h
# free -m
# uptime
# "
- name: Get self-hosted runner ID
id: get-runner-id
env:
GH_TOKEN: ${{ secrets.DEPLOY_SELF_HOSTED_RUNNER_TOKEN }}
run: |
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/vhive-serverless/STeLLAR/actions/runners \
| echo id=$(jq '.runners[] | select(.name == "${{ env.AWS_RUNNER_NAME }}") | .id') > $GITHUB_OUTPUT
response=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/vhive-serverless/STeLLAR/actions/runners)
echo "$response"
- name: Remove self-hosted runner
env:
GH_TOKEN: ${{ secrets.DEPLOY_SELF_HOSTED_RUNNER_TOKEN }}
run: |
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/vhive-serverless/STeLLAR/actions/runners/${{ steps.get-runner-id.outputs.id }}
# - name: Get AWS EC2 instance ID
# run: |
# echo id=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${{ env.AWS_RUNNER_NAME }}" --query "Reservations[*].Instances[*].InstanceId" --output text) > $GITHUB_OUTPUT
# echo "$id"
# id: get-instance-id
# - name: Terminate AWS EC2 instance
# run: |
# aws ec2 terminate-instances --instance-ids ${{ steps.get-instance-id.outputs.id }}
# teardown-cloudflare-vm:
# runs-on: ubuntu-latest
# env:
# CLOUDFLARE_RUNNER_NAME: stellar-continuous-cloudflare
# steps:
# - uses: actions/checkout@v4
# - name: Configure AWS credentials using EASE lab account
# uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
# aws-region: us-east-2
# - name: Get self-hosted runner ID
# id: get-runner-id
# env:
# GH_TOKEN: ${{ secrets.DEPLOY_SELF_HOSTED_RUNNER_TOKEN }}
# run: |
# gh api \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# /repos/vhive-serverless/STeLLAR/actions/runners \
# | echo id=$(jq '.runners[] | select(.name == "${{ env.CLOUDFLARE_RUNNER_NAME }}") | .id') > $GITHUB_OUTPUT
# - name: Remove self-hosted runner
# env:
# GH_TOKEN: ${{ secrets.DEPLOY_SELF_HOSTED_RUNNER_TOKEN }}
# run: |
# gh api \
# --method DELETE \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# /repos/vhive-serverless/STeLLAR/actions/runners/${{ steps.get-runner-id.outputs.id }}
# - name: Get AWS EC2 instance ID
# run: |
# echo id=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${{ env.CLOUDFLARE_RUNNER_NAME }}" --query "Reservations[*].Instances[*].InstanceId" --output text) > $GITHUB_OUTPUT
# echo "$id"
# id: get-instance-id
# - name: Terminate AWS EC2 instance
# run: |
# aws ec2 terminate-instances --instance-ids ${{ steps.get-instance-id.outputs.id }}
# teardown-azure-vm:
# runs-on: ubuntu-latest
# permissions: write-all
# steps:
# - uses: actions/checkout@v4
# - name: Setup Azure CLI
# uses: azure/login@v2
# with:
# creds: ${{ secrets.AZURE_CREDENTIALS}}
# - name: Get self-hosted runner ID
# id: get-runner-id
# env:
# GH_TOKEN: ${{ secrets.DEPLOY_SELF_HOSTED_RUNNER_TOKEN }}
# run: |
# gh api \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# /repos/vhive-serverless/STeLLAR/actions/runners \
# | echo id=$(jq '.runners[] | select(.name == "stellar-continuous-azure") | .id') > $GITHUB_OUTPUT
# # | echo id=$(jq '.runners[] | select(.name == "stellar-continuous-azure-TEST") | .id') > $GITHUB_OUTPUT
# - name: Remove self-hosted runner
# env:
# GH_TOKEN: ${{ secrets.DEPLOY_SELF_HOSTED_RUNNER_TOKEN }}
# run: |
# gh api \
# --method DELETE \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# /repos/vhive-serverless/STeLLAR/actions/runners/${{ steps.get-runner-id.outputs.id }}
# - name: Delete Azure resource group
# run: az group delete --resource-group github-actions-runners --yes
# teardown-gcr-vm:
# runs-on: ubuntu-latest
# permissions: write-all
# steps:
# - uses: actions/checkout@v4
# - id: auth
# name: Configure GCR credentials
# uses: google-github-actions/auth@v1
# with:
# credentials_json: ${{ secrets.GCR_CREDENTIALS }}
# - name: Set up gcloud
# uses: google-github-actions/setup-gcloud@v1
# with:
# version: ">= 363.0.0"
# - name: Get self-hosted runner ID
# id: get-runner-id
# env:
# GH_TOKEN: ${{ secrets.DEPLOY_SELF_HOSTED_RUNNER_TOKEN }}
# run: |
# gh api \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# /repos/vhive-serverless/STeLLAR/actions/runners \
# | echo id=$(jq '.runners[] | select(.name == "stellar-continuous-gcr") | .id') > $GITHUB_OUTPUT
# response=$(gh api \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# /repos/vhive-serverless/STeLLAR/actions/runners)
# echo "$response"
# - name: Remove self-hosted runner
# env:
# GH_TOKEN: ${{ secrets.DEPLOY_SELF_HOSTED_RUNNER_TOKEN }}
# run: |
# gh api \
# --method DELETE \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# /repos/vhive-serverless/STeLLAR/actions/runners/${{ steps.get-runner-id.outputs.id }}
# - name: Delete GCloud Compute Engine VM
# run: gcloud compute instances delete github-actions-runner-gcr --zone=us-west1-a