mirror of
https://github.com/Ishan09811/pine.git
synced 2025-04-24 08:55:10 +00:00
40 lines
1.3 KiB
YAML
40 lines
1.3 KiB
YAML
name: Cleanup Artifacts
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
schedule:
|
|
- cron: '0 0 * * *'
|
|
|
|
jobs:
|
|
cleanup:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Get all artifacts
|
|
id: get-artifacts
|
|
run: |
|
|
curl -H "Authorization: token ${{ secrets.ME_TOKEN }}" \
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
https://api.github.com/repos/${{ github.repository }}/actions/artifacts \
|
|
-o artifacts.json
|
|
|
|
- name: Process artifacts
|
|
id: process-artifacts
|
|
run: |
|
|
NEWEST_ARTIFACT_ID=$(jq '.artifacts[0].id' artifacts.json)
|
|
echo "Newest artifact ID: $NEWEST_ARTIFACT_ID"
|
|
jq -c '.artifacts[] | select(.id != '"$NEWEST_ARTIFACT_ID"')' artifacts.json > artifacts_to_delete.json
|
|
jq -r '.id' artifacts_to_delete.json > artifacts_ids.txt
|
|
|
|
- name: Delete old artifacts
|
|
run: |
|
|
while IFS= read -r artifact_id; do
|
|
echo "Deleting artifact $artifact_id"
|
|
curl -X DELETE -H "Authorization: token ${{ secrets.ME_TOKEN }}" \
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact_id
|
|
done < artifacts_ids.txt
|