fi delete pre release version by default

This commit is contained in:
Namrata Jha
2021-11-16 05:34:29 +00:00
committed by GitHub
parent 1ea7a488b4
commit 0de5ea0608
5 changed files with 87 additions and 22 deletions

View File

@@ -11,6 +11,8 @@ This action deletes versions of a package from [GitHub Packages](https://github.
* Delete version(s) of a package that is hosted in the same repo that is executing the workflow
* Delete version(s) of a package that is hosted in a different repo than the one executing the workflow
* Specify a minimum number of latest package versions to not get deleted.
* Ignore some versions based on name and delete remaining versions.
* Delete all pre-release versions
# Usage
@@ -44,6 +46,14 @@ This action deletes versions of a package from [GitHub Packages](https://github.
# Defaults to 1.
min-versions-to-keep:
# The package versions to ignore exclude from deletion.
# By default nothing is ignored"
ignore-versions:
# If true it will delete all the pre-release versions upto 100 at once.
# Defaults to false.
delete-only-pre-release-versions:
# The token used to authenticate with GitHub Packages.
# Defaults to github.token.
# Required if deleting a version from a package hosted in a different repo than the one executing the workflow.
@@ -54,25 +64,19 @@ This action deletes versions of a package from [GitHub Packages](https://github.
# Scenarios
- [Delete Package Versions](#delete-package-versions)
- [What It Can Do](#what-it-can-do)
- [Usage](#usage)
- [Scenarios](#scenarios)
- [Delete oldest x number of versions and keeping y latest versions of a package hosted in the same repo as the workflow](#delete-oldest-x-number-of-versions-and-keeping-y-latest-versions-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete oldest x number of versions and keeping y latest versions of a package hosted in a different repo than the workflow](#delete-oldest-x-number-of-versions-and-keeping-y-latest-versions-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete a specific version of a package hosted in the same repo as the workflow](#delete-a-specific-version-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete a specific version of a package hosted in a different repo than the workflow](#delete-a-specific-version-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete multiple specific versions of a package hosted in the same repo as the workflow](#delete-multiple-specific-versions-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete multiple specific versions of a package hosted in a different repo than the workflow](#delete-multiple-specific-versions-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete oldest version of a package hosted in the same repo as the workflow](#delete-oldest-version-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete oldest version of a package hosted in a different repo than the workflow](#delete-oldest-version-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete oldest x number of versions of a package hosted in the same repo as the workflow](#delete-oldest-x-number-of-versions-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete oldest x number of versions of a package hosted in a different repo than the workflow](#delete-oldest-x-number-of-versions-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete oldest x number of versions and keeping y latest versions of a package hosted in the same repo as the workflow](#delete-oldest-x-number-of-versions-and-keeping-y-latest-versions-of-a-package-hosted-in-the-same-repo-as-the-workflow-1)
- [Delete oldest x number of versions and keeping y latest versions of a package hosted in a different repo than the workflow](#delete-oldest-x-number-of-versions-and-keeping-y-latest-versions-of-a-package-hosted-in-a-different-repo-than-the-workflow-1)
- [License](#license)
# [Delete oldest x number of versions and keeping y latest versions of a package hosted in the same repo as the workflow](#delete-oldest-x-number-of-versions-and-keeping-y-latest-versions-of-a-package-hosted-in-the-same-repo-as-the-workflow)
# [Delete oldest x number of versions and keeping y latest versions of a package hosted in a different repo than the workflow](#delete-oldest-x-number-of-versions-and-keeping-y-latest-versions-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete a specific version of a package hosted in the same repo as the workflow](#delete-a-specific-version-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete a specific version of a package hosted in a different repo than the workflow](#delete-a-specific-version-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete multiple specific versions of a package hosted in the same repo as the workflow](#delete-multiple-specific-versions-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete multiple specific versions of a package hosted in a different repo than the workflow](#delete-multiple-specific-versions-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete oldest version of a package hosted in the same repo as the workflow](#delete-oldest-version-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete oldest version of a package hosted in a different repo than the workflow](#delete-oldest-version-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete oldest x number of versions of a package hosted in the same repo as the workflow](#delete-oldest-x-number-of-versions-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete oldest x number of versions of a package hosted in a different repo than the workflow](#delete-oldest-x-number-of-versions-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete oldest x number of versions and keeping y latest versions of a package hosted in the same repo as the workflow](#delete-oldest-x-number-of-versions-and-keeping-y-latest-versions-of-a-package-hosted-in-the-same-repo-as-the-workflow)
- [Delete oldest x number of versions and keeping y latest versions of a package hosted in a different repo than the workflow](#delete-oldest-x-number-of-versions-and-keeping-y-latest-versions-of-a-package-hosted-in-a-different-repo-than-the-workflow)
- [Delete oldest x number of versions while ignoring particular package versions in the same repo as the workflow](#delete-oldest-x-number-of-versions-while-ignoring-particular-package-versions-in-the-same-repo-as-the-workflow)
- [Delete all pre-release package versions in the same repo as the workflow](#delete-all-pre-release-package-versions-in-the-same-repo-as-the-workflow)
### Delete a specific version of a package hosted in the same repo as the workflow
@@ -255,6 +259,40 @@ Delete the oldest 3 version and always keep atleast 2 versions of a package host
token: ${{ secrets.GITHUB_PAT }}
```
<br>
### Delete oldest x number of versions while ignoring particular package versions in the same repo as the workflow
To delete oldest x number of versions while ignoring all the major package versions in the same repo as the workflow the __package-name__, __num-oldest-versions-to-delete__ and __ignore-versions__ inputs are required.
There is a possibility if the oldest x number of versions contain ignored package versions, actual package versions to ge deleted will be less than x.
__Example__
Delete 3 oldest versions excluding major versions as per semver is the same repo as the workflow
```yaml
- uses: actions/delete-package-versions@v1
with:
package-name: 'test-packae'
num-old-versions-to-delete: 3
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
```
### Delete all pre-release package versions in the same repo as the workflow
To delete all pre release package versions in the same repo as the workflow the __package-name__ and __delete-only-pre-release-versions__ inputs are required.
__Example__
Delete all pre-release package versions in the same repo as the workflow
```yaml
- uses: actions/delete-package-versions@v1
with:
package-name: 'test-package'
delete-only-pre-release-versions: "true"
```
# License

View File

@@ -42,10 +42,18 @@ inputs:
ignore-versions:
description: >
Comma seperated regex patterns of versions to ignore.
Defaults to all major and minor versions and only deletes pre-release and patch versions.
Regex pattern for package versions to ignore.
Defaults to delete all versions.
required: false
default: "^(0|[1-9]\\d*)((\\.(0|[1-9]\\d*))*)$"
default: "^$"
delete-only-pre-release-versions:
description: >
Deletes all the pre-release versions upto 100.
When this is set min-versions-to-keep, num-old-versions-to-delete and ignore-versions will not be taken into account.
By default this is set to false
required: false
default: "false"
token:
description: >

8
dist/index.js vendored
View File

@@ -75,6 +75,7 @@ const defaultParams = {
numOldVersionsToDelete: 0,
minVersionsToKeep: 0,
ignoreVersions: new RegExp(''),
deletePreReleaseVersions: '',
token: ''
};
class Input {
@@ -87,7 +88,13 @@ class Input {
this.numOldVersionsToDelete = validatedParams.numOldVersionsToDelete;
this.minVersionsToKeep = validatedParams.minVersionsToKeep;
this.ignoreVersions = validatedParams.ignoreVersions;
this.deletePreReleaseVersions = validatedParams.deletePreReleaseVersions;
this.token = validatedParams.token;
if (this.deletePreReleaseVersions == 'true') {
this.numOldVersionsToDelete = 100;
this.minVersionsToKeep = 0;
this.ignoreVersions = new RegExp('^(0|[1-9]\\d*)((\\.(0|[1-9]\\d*))*)$');
}
}
hasOldestVersionQueryInfo() {
return !!(this.owner &&
@@ -40315,6 +40322,7 @@ function getActionInput() {
numOldVersionsToDelete: Number(core_1.getInput('num-old-versions-to-delete')),
minVersionsToKeep: Number(core_1.getInput('min-versions-to-keep')),
ignoreVersions: RegExp(core_1.getInput('ignore-versions')),
deletePreReleaseVersions: core_1.getInput('delete-only-pre-release-versions'),
token: core_1.getInput('token')
});
}

View File

@@ -7,6 +7,7 @@ export interface InputParams {
minVersionsToKeep?: number
ignoreVersions?: RegExp
token?: string
deletePreReleaseVersions?: string
}
const defaultParams = {
@@ -17,6 +18,7 @@ const defaultParams = {
numOldVersionsToDelete: 0,
minVersionsToKeep: 0,
ignoreVersions: new RegExp(''),
deletePreReleaseVersions: '',
token: ''
}
@@ -28,6 +30,7 @@ export class Input {
numOldVersionsToDelete: number
minVersionsToKeep: number
ignoreVersions: RegExp
deletePreReleaseVersions: string
token: string
constructor(params?: InputParams) {
@@ -40,7 +43,14 @@ export class Input {
this.numOldVersionsToDelete = validatedParams.numOldVersionsToDelete
this.minVersionsToKeep = validatedParams.minVersionsToKeep
this.ignoreVersions = validatedParams.ignoreVersions
this.deletePreReleaseVersions = validatedParams.deletePreReleaseVersions
this.token = validatedParams.token
if (this.deletePreReleaseVersions == 'true') {
this.numOldVersionsToDelete = 100
this.minVersionsToKeep = 0
this.ignoreVersions = new RegExp('^(0|[1-9]\\d*)((\\.(0|[1-9]\\d*))*)$')
}
}
hasOldestVersionQueryInfo(): boolean {

View File

@@ -16,6 +16,7 @@ function getActionInput(): Input {
numOldVersionsToDelete: Number(getInput('num-old-versions-to-delete')),
minVersionsToKeep: Number(getInput('min-versions-to-keep')),
ignoreVersions: RegExp(getInput('ignore-versions')),
deletePreReleaseVersions: getInput('delete-only-pre-release-versions'),
token: getInput('token')
})
}