-
Notifications
You must be signed in to change notification settings - Fork 51
37 lines (34 loc) · 1.18 KB
/
cleanup-copilot-artifacts.yml
File metadata and controls
37 lines (34 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
name: Cleanup Copilot Artifacts
on:
workflow_run:
workflows: ["Copilot code review"]
types:
- completed
permissions:
actions: write
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Delete artifacts from Copilot code review run
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Deleting artifacts for run ID: ${{ github.event.workflow_run.id }}"
mapfile -t artifact_ids < <(gh api \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts \
--jq '.artifacts[].id')
if [ ${#artifact_ids[@]} -eq 0 ]; then
echo "No artifacts found for this run."
else
for artifact_id in "${artifact_ids[@]}"; do
gh api \
--silent \
-X DELETE \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/actions/artifacts/"$artifact_id" \
|| echo "Warning: failed to delete artifact $artifact_id"
done
fi
echo "Artifact cleanup completed"