-
Notifications
You must be signed in to change notification settings - Fork 0
26 lines (22 loc) · 1006 Bytes
/
cleanup.yml
File metadata and controls
26 lines (22 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
name: Cleanup
on:
schedule:
- cron: '0 * * * *'
workflow_dispatch:
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Cleanup specific workflow
run: |
# 获取特定工作流的ID
WORKFLOW_PATH=".github/workflows/detect.yml"
WORKFLOW_ID=$(gh api repos/${{ github.repository }}/actions/workflows --jq ".workflows[] | select(.path == \"$WORKFLOW_PATH\") | .id")
MAX_PARALLEL=2 # 根据API限制调整并行度
gh api "repos/${{ github.repository }}/actions/workflows/$WORKFLOW_ID/runs?per_page=100" \
--jq ".workflow_runs[] | select(.conclusion == \"cancelled\") | .id" \
| xargs -P $MAX_PARALLEL -I {} bash -c '
gh api repos/${{ github.repository }}/actions/runs/{} -X DELETE --silent
'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}