---
title: Why I delete GitHub Actions artifacts after deployment
author: Szymon Cytrowski
url: https://cytrowski.me/posts/github-actions-artifact-cleanup/
published: 2026-11-23T00:00:00.000Z
description: My release workflow kept a copy of every build after deployment. I
  changed when GitHub Actions deletes those files once I understood how storage
  hours add up.
tags:
  - github
language: en
---

# Why I delete GitHub Actions artifacts after deployment

My release workflow kept a copy of every build after deployment. I changed when GitHub Actions deletes those files once I understood how storage hours add up.

I used up my monthly GitHub Actions storage allowance while working on a web app. Each time I deployed a new version, a copy of the build stayed on GitHub after the release was over.

Those copies came from the way I passed files between jobs. The build job uploaded the contents of `dist/` as an artifact called `site-dist`. The end-to-end tests ran against the files in that archive. If they passed, the deployment job downloaded the same archive, so the files that went to production were exactly the ones I had tested.

Deployment was the last time I needed that archive. I had left `retention-days` unset on the upload step, though, so GitHub kept each copy for the repository's retention period. The default is 90 days. [Artifact retention](https://docs.github.com/en/actions/how-tos/manage-workflow-runs/remove-workflow-artifacts)

## What It Costs to Keep a Build

GitHub adds up how much data I store each hour. Keeping a 1 GB build for one hour uses one **GB-hour**. Deleting the build frees the space immediately. The GB-hours it used still count toward that month's total.

My $4/month GitHub Pro account shows a **2 GB** storage allowance. Over a 30-day billing cycle, that covers **1,440 GB-hours** (2 GB × 30 days × 24 hours per day). Suppose I upload a 2 GB build at the start of the cycle and deploy another 2 GB build halfway through. These are my only stored files.

- **If I delete the old build when the new one goes live**, each build spends 15 days in storage. Together they use **1,440 GB-hours**, exactly my allowance. I pay nothing extra.
- **If I keep the old build**, it uses 1,440 GB-hours over 30 days. The new build uses another 720 over the last 15 days. That's **2,160 GB-hours** in total, or 720 over my allowance. Keeping that extra 2 GB for half the month costs **$0.25**, the price of one GB-month. [GitHub's storage rates](https://docs.github.com/en/billing/concepts/product-billing/github-actions#storage-pricing)

Private repository artifacts share this allowance with GitHub Packages. GitHub's billing tables list 1 GB for Pro artifacts and 2 GB for Pro packages, so I used the figure shown on my account. [Actions billing](https://docs.github.com/en/billing/concepts/product-billing/github-actions#how-storage-billing-works) · [Packages billing](https://docs.github.com/en/billing/concepts/product-billing/github-packages#free-use-of-github-packages)

## Delete the Build After Its Last Job

The smallest change was to set `retention-days: 1` on the build job's upload step. That gives each new archive a one-day lifetime, which makes sense if someone might need it the next morning.

```yaml
- name: Upload built site
  uses: actions/upload-artifact@v4
  with:
    name: site-dist
    path: dist/
    if-no-files-found: error
    retention-days: 1
```

In my case the deployment job was the last reader. I kept the one-day expiry as a fallback and added a final job under `jobs` to delete this run's copy as soon as the release was over.

```yaml
cleanup:
  needs: [build, e2e, deploy]
  if: ${{ always() }}
  runs-on: ubuntu-latest
  steps:
    - name: Delete built site
      uses: geekyeggo/delete-artifact@176a747ab7e287e3ff4787bf8a148716375ca118
      with:
        name: site-dist
        failOnError: false
```

`needs` makes cleanup wait for the build, tests, and deployment. If E2E fails and deployment is skipped, `always()` still lets cleanup run. With `failOnError: false`, the delete action logs a deletion error without failing the job. If the archive survives, the one-day expiry still applies. [Job dependencies](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idneeds) · [Delete action behavior](https://github.com/GeekyEggo/delete-artifact/blob/176a747ab7e287e3ff4787bf8a148716375ca118/README.md)

The trade-off shows up on a retry. Once cleanup deletes `site-dist`, rerunning just the deployment job leaves it with nothing to download. I'd have to run the build and tests again. If I needed to redeploy yesterday's exact files, I'd keep the archive for that retry window.
