Skip to content

Commit

Permalink
Switch meta actions to vendored tools image.
Browse files Browse the repository at this point in the history
  • Loading branch information
asakatida committed May 6, 2024
1 parent ea98bc5 commit 60b9997
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 156 deletions.
90 changes: 49 additions & 41 deletions .github/workflows/actions-branch-delete.yml
Expand Up @@ -10,42 +10,46 @@ jobs:
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(
.conclusion == null and
.path != ".github/workflows/actions-branch-delete.yml" and
.head_branch != "stable"
) |
{head_branch, pull_requests, cancel_url}
' |
jq --arg head_branch "${BRANCH}"
'select(
.head_branch == $head_branch or
(.pull_requests[0].head.ref // "") == $head_branch
) | .cancel_url' |
jq --join-output --slurp 'join("\u0000")' |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --null --verbose --
gh api -X POST || true;
gh api "repos/${REPO}/actions/runs" --paginate -q '
.workflow_runs[] |
select(
.conclusion != null and
.status != "in_progress" and
.head_branch != "stable"
) |
{head_branch, pull_requests, url}
' |
jq --arg head_branch "${BRANCH}"
'select(
.head_branch == $head_branch or
(.pull_requests[0].head.ref // "") == $head_branch
) | .url' |
jq --join-output --slurp 'join("\u0000")' |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --null --verbose --
gh api -X DELETE
uses: ./
with:
# yamllint disable rule:line-length
run: >
set -o pipefail;
gh api "repos/${REPO}/actions/runs" --paginate -q '
.workflow_runs[] |
select(
.conclusion == null and
.path != ".github/workflows/actions-branch-delete.yml" and
.head_branch != "stable"
) |
{head_branch, pull_requests, cancel_url}
' |
jq --arg head_branch "${BRANCH}"
'select(
.head_branch == $head_branch or
(.pull_requests[0].head.ref // "") == $head_branch
) | .cancel_url' |
jq --join-output --slurp 'join("\u0000")' |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --null --verbose --
gh api -X POST || true;
gh api "repos/${REPO}/actions/runs" --paginate -q '
.workflow_runs[] |
select(
.conclusion != null and
.status != "in_progress" and
.head_branch != "stable"
) |
{head_branch, pull_requests, url}
' |
jq --arg head_branch "${BRANCH}"
'select(
.head_branch == $head_branch or
(.pull_requests[0].head.ref // "") == $head_branch
) | .url' |
jq --join-output --slurp 'join("\u0000")' |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --null --verbose --
gh api -X DELETE
# yamllint enable rule:line-length
cleanup-cache:
runs-on: ubuntu-latest
steps:
Expand All @@ -57,11 +61,15 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
name: Cleanup
run: >
gh extension install actions/gh-actions-cache;
gh actions-cache list -R "${REPO}" -B "${BRANCH}" | cut -f 1 |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --verbose --
gh actions-cache delete -R "${REPO}" -B "${BRANCH}" --confirm
uses: ./
with:
# yamllint disable rule:line-length
run: >
gh extension install actions/gh-actions-cache;
gh actions-cache list -R "${REPO}" -B "${BRANCH}" | cut -f 1 |
xargs --max-args=1 --max-procs=2 --no-run-if-empty --verbose --
gh actions-cache delete -R "${REPO}" -B "${BRANCH}" --confirm
# yamllint enable rule:line-length

name: cleanup by branch on delete

Expand Down
242 changes: 127 additions & 115 deletions .github/workflows/actions.yml
Expand Up @@ -9,50 +9,54 @@ jobs:
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
uses: ./
with:
# yamllint disable rule:line-length
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 != "stable" or
.head_branch != null 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
) and
.status != "in_progress"
) |
select(
(.run_started_at | fromdate) < (now - 60 * 60 * 24 * 60) or
(.head_branch != "stable" and .conclusion == "cancelled") or
(
(.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."))
(.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
) |
{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
# yamllint enable rule:line-length
cleanup-packages:
permissions:
packages: write
Expand All @@ -62,20 +66,24 @@ jobs:
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
using:
with:
# yamllint disable rule:line-length
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
# yamllint enable rule:line-length
rerun-actions:
permissions:
actions: write
Expand All @@ -86,68 +94,72 @@ jobs:
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
uses: ./
with:
# yamllint disable rule:line-length
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
# yamllint enable rule:line-length

name: Meta Actions

Expand Down

0 comments on commit 60b9997

Please sign in to comment.