Monitor your GitHub Actions storage usage with a script
GitHub Actions is a powerful tool for automating workflows, but managing storage usage for artifacts and caches can be challenging. GitHub does not currently provide a consolidated overview of storage usage across repositories, making it difficult to track how much space your workflows consume. To address this, I created a script that calculates the total storage used by artifacts and caches for all repositories under a given owner/organization.
Why This Script?
GitHub Actions has storage quotas for artifacts:
Artifacts: 500 MB (free tier), 1GB (pro tier), 50GB (enterprise tier).
Exceeding these quotas can lead to failed workflows or additional costs.

This script which I am sharing provides a detailed breakdown of storage usage for each repository and calculates the total usage across all repositories in an organization.
Prerequisites
Before running the script, ensure you have the following:
- GitHub CLI (
gh
): Install it from GitHub CLI. - Authentication: Log in to the GitHub CLI using
gh auth login
. jq
: A lightweight JSON processor. Install it using your package manager (e.g.,brew install jq
on macOS).
The script to check the storage usage
# Ensure the GitHub CLI is authenticatedif ! gh auth status > /dev/null 2>&1; then echo "Please authenticate with the GitHub CLI using 'gh auth login'." exit 1fi
# Check if the owner is providedif [ -z "$1" ]; then echo "Usage: $0 <owner>" echo "Example: $0 owner" exit 1fi
OWNER=$1
# Check if the owner type is providedecho "Is the owner an organization or a user? (org/user)"read -r OWNER_TYPE
if [[ "$OWNER_TYPE" != "org" && "$OWNER_TYPE" != "user" ]]; then echo "Invalid input. Please specify 'org' or 'user'." exit 1fi
echo "Fetching repositories for owner: $OWNER"
PAGE=1TOTAL_ARTIFACT_SIZE=0TOTAL_CACHE_SIZE=0
while true; do # Fetch repositories for the given owner based on type (paginated, including private and internal) if [ "$OWNER_TYPE" == "org" ]; then REPOS_RESPONSE=$(gh api -H "Accept: application/vnd.github+json" \ "/orgs/$OWNER/repos?type=all&per_page=100&page=$PAGE") else REPOS_RESPONSE=$(gh api -H "Accept: application/vnd.github+json" \ "/users/$OWNER/repos?type=all&per_page=100&page=$PAGE") fi
REPOS=$(echo "$REPOS_RESPONSE" | jq -r '.[].full_name') if [ -z "$REPOS" ]; then break fi
echo "Repositories on page $PAGE:" echo "$REPOS"
for REPO in $REPOS; do echo "Processing repository: $REPO" REPO_PAGE=1 REPO_ARTIFACT_SIZE=0
while true; do # Fetch artifacts for the repository (paginated) RESPONSE=$(gh api -H "Accept: application/vnd.github+json" \ "/repos/$REPO/actions/artifacts?per_page=100&page=$REPO_PAGE")
# Extract artifact sizes and sum them up SIZES=$(echo "$RESPONSE" | jq '.artifacts[].size_in_bytes' 2>/dev/null) if [ -z "$SIZES" ]; then break fi
for SIZE in $SIZES; do REPO_ARTIFACT_SIZE=$((REPO_ARTIFACT_SIZE + SIZE)) done
# Check if there are more pages HAS_NEXT_PAGE=$(echo "$RESPONSE" | jq '.artifacts | length == 100') if [ "$HAS_NEXT_PAGE" != "true" ]; then break fi
REPO_PAGE=$((REPO_PAGE + 1)) done
# Fetch cache usage for the repository CACHE_RESPONSE=$(gh api -H "Accept: application/vnd.github+json" \ "/repos/$REPO/actions/cache/usage")
REPO_CACHE_SIZE=$(echo "$CACHE_RESPONSE" | jq '.active_caches_size_in_bytes // 0')
# Add to total sizes TOTAL_ARTIFACT_SIZE=$((TOTAL_ARTIFACT_SIZE + REPO_ARTIFACT_SIZE)) TOTAL_CACHE_SIZE=$((TOTAL_CACHE_SIZE + REPO_CACHE_SIZE))
# Convert sizes to GB REPO_ARTIFACT_SIZE_GB=$(echo "scale=2; $REPO_ARTIFACT_SIZE / 1024 / 1024 / 1024" | bc) REPO_CACHE_SIZE_GB=$(echo "scale=2; $REPO_CACHE_SIZE / 1024 / 1024 / 1024" | bc)
echo "Total artifact size for $REPO: $REPO_ARTIFACT_SIZE_GB GB" echo "Total cache size for $REPO: $REPO_CACHE_SIZE_GB GB" done
# Check if there are more pages of repositories HAS_NEXT_PAGE=$(echo "$REPOS_RESPONSE" | jq 'length == 100') if [ "$HAS_NEXT_PAGE" != "true" ]; then break fi
PAGE=$((PAGE + 1))done
# Log total sizes across all repositoriesTOTAL_ARTIFACT_SIZE_GB=$(echo "scale=2; $TOTAL_ARTIFACT_SIZE / 1024 / 1024 / 1024" | bc)TOTAL_CACHE_SIZE_GB=$(echo "scale=2; $TOTAL_CACHE_SIZE / 1024 / 1024 / 1024" | bc)
echo "========================================"echo "Total artifact size across all repositories: $TOTAL_ARTIFACT_SIZE_GB GB"echo "Total cache size across all repositories: $TOTAL_CACHE_SIZE_GB GB"
How to Use the Script
- Save the script to a file, e.g.,
check-artifacts-usage.sh
. - Make it executable:
Terminal window chmod +x check-artifacts-usage.sh - Run the script with the organization name as an argument:
Replace
Terminal window ./check-artifacts-usage.sh <owner/organization><owner/organization>
with the name of your GitHub owner or organization. - Specify whether the owner is an organization or a user when prompted. The script will:
- Fetch all repositories for the given organization.
- Calculate the total size of artifacts and caches for each repository.
- Display the total storage usage across all repositories.
Example Output
> ./check-artifacts-usage.sh my-organizationIs the owner an organization or a user? (org/user)> orgFetching repositories for owner: my-organizationmy-organization/repo1my-organization/repo2
Processing repository: my-organization/repo1Total artifact size for my-organization/repo1: 0 GBTotal cache size for my-organization/repo1: 0 GB...========================================Total artifact size across all repositories: 24.42 GBTotal cache size across all repositories: 4.09 GB
GitHub Actions Storage Quotas
For more details on GitHub Actions storage quotas, refer to the GitHub Actions usage limits.
Conclusion
This script provides a quick and easy way to monitor your GitHub Actions storage usage, helping you stay within your quotas and avoid unexpected costs. Feel free to adapt it to your needs and share your feedback!
Happy automating!
Related articles
Conditional publish packages to NPM via GitHub actions
#DevHack: Running a background service on GitHub Actions
Learn how to run a background service on GitHub Actions and use it in combination with other steps.
Using the Office 365 CLI in your Azure DevOps CI/CD pipelines for SharePoint Framework solutions
Report issues or make changes on GitHub
Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.
Comments
Let's build together
Manage content in VS Code
Present from VS Code