Skip to content

Improve delete method #1

@fnperez

Description

@fnperez

This is my approach for organizations, it improves a little the jq usage.


export $(grep -v '^#' .env | xargs)

ORG="***"
TOKEN="${GITHUB_TOKEN}"  # Use a .env variable to avoid exposing it

if [ -z "$TOKEN" ]; then
    echo "Error: Token not found. Make sure to export it with 'export GITHUB_TOKEN=tu-token' or add it to an .env file"
    exit 1
fi

# Get offline runners
RUNNER_LIST=$(curl -s -H "Authorization: token ${TOKEN}" -H "Accept: application/vnd.github+json" \
  https://api.github.com/orgs/${ORG}/actions/runners | jq '[.runners[] | select(.status == "offline") | {id: .id}]')

# Check if there are offline runners
if [ "$(echo "$RUNNER_LIST" | jq 'length')" -eq 0 ]; then
    echo "No hay runners offline para eliminar."
    exit 0
fi

# Remove offline runners
for id in $(echo "$RUNNER_LIST" | jq -r '.[].id'); do
    echo "Removing runner with ID: $id"
    curl -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: token ${TOKEN}" \
        https://api.github.com/orgs/${ORG}/actions/runners/$id
done```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions