Skip to content

Delete Old Build Artifacts #571

Delete Old Build Artifacts

Delete Old Build Artifacts #571

Workflow file for this run

name: Delete Old Build Artifacts
on:
workflow_dispatch:
push:
schedule:
- cron: "0 21 * * *"
jobs:
get_and_delete_old_run_ids:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Get old run IDs
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "OLD_IDS<<$EOF" >> "$GITHUB_ENV"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs \
| jq -r '.workflow_runs[] | select(.created_at < "'$(date -d "-7 day" +%Y-%m-%dT%H:%M:%SZ)'") | .id' >> "$GITHUB_ENV"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs \
| jq -r '.workflow_runs[] | select(.name == "Delete Old Build Artifacts") | .id' >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"
- name: Delete old run IDs
run: |
echo $OLD_IDS | while read -d ' ' -r id || [[ -n ${id} ]]; do
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/$id
echo "Delete run id: $id"
done
# curl -L \
# -X DELETE \
# -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/RUN_ID
# curl -X GET -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/Roarcannotprogramming/openwrt_workflow/actions/runs | jq -r '.workflow_runs[] | select(.created_at < "'$(date -d "-7 day" +%Y-%m-%dT%H:%M:%SZ)'") | .id'