-
Notifications
You must be signed in to change notification settings - Fork 1
77 lines (61 loc) · 2.53 KB
/
_delete-partFiles.yml
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# ATTRIBUTION-AI: Largely attributable to ChatGPT o1-preview 2024-11-20 .
name: _delete-partFiles
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
permissions:
actions: write
checks: read
contents: write
deployments: read
issues: read
packages: read
pull-requests: read
repository-projects: read
security-events: none
statuses: read
on:
workflow_dispatch:
inputs:
release_tag:
description: 'Release tag (e.g., build-10889308814-1)'
required: true
jobs:
delete_part_files:
runs-on: ubuntu-latest
steps:
- name: Delete .part* Files from Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
run: |
OWNER=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f1)
REPO=$(echo "${GITHUB_REPOSITORY}" | cut -d'/' -f2)
echo "Fetching release information for tag: ${RELEASE_TAG}"
RESPONSE=$(curl -sSL \
-H "Authorization: token ${GH_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${OWNER}/${REPO}/releases/tags/${RELEASE_TAG}")
if echo "${RESPONSE}" | grep -q '"message": "Not Found"'; then
echo "Error: Release '${RELEASE_TAG}' not found."
exit 1
fi
echo "Deleting .part* files from release: ${RELEASE_TAG}"
echo "${RESPONSE}" | jq -r '.assets[] | select(.name | test("\\.part.*$")) | .id' | while read ASSET_ID; do
ASSET_INFO=$(curl -sSL \
-H "Authorization: token ${GH_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${OWNER}/${REPO}/releases/assets/${ASSET_ID}")
ASSET_NAME=$(echo "${ASSET_INFO}" | jq -r '.name')
echo "Deleting asset: ${ASSET_NAME} (ID: ${ASSET_ID})"
DELETE_RESPONSE=$(curl -sSL -o /dev/null -w "%{http_code}" \
-X DELETE \
-H "Authorization: token ${GH_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${OWNER}/${REPO}/releases/assets/${ASSET_ID}")
if [ "${DELETE_RESPONSE}" -eq 204 ]; then
echo "Successfully deleted asset: ${ASSET_NAME}"
else
echo "Failed to delete asset: ${ASSET_NAME}"
echo "HTTP Response Code: ${DELETE_RESPONSE}"
exit 1
fi
done