Skip to content

ci(deploy): prune expired deployment prefixes - #592

Draft
caugner wants to merge 8 commits into
528-release-specific-content-prefixesfrom
528-cleanup-expired-deployments
Draft

caugner wants to merge 8 commits into
528-release-specific-content-prefixesfrom
528-cleanup-expired-deployments

Conversation

@caugner

@caugner caugner commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Clean up expired deployment prefixes after prod, stage, and test deployments.

  • Preserve prefixes used by active Cloud Functions.
  • Remove inactive prefixes older than the configured retention period.

Motivation

Keep the release-specific deployment folders introduced by #573 from accumulating indefinitely while ensuring active functions retain their source content.

Additional details

  • List immediate prefixes under deployments/ with gcloud storage ls, then delete each expired prefix with gcloud storage rm --recursive, which deletes in bulk.
  • Read active function configuration with gcloud functions and run storage cleanup with the content service account.
  • Cleanup steps are continue-on-error, since they run after the deploy succeeded.
  • Serialize deployments per environment so a delayed older run can't deploy over a newer one. GitHub keeps at most one pending run per group, so a queued run may be superseded by a newer one.
  • Rolling back to a Cloud Run revision older than the retention period would point at a deleted prefix.

Related issues and pull requests

Depends on:

@caugner
caugner added this pull request to stack #593 October 16, 2026 18:16
`Bucket.deleteFiles()` removes objects one at a time with a parallelism
of 10, which takes tens of minutes for a full build. `gcloud storage rm
--recursive` deletes in bulk, is already on the runner, and avoids the
extra dependency. List with `gcloud storage ls`, whose output contains
only the immediate children of `deployments/`.

Keep only the tail of gcloud's stderr, since `rm` prints a status line
per object.
Keep a single definition of a valid deployment prefix instead of a
second, looser regex in `getActiveDeployment()`.
Separate the pure expired/retained/unrecognized split from listing and
deletion so it can be unit-tested, and only run `main()` when the script
is executed directly.
Cleanup runs after the function deploy succeeded, so a transient storage
or auth error must not fail the run or skip the remaining steps.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants