Cleanup #79
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }} |