批量删除全部github action workflow

#!/bin/bash

# Replace with your own values
TOKEN="YOUR_TOKEN"
OWNER="your_username"
REPO="your_repository"

# Get all workflow runs for the repository
runs=$(curl -s -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github.v3+json" \
  "https://api.github.com/repos/$OWNER/$REPO/actions/runs")

# Parse each run ID and delete it
for run_id in $(echo "$runs" | jq -r '.workflow_runs[].id'); do
  echo "Deleting run: $run_id"
  curl -X DELETE -s -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github.v3+json" \
    "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id"
done

api 参考
https://docs.github.com/zh/rest/actions/workflow-runs?apiVersion=2022-11-28#delete-a-workflow-run

第二版

#!/bin/bash

# Replace with your own values
TOKEN="123"
OWNER="123"
REPO="123"
WAIT_TIME=2 # 等待时间(秒)
MAX_TRIES=100  #有几页就填几

# Attempt to fetch runs multiple times
for ((tries = 0; tries < MAX_TRIES; tries++)); do
    echo "Attempt $((tries + 1)) to fetch runs"
    runs=$(curl -s -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github.v3+json" \
        "https://api.github.com/repos/$OWNER/$REPO/actions/runs")

    # If runs are successfully fetched, break the loop and proceed to delete

    # Parse each run ID and delete it
    for run_id in $(echo "$runs" | jq -r '.workflow_runs[].id'); do
        echo "Deleting run: $run_id"
        curl -X DELETE -s -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github.v3+json" \
            "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$run_id"
    done
    sleep $WAIT_TIME
done

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据