Skip to content

Instantly share code, notes, and snippets.

@gilbertwat
Created March 23, 2022 09:16
Show Gist options
  • Save gilbertwat/ca061b0d5d1f4d623c9ed878362835a4 to your computer and use it in GitHub Desktop.
Save gilbertwat/ca061b0d5d1f4d623c9ed878362835a4 to your computer and use it in GitHub Desktop.
Remove all Github Action Artifacts for 1 repo
#!/bin/zsh
ORG=${ORG:-"preface-ai"}
REPO=${REPO:-"preface-website-frontend"}
echo "Removing artifacts in {$REPO} from {$ORG}"
IDS="$(gh api /repos/$ORG/$REPO/actions/artifacts --paginate --jq '.artifacts[] | .id')"
echo $IDS
if [ -z "$IDS" ];
then
echo "There is no artifacts."
return 0
fi
while read id; do
echo "Removing artifact id {$id}"
if ! (gh api -X DELETE /repos/$ORG/$REPO/actions/artifacts/$id --silent)
then
echo "Failed to remove artifact id {$id}"
else
echo "Success! Removed artifact id {$id}"
fi
done <<< "$IDS" #here-string from https://askubuntu.com/questions/344407/how-to-read-complete-line-in-for-loop-with-spaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment