Skip to content

Instantly share code, notes, and snippets.

@mieky
Last active July 22, 2024 11:48
Show Gist options
  • Save mieky/33d34f2f4db7c187f351765aebe3b5e6 to your computer and use it in GitHub Desktop.
Save mieky/33d34f2f4db7c187f351765aebe3b5e6 to your computer and use it in GitHub Desktop.
Get total size of artifacts in a GitHub repo
#!/bin/bash
# Calculate the total size of artifacts in GitHub repo (not visible in the UI).
# Needs token with the "repo" scope: Profile > Settings > Developer Settings > Personal access tokens
#
# Requires jq 1.6 or higher.
if [ $# -ne 1 ] || [ -z $API_TOKEN ]; then
echo "Usage: API_TOKEN=<token> $0 <org/repo>"
exit 1
fi
REPO_NAME=$1
ARTIFACTS_SIZE=$(curl --silent \
-H "Authorization: token $API_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$REPO_NAME/actions/artifacts" \
| jq '[.artifacts[] | .size_in_bytes] | (add // 0) / (1024*1024) | round')
echo "Total size of artifacts in repo \"$REPO_NAME\": ${ARTIFACTS_SIZE}MB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment