Meta Actions #8912
This file contains 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
--- | |
jobs: | |
cleanup-actions: | |
permissions: | |
actions: write | |
runs-on: ubuntu-22.04 | |
steps: | |
- env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
REPO: ${{ github.repository }} | |
name: Cleanup | |
run: > | |
set -o pipefail; | |
gh api "repos/${REPO}/actions/runs" --paginate -q ' | |
.workflow_runs[] | | |
select( | |
(.run_started_at | fromdate) < (now - 60 * 60 * 24) and | |
.conclusion != null and | |
( | |
.head_branch != null or | |
(.name | startswith("PR #")) or | |
(.pull_requests[0].head.ref // "" | length > 0) | |
) and | |
.status != "in_progress" | |
) | | |
select( | |
(.run_started_at | fromdate) < (now - 60 * 60 * 24 * 60) or | |
(.head_branch != "stable" and .conclusion == "cancelled") or | |
( | |
(.run_started_at | fromdate) < (now - 60 * 60 * 24 * 7) and | |
( | |
.head_branch != "stable" or | |
(.name | startswith("PR #")) or | |
(.pull_requests[0].head.ref // "" | length > 0) | |
) | |
) or ( | |
(.path | startswith(".github/workflows/actions")) and | |
(.run_started_at | fromdate) < (now - 60 * 60 * 24 * 2) | |
) or ( | |
(.run_started_at | fromdate) < (now - 60 * 60 * 24 * 3) and | |
.head_branch != null and | |
( | |
(.head_branch == "requirements-txt") or | |
(.head_branch == "utf8-generate-grammar") or | |
(.head_branch | startswith("corpus-")) or | |
(.head_branch | startswith("dependabot/")) or | |
(.head_branch | startswith("pin-0.")) | |
) | |
) | |
) | | |
{url} | |
' | | |
jq --join-output --slurp 'map(.url) | join("\u0000")' | | |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --null --verbose -- | |
gh api -X DELETE | |
cleanup-packages: | |
permissions: | |
packages: write | |
runs-on: ubuntu-22.04 | |
steps: | |
- env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.repository_owner }} | |
name: Cleanup | |
run: > | |
set -o pipefail; | |
gh api "users/${OWNER}/packages/container/chimera/versions" --paginate -q ' | |
.[] | | |
select( | |
(.metadata.container.tags | map(test("^[A-Za-z0-9]+$")) | all) and | |
(.metadata.container.tags | length > 0) and | |
(.updated_at | fromdate) < (now - 60 * 60 * 24 * 5) | |
) | | |
{url} | |
' | | |
jq --join-output --slurp 'map(.url) | join("\u0000")' | | |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --null --verbose -- | |
gh api -X DELETE | |
rerun-actions: | |
permissions: | |
actions: write | |
runs-on: ubuntu-22.04 | |
steps: | |
- env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
REPO: ${{ github.repository }} | |
RUN_ID: ${{ github.run_id }} | |
name: Rerun | |
run: > | |
set -o pipefail; | |
set -ex; | |
gh api "repos/${REPO}/actions/runs" --paginate -q ' | |
.workflow_runs[] | | |
select( | |
.head_branch == "stable" and | |
.conclusion == null and | |
.path == ".github/workflows/actions.yml" | |
) | | |
{cancel_url, id} | |
' | | |
jq --argjson run_id "${RUN_ID}" --join-output --slurp ' | |
map(select(.id < $run_id) | .cancel_url) | | |
join("\u0000") | |
' | | |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --null --verbose -- | |
gh api -X POST || true; | |
job_names="$(gh api "repos/${REPO}/actions/runs" --paginate -q ' | |
.workflow_runs[] | | |
select( | |
(.run_started_at | fromdate) > (now - 60 * 60 * 24 * 14) and | |
.head_branch == "stable" and | |
.conclusion == "cancelled" | |
) | | |
{path} | |
' | | |
jq --compact-output --slurp 'map(.path) | sort | unique')"; | |
while gh api "repos/${REPO}/actions/runs" --paginate -q ' | |
.workflow_runs[] | | |
select( | |
.head_branch == "stable" and | |
.conclusion == null | |
) | | |
{id, path, url} | |
' | | |
jq | |
--argjson run_id "${RUN_ID}" | |
--argjson job_names "${job_names}" | |
--exit-status --slurp ' | |
debug | | |
map(select(.id != $run_id and ([.path] | inside($job_names)))) | | |
length > 0 | |
' >/dev/null; do | |
sleep 60; | |
done; | |
gh api "repos/${REPO}/actions/runs" --paginate -q ' | |
.workflow_runs[] | | |
select( | |
(.run_started_at | fromdate) > (now - 60 * 60 * 24 * 14) and | |
.head_branch == "stable" and | |
.conclusion == "cancelled" | |
) | | |
{path, rerun_url, run_started_at} | |
' | | |
jq --join-output --slurp ' | |
group_by(.path) | | |
map(sort_by(.run_started_at) | last | .rerun_url) | | |
join("\u0000") | |
' | | |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --null --verbose -- | |
gh api -X POST | |
name: Meta Actions | |
# yamllint disable-line rule:truthy | |
on: | |
push: | |
branches: | |
- stable | |
paths: | |
- .github/workflows/actions.yml | |
schedule: | |
- cron: 59 * * * * | |
workflow_dispatch: ~ |