Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from smallprogram/master
Browse files Browse the repository at this point in the history
  • Loading branch information
thadguidry authored Sep 28, 2023
2 parents 12d87c8 + faa8a6f commit b6cc328
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ inputs:
delete_tags:
description: whether to delete tags associated to older releases or not
required: false
delete_prerelease_only:
description: Remove only prerelease
required: false
default: false
delete_tag_pattern:
description: part of the tag name. Example, if you want to delete 0.0.1-beta and 0.0.2-beta but not 0.0.1 then set this to just "beta". If not set then it will target all releases.
required: false
Expand Down
15 changes: 13 additions & 2 deletions README.md β†’ docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This action deletes older releases of given repo
Add following step to your workflow:

```yaml
- uses: dev-drprasad/[email protected].0
- uses: dev-drprasad/[email protected].1
with:
repo: <owner>/<repoName> # defaults to current repo
keep_latest: 3
Expand Down Expand Up @@ -50,6 +50,14 @@ To delete data that exceeds the specified number of days, please enter the numbe

Specifies whether to delete tags associated to older releases or not. Older tags without any associated releases will not be deleted

#### `delete_prerelease_only`

| required | default |
| -------- | ------- |
| false | false |

Delete only prerelease

#### `repo`

| required | default |
Expand All @@ -64,4 +72,7 @@ Repo name in the format of `<owner>/<repoName>`. Defaults to the repo that execu
| -------- | ------------ |
| false | empty string |

Specifies a pattern to match. If not specified then every release will be targeted. If specified then every release containing the pattern will be targeted. Use this option for example to remove old beta releases.
Specifies a release **tag** (not title) Regex string pattern to match. If not specified, then every release will be targeted. If specified, then every release containing the pattern will be targeted. Examples, `beta`, `^v2\..*-beta$`, `v3\.0.*`

### Flow Chart
![http-bw](flowChart.svg)
1 change: 1 addition & 0 deletions docs/flowChart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 29 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,17 @@ if (shouldDeleteTags) {
console.log("πŸ”– corresponding tags also will be deleted");
}

let deletePattern = process.env.INPUT_DELETE_TAG_PATTERN || "";
if (deletePattern) {
console.log(`releases containing ${deletePattern} will be targeted`);
const deletePrereleaseOnly = process.env.INPUT_DELETE_PRERELEASE_ONLY === "true";

if (deletePrereleaseOnly) {
console.log("πŸ”– Remove only prerelease");
}

let deletePatternStr = process.env.INPUT_DELETE_TAG_PATTERN || "";
let deletePattern = new RegExp("");
if (deletePatternStr) {
console.log(`releases matching ${deletePatternStr} will be targeted`);
deletePattern = new RegExp(deletePatternStr);
}
const commonOpts = {
host: "api.github.com",
Expand Down Expand Up @@ -112,10 +120,14 @@ async function deleteOlderReleases(keepLatest, keepMinDownloadCount, deleteExpir
}

data = releasesData || [];
// filter for delete_pattern
const activeMatchedReleases = data.filter(
({ draft, tag_name, assets }) => !draft && tag_name.indexOf(deletePattern) !== -1 && assets.length > 0
);

const activeMatchedReleases = data.filter((item) => {
if (deletePrereleaseOnly) {
return !item.draft && item.tag_name.match(deletePattern) !== -1 && item.assets.length > 0 && item.prerelease;
} else {
return !item.draft && item.tag_name.match(deletePattern) !== -1 && item.assets.length > 0;
}
})

if (activeMatchedReleases.length === 0) {
console.log(`πŸ˜• no active releases found. exiting...`);
Expand All @@ -124,9 +136,16 @@ async function deleteOlderReleases(keepLatest, keepMinDownloadCount, deleteExpir

const matchingLoggingAddition = deletePattern.length > 0 ? " matching" : "";

console.log(
`πŸ’¬ found total of ${activeMatchedReleases.length}${matchingLoggingAddition} active release(s)`
);
if (deletePrereleaseOnly) {
console.log(
`πŸ’¬ found total of ${activeMatchedReleases.length}${matchingLoggingAddition} active prerelease(s)`
);
} else {
console.log(
`πŸ’¬ found total of ${activeMatchedReleases.length}${matchingLoggingAddition} active release(s)`
);
}



releaseIdsAndTags = activeMatchedReleases
Expand Down

0 comments on commit b6cc328

Please sign in to comment.