Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue #35

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/README.md → 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/delete-older-releases@v0.3.1
- uses: dev-drprasad/delete-older-releases@v0.3.2
with:
repo: <owner>/<repoName> # defaults to current repo
keep_latest: 3
Expand Down Expand Up @@ -74,6 +74,14 @@ Repo name in the format of `<owner>/<repoName>`. Defaults to the repo that execu

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.*`

#### github_rest_api_url

| required | default |
| -------- | ------------ |
| false |api.github.com|

Github rest api url, the default is "api.github.com". If you are an enterprise user, you can replace it with "{your-github-enterprise-url}/api/v3". Please refer to: https://docs.github.com/en/enterprise-cloud@latest/rest

### Flow Chart (mermaid format)

```mermaid
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ inputs:
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
github_rest_api_url:
description: the URL of the GitHub Rest API to be used. This might need to be different if you are a GitHub Enterprise user.
required: false
default: api.github.com

runs:
using: "node16"
Expand Down
44 changes: 32 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ if (deletePatternStr) {
console.log(`releases matching ${deletePatternStr} will be targeted`);
deletePattern = new RegExp(deletePatternStr);
}
const commonOpts = {
host: "api.github.com",
port: 443,
protocol: "https:",
auth: `user:${GITHUB_TOKEN}`,
headers: {
"Content-Type": "application/json",
"User-Agent": "node.js",
},
};

let keepMinDownloadCount = Number(process.env.INPUT_KEEP_MIN_DOWNLOAD_COUNTS);

Expand All @@ -97,6 +87,18 @@ if (Number.isNaN(deleteExpiredData) || deleteExpiredData < 0) {

console.log("🌶 given `delete_expired_data` is ",deleteExpiredData);

let gitHubRestApi = process.env.INPUT_GITHUB_REST_API_URL || "api.github.com";

const commonOpts = {
host: gitHubRestApi,
port: 443,
protocol: "https:",
auth: `user:${GITHUB_TOKEN}`,
headers: {
"Content-Type": "application/json",
"User-Agent": "node.js",
},
};


async function deleteOlderReleases(keepLatest, keepMinDownloadCount, deleteExpiredData) {
Expand All @@ -123,12 +125,30 @@ async function deleteOlderReleases(keepLatest, keepMinDownloadCount, deleteExpir

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

// const activeMatchedReleases = data.filter((item) => {
// const shouldDelete = deletePrereleaseOnly && deletePatternStr;
// const isDraft = item.draft;
// const hasAssets = item.assets.length > 0;
// const isPrerelease = item.prerelease;
// const isTagMatching = deletePatternStr ? item.tag_name.match(deletePattern) : true;

// return !isDraft && hasAssets && (shouldDelete ? (isTagMatching && isPrerelease) : true);
// });

if (activeMatchedReleases.length === 0) {
console.log(`😕 no active releases found. exiting...`);
return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "delete-older-releases",
"version": "0.2.1",
"version": "0.3.2",
"main": "index.js",
"repository": {
"type": "git",
Expand Down