_delete-partFiles #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ATTRIBUTION-AI: Largely attributable to ChatGPT o1-preview 2024-11-20 . | |
name: _delete-partFiles | |
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 |