A GitHub action to remove older releases with their tags based on a regex pattern. This action provides flexible filtering options to keep releases based on recency, age, or exclusion patterns.
Key Features:
To use the action, add following to your workflow file
- name: Delete Older Releases
uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: "Build*"
RELEASES_TO_KEEP: 5 # Optional: Keep the 5 most recent releases matching the pattern
Following inputs can be used as step.with
keys
Name | Type | Required | Default | Description |
---|---|---|---|---|
GITHUB_TOKEN |
String | âś… Yes | Â | GitHub Token with contents:write permissions to delete releases and tags |
RELEASE_PATTERN |
String | âś… Yes | Â | Regular expression pattern to match release tag names for deletion (e.g., "^v1\\..*" for all v1.x releases) |
RELEASES_TO_KEEP |
Number | ❌ No | 0 |
Number of most recent matching releases to keep (sorted by creation date). 0 means don’t keep any by count |
EXCLUDE_PATTERN |
String | ❌ No | "" |
Regular expression pattern to exclude releases from deletion (e.g., ".*-stable$" to exclude stable releases) |
DAYS_TO_KEEP |
Number | ❌ No | 0 |
Number of days to keep releases. Releases newer than this will be preserved. 0 means don’t keep any by age |
DRY_RUN |
Boolean | ❌ No | false |
If true , the action will list the releases to be deleted without actually deleting them. Useful for testing. |
DELETE_DRAFT_RELEASES_ONLY |
Boolean | ❌ No | false |
If true , only draft releases will be considered for deletion. This filter is applied before RELEASE_PATTERN . |
DELETE_PRERELEASES_ONLY |
Boolean | ❌ No | false |
If true , only prereleases will be considered for deletion. This filter is applied before RELEASE_PATTERN . |
TARGET_BRANCH_PATTERN |
String | ❌ No | "" |
Regex pattern to match the target branch of a release’s commit. Only releases whose associated commit is on a matching branch will be considered for deletion. |
RELEASES_TO_KEEP
and DAYS_TO_KEEP
must be non-negative integersRELEASE_PATTERN
and EXCLUDE_PATTERN
must be valid regular expressionsRELEASE_PATTERN
will result in no releases being processedThe action follows this logic sequence:
DELETE_DRAFT_RELEASES_ONLY
is true
, filter to include only draft releases.DELETE_PRERELEASES_ONLY
is true
, filter to include only prereleases.TARGET_BRANCH_PATTERN
is provided, filter releases to include only those whose associated commit is on a branch matching the pattern.RELEASE_PATTERN
EXCLUDE_PATTERN
(if provided)RELEASES_TO_KEEP
most recent releasesDAYS_TO_KEEP
days oldDELETE_DRAFT_RELEASES_ONLY
is true
, the action will exclusively target draft releases, ignoring published releases. This filter is applied at the very beginning of the process.DELETE_PRERELEASES_ONLY
is true
, the action will exclusively target prereleases, ignoring stable releases. This filter is applied at the very beginning of the process.TARGET_BRANCH_PATTERN
is provided, the action will fetch the commit associated with each release and filter releases based on whether their commit’s branch matches the provided pattern. This filter is applied early in the process.RELEASES_TO_KEEP
and DAYS_TO_KEEP
work with OR logic - a release is kept if it meets either criteriaEXCLUDE_PATTERN
is applied first, so excluded releases are never deleted regardless of other settingsRELEASES_TO_KEEP=0
or DAYS_TO_KEEP=0
disables that specific preservation method- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: "^beta-.*" # Delete all beta releases
- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: ".*" # Match all releases (drafts will be filtered by DELETE_DRAFT_RELEASES_ONLY)
DELETE_DRAFT_RELEASES_ONLY: true # Only target draft releases for deletion
- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: ".*" # Match all releases
DRY_RUN: true # List releases to be deleted without actually deleting them
- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: "^v[0-9]+\\.[0-9]+\\.[0-9]+$" # Match semantic versions
RELEASES_TO_KEEP: 3 # Keep the 3 most recent versions
- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: ".*" # Match all releases
DAYS_TO_KEEP: 30 # Keep releases from the last 30 days
- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: "^v.*"
RELEASES_TO_KEEP: 2 # Keep 2 most recent releases
DAYS_TO_KEEP: 90 # AND/OR keep releases from last 90 days
# A release is kept if it's either in the top 2 recent OR newer than 90 days
- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: "^v.*"
EXCLUDE_PATTERN: ".*-stable$" # Never delete releases ending with '-stable'
RELEASES_TO_KEEP: 5
- name: Delete Older Releases
uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: "Build*"
RELEASES_TO_KEEP: 5 # Optional: Keep the 5 most recent releases matching the pattern
- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: ".*" # Match all releases (prereleases will be filtered by DELETE_PRERELEASES_ONLY)
DELETE_PRERELEASES_ONLY: true # Only target prereleases for deletion
- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: ".*" # Match all releases
TARGET_BRANCH_PATTERN: "^release/.*" # Only delete releases whose commit is on a branch starting with 'release/'
- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
RELEASE_PATTERN: "^(dev|test|staging)-.*" # Target dev/test/staging releases
EXCLUDE_PATTERN: ".*(important|milestone).*" # Protect important releases
RELEASES_TO_KEEP: 10 # Keep 10 most recent matching releases
DAYS_TO_KEEP: 7 # Also keep any from the last week
The GitHub token must have the following permissions:
contents: write
- Required to delete releases and tagsmetadata: read
- Required to read repository information- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
# ... other inputs
If you need to run this action on a different repository or need additional permissions:
repo
scopeGH_TOKEN
)- uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: $
# ... other inputs
The action provides detailed error messages for common issues:
Error Message | Cause | Solution |
---|---|---|
Need Github Token |
Missing or empty GITHUB_TOKEN |
Ensure GITHUB_TOKEN is provided and not empty |
RELEASES_TO_KEEP must be a non-negative integer |
Invalid RELEASES_TO_KEEP value |
Use a non-negative integer (0, 1, 2, etc.) |
DAYS_TO_KEEP must be a non-negative integer |
Invalid DAYS_TO_KEEP value |
Use a non-negative integer (0, 1, 2, etc.) |
Unable to list release |
API error or permissions issue | Check token permissions and repository access |
Unable to delete release |
Insufficient permissions or release doesn’t exist | Verify contents:write permission |
Unable to delete tag |
Insufficient permissions or tag doesn’t exist | Verify contents:write permission |
Invalid regular expression | Malformed regex in patterns | Test regex patterns before using |
To test your configuration without actually deleting releases:
RELEASE_PATTERN
matches existing release tag namesRELEASES_TO_KEEP
and DAYS_TO_KEEP
use OR logicEXCLUDE_PATTERN
is working as expectedcontents:write
permissionWant to contribute? Awesome! The most basic way to show your support is to star the project, or to raise issues.
Thanks again for your support, it is much appreciated!