Compare commits
92
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eaa1f7c20f | ||
|
|
ce1d329288 | ||
|
|
9dbafb83da | ||
|
|
64305dab94 | ||
|
|
e95cd87648 | ||
|
|
7f4037254e | ||
|
|
e521d9e753 | ||
|
|
cc7196aa1d | ||
|
|
6ce7577c5e | ||
|
|
92bd8a3cd0 | ||
|
|
280935cb1a | ||
|
|
272ad859dc | ||
|
|
c5e64443ea | ||
|
|
9b1e76ea45 | ||
|
|
37b7aca7eb | ||
|
|
f87b4a0b81 | ||
|
|
6961202f36 | ||
|
|
4eab40be13 | ||
|
|
8701e46f41 | ||
|
|
565ec2459a | ||
|
|
ec4518c513 | ||
|
|
33300d7916 | ||
|
|
e048663cdf | ||
|
|
0e86ee6891 | ||
|
|
a31a43afa6 | ||
|
|
56849b848a | ||
|
|
000223ef3e | ||
|
|
df897cea27 | ||
|
|
b77daeff53 | ||
|
|
7515f7a4f9 | ||
|
|
3e14cd73d4 | ||
|
|
5e4787da1c | ||
|
|
355299fa7d | ||
|
|
5263253279 | ||
|
|
d6bf5f6a97 | ||
|
|
4afcc8f713 | ||
|
|
1472d90599 | ||
|
|
09f7b84634 | ||
|
|
5aa567b6f7 | ||
|
|
1979f24cbb | ||
|
|
6a5e08c48d | ||
|
|
f804442fe4 | ||
|
|
5282013b71 | ||
|
|
4d762a4bc3 | ||
|
|
aac34a9f33 | ||
|
|
406ce0281d | ||
|
|
72cc4b27b0 | ||
|
|
7d188d1776 | ||
|
|
81676df338 | ||
|
|
cfbae0ac37 | ||
|
|
f556b07dce | ||
|
|
8283350471 | ||
|
|
1a7a0291b8 | ||
|
|
38d4003d57 | ||
|
|
bf6c02443a | ||
|
|
e9faf3233c | ||
|
|
9ff1e31776 | ||
|
|
0739cce1e8 | ||
|
|
ef5d9ac398 | ||
|
|
1369f0ca05 | ||
|
|
372546727d | ||
|
|
324039ba0a | ||
|
|
508f6970a5 | ||
|
|
e6a9d9c802 | ||
|
|
21a6c99c5d | ||
|
|
db4d66086a | ||
|
|
c8087bcc70 | ||
|
|
75db2288ca | ||
|
|
cbfc7d9ca3 | ||
|
|
d846be5128 | ||
|
|
15db109d58 | ||
|
|
94d1202726 | ||
|
|
8e78cd925d | ||
|
|
c6b1d83a14 | ||
|
|
b7877514c6 | ||
|
|
370a350353 | ||
|
|
ba58e0e966 | ||
|
|
106b04e076 | ||
|
|
04947a51f3 | ||
|
|
7d96e1e541 | ||
|
|
5003595d8e | ||
|
|
263c5d855a | ||
|
|
36894fd813 | ||
|
|
a22ff2a7c5 | ||
|
|
8c24449b56 | ||
|
|
0994e6c0d2 | ||
|
|
334f20f7fa | ||
|
|
93d3863084 | ||
|
|
e7ecd94635 | ||
|
|
c253b9d27a | ||
|
|
248e3651e3 | ||
|
|
fd4e8f971f |
+27
-8
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"plugins": ["jest", "@typescript-eslint"],
|
"plugins": ["jest", "@typescript-eslint"],
|
||||||
"extends": ["plugin:github/es6"],
|
"extends": ["plugin:github/recommended","plugin:@typescript-eslint/recommended"],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 9,
|
"ecmaVersion": 9,
|
||||||
@@ -17,13 +17,29 @@
|
|||||||
"@typescript-eslint/no-require-imports": "error",
|
"@typescript-eslint/no-require-imports": "error",
|
||||||
"@typescript-eslint/array-type": "error",
|
"@typescript-eslint/array-type": "error",
|
||||||
"@typescript-eslint/await-thenable": "error",
|
"@typescript-eslint/await-thenable": "error",
|
||||||
"@typescript-eslint/ban-ts-ignore": "error",
|
"@typescript-eslint/ban-ts-comment": "error",
|
||||||
"camelcase": "off",
|
"camelcase": "off",
|
||||||
"@typescript-eslint/camelcase": "error",
|
"@typescript-eslint/naming-convention": [
|
||||||
"@typescript-eslint/class-name-casing": "error",
|
"error",
|
||||||
|
{
|
||||||
|
"selector": "class",
|
||||||
|
"format": ["PascalCase"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"selector": "interface",
|
||||||
|
"format": ["PascalCase"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"selector": "typeProperty",
|
||||||
|
"format": [],
|
||||||
|
"custom": {
|
||||||
|
"regex": "^[A-Z][A-Za-z]*$",
|
||||||
|
"match": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
||||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||||
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
|
|
||||||
"@typescript-eslint/no-array-constructor": "error",
|
"@typescript-eslint/no-array-constructor": "error",
|
||||||
"@typescript-eslint/no-empty-interface": "error",
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
"@typescript-eslint/no-explicit-any": "error",
|
"@typescript-eslint/no-explicit-any": "error",
|
||||||
@@ -33,7 +49,7 @@
|
|||||||
"@typescript-eslint/no-misused-new": "error",
|
"@typescript-eslint/no-misused-new": "error",
|
||||||
"@typescript-eslint/no-namespace": "error",
|
"@typescript-eslint/no-namespace": "error",
|
||||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||||
"@typescript-eslint/no-object-literal-type-assertion": "error",
|
"@typescript-eslint/consistent-type-assertions": "error",
|
||||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||||
"@typescript-eslint/no-useless-constructor": "error",
|
"@typescript-eslint/no-useless-constructor": "error",
|
||||||
@@ -41,7 +57,7 @@
|
|||||||
"@typescript-eslint/prefer-for-of": "warn",
|
"@typescript-eslint/prefer-for-of": "warn",
|
||||||
"@typescript-eslint/prefer-function-type": "warn",
|
"@typescript-eslint/prefer-function-type": "warn",
|
||||||
"@typescript-eslint/prefer-includes": "error",
|
"@typescript-eslint/prefer-includes": "error",
|
||||||
"@typescript-eslint/prefer-interface": "error",
|
"@typescript-eslint/consistent-type-definitions": "error",
|
||||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||||
"@typescript-eslint/promise-function-async": "error",
|
"@typescript-eslint/promise-function-async": "error",
|
||||||
"@typescript-eslint/require-array-sort-compare": "error",
|
"@typescript-eslint/require-array-sort-compare": "error",
|
||||||
@@ -50,7 +66,10 @@
|
|||||||
"@typescript-eslint/semi": ["error", "never"],
|
"@typescript-eslint/semi": ["error", "never"],
|
||||||
"@typescript-eslint/type-annotation-spacing": "error",
|
"@typescript-eslint/type-annotation-spacing": "error",
|
||||||
"@typescript-eslint/unbound-method": "error",
|
"@typescript-eslint/unbound-method": "error",
|
||||||
"no-console": "off"
|
"no-console": "off",
|
||||||
|
"import/no-unresolved": "off",
|
||||||
|
"sort-imports": "off",
|
||||||
|
"filenames/match-regex": "off"
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
- name: Set Node.js 16.x
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 16.x
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: "@actions/core"
|
name: "@actions/core"
|
||||||
version: 1.6.0
|
version: 1.9.1
|
||||||
type: npm
|
type: npm
|
||||||
summary: Actions core lib
|
summary: Actions core lib
|
||||||
homepage: https://github.com/actions/toolkit/tree/master/packages/core
|
homepage: https://github.com/actions/toolkit/tree/master/packages/core
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: rxjs
|
name: rxjs
|
||||||
version: 6.5.4
|
version: 6.6.7
|
||||||
type: npm
|
type: npm
|
||||||
summary: Reactive Extensions for modern JavaScript
|
summary: Reactive Extensions for modern JavaScript
|
||||||
homepage: https://github.com/ReactiveX/RxJS
|
homepage: https://github.com/ReactiveX/RxJS
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
# Delete Package Versions
|
# Delete Package Versions
|
||||||
|
|
||||||
This action deletes versions of a package from [GitHub Packages](https://github.com/features/packages).
|
This action deletes versions of a package from [GitHub Packages](https://github.com/features/packages). This action will only delete a maximum of 99 versions in one run.
|
||||||
|
|
||||||
### What It Can Do
|
### What It Can Do
|
||||||
|
|
||||||
* Create a retention policy (delete all except n most recent pre-release versions)
|
* Create a retention policy (delete all except n most recent pre-release versions)
|
||||||
* Delete all package versions except n most recent versions.
|
* Delete all package versions except n most recent versions
|
||||||
* Delete oldest version(s)
|
* Delete oldest version(s)
|
||||||
* Ignore version(s) from deletion through regex.
|
* Ignore version(s) from deletion through regex
|
||||||
* 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 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
|
* Delete version(s) of a package that is hosted in a different repo than the one executing the workflow
|
||||||
* Delete a single version
|
* Delete a single version
|
||||||
* Delete multiple versions
|
* Delete multiple versions
|
||||||
|
|
||||||
|
|
||||||
* Delete specific version(s)
|
* Delete specific version(s)
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
# Can be a single package version id, or a comma separated list of package version ids.
|
# Can be a single package version id, or a comma separated list of package version ids.
|
||||||
# Defaults to an empty string.
|
# Defaults to an empty string.
|
||||||
@@ -30,26 +28,22 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
# Required if deleting a version from a package hosted in a different repo than the one executing the workflow.
|
# Required if deleting a version from a package hosted in a different repo than the one executing the workflow.
|
||||||
owner:
|
owner:
|
||||||
|
|
||||||
# Repo hosting the package.
|
|
||||||
# Defaults to the repo executing the workflow.
|
|
||||||
# Required if deleting a version from a package hosted in a different repo than the one executing the workflow.
|
|
||||||
repo:
|
|
||||||
|
|
||||||
# Name of the package.
|
# Name of the package.
|
||||||
# Defaults to an empty string.
|
# Required
|
||||||
# Required if `package-version-ids` input is not given.
|
|
||||||
package-name:
|
package-name:
|
||||||
|
|
||||||
|
# Type of the package.
|
||||||
|
# Required
|
||||||
|
package-type:
|
||||||
|
|
||||||
# The number of old versions to delete starting from the oldest version.
|
# The number of old versions to delete starting from the oldest version.
|
||||||
# Defaults to 1.
|
# Defaults to 1.
|
||||||
# Cannot be more than 100.
|
|
||||||
num-old-versions-to-delete:
|
num-old-versions-to-delete:
|
||||||
|
|
||||||
# The number of latest versions to not delete.
|
# The number of latest versions to keep.
|
||||||
# Defaults to 0.
|
# This cannot be specified with `num-old-versions-to-delete`. By default, `num-old-versions-to-delete` takes precedence over `min-versions-to-keep`.
|
||||||
# When this is set greater than 0 it will delete all deletable package versions except the specified no.
|
# When set to 0, all deletable versions will be deleted.
|
||||||
# `num-old-versions-to-delete` will not be taken into account with this option.
|
# When set greater than 0, all deletable package versions except the specified number will be deleted.
|
||||||
# Cannot be more than 100.
|
|
||||||
min-versions-to-keep:
|
min-versions-to-keep:
|
||||||
|
|
||||||
# The package versions to exclude from deletion.
|
# The package versions to exclude from deletion.
|
||||||
@@ -61,6 +55,7 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
# The number of pre-release versions to keep can be set by using `min-versions-to-keep` value with this.
|
# The number of pre-release versions to keep can be set by using `min-versions-to-keep` value with this.
|
||||||
# When `min-versions-to-keep` is 0, all pre-release versions get deleted.
|
# When `min-versions-to-keep` is 0, all pre-release versions get deleted.
|
||||||
# Defaults to false.
|
# Defaults to false.
|
||||||
|
# Cannot be used with `num-old-versions-to-delete` and `ignore-versions`.
|
||||||
delete-only-pre-release-versions:
|
delete-only-pre-release-versions:
|
||||||
|
|
||||||
# The token used to authenticate with GitHub Packages.
|
# The token used to authenticate with GitHub Packages.
|
||||||
@@ -71,6 +66,18 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
token:
|
token:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Valid Input Combinations
|
||||||
|
|
||||||
|
`owner`, `package-name`, `package-type` and `token` can be used with the following combinations in a workflow -
|
||||||
|
|
||||||
|
- `num-old-versions-to-delete`
|
||||||
|
- `min-versions-to-keep`
|
||||||
|
- `delete-only-pre-release-versions`
|
||||||
|
- `ignore-versions`
|
||||||
|
- `num-old-versions-to-delete` + `ignore-versions`
|
||||||
|
- `min-versions-to-keep` + `ignore-versions`
|
||||||
|
- `min-versions-to-keep` + `delete-only-pre-release-versions`
|
||||||
|
|
||||||
# Scenarios
|
# Scenarios
|
||||||
|
|
||||||
- [Delete all pre-release versions except y latest pre-release package versions](#delete-all-pre-release-versions-except-y-latest-pre-release-package-versions)
|
- [Delete all pre-release versions except y latest pre-release package versions](#delete-all-pre-release-versions-except-y-latest-pre-release-package-versions)
|
||||||
@@ -92,13 +99,14 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
Delete all pre-release package versions except latest 10 in the same repo as the workflow
|
Delete all pre-release package versions except latest 10 in the same repo as the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-name: 'test-package'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
min-versions-to-keep: 10
|
min-versions-to-keep: 10
|
||||||
delete-only-pre-release-versions: "true"
|
delete-only-pre-release-versions: "true"
|
||||||
```
|
```
|
||||||
To delete all pre release versions except y latest pre-release package versions in a different repo than the workflow the __owner__, __repo__, __package-name__, __token__, __min-versions-to-keep__ and __delete-only-pre-release-versions__ inputs are required.
|
To delete all pre release versions except y latest pre-release package versions in a different repo than the workflow the __owner__, __package-name__, __token__, __min-versions-to-keep__ and __delete-only-pre-release-versions__ inputs are required.
|
||||||
|
|
||||||
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
||||||
|
|
||||||
@@ -107,11 +115,11 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
Delete all pre-release package versions except latest 10 in a different repo than the workflow
|
Delete all pre-release package versions except latest 10 in a different repo than the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
owner: 'github'
|
owner: 'github'
|
||||||
repo: 'packages'
|
|
||||||
package-name: 'test-package'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
token: ${{ secrets.GITHUB_PAT }}
|
token: ${{ secrets.GITHUB_PAT }}
|
||||||
min-versions-to-keep: 10
|
min-versions-to-keep: 10
|
||||||
delete-only-pre-release-versions: "true"
|
delete-only-pre-release-versions: "true"
|
||||||
@@ -128,14 +136,15 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
Delete all except latest 3 package versions excluding major versions as per semver in the same repo as the workflow
|
Delete all except latest 3 package versions excluding major versions as per semver in the same repo as the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-name: 'test-packae'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
min-versions-to-keep: 3
|
min-versions-to-keep: 3
|
||||||
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
|
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
|
||||||
```
|
```
|
||||||
|
|
||||||
To delete all except y latest versions while ignoring particular package versions in a different repo than the workflow the __owner__, __repo__, __package-name__, __token__, __min-versions-to-keep__ and __ignore-versions__ inputs are required.
|
To delete all except y latest versions while ignoring particular package versions in a different repo than the workflow the __owner__, __package-name__, __token__, __min-versions-to-keep__ and __ignore-versions__ inputs are required.
|
||||||
|
|
||||||
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
||||||
|
|
||||||
@@ -144,11 +153,11 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
Delete all except latest 3 package versions excluding major versions as per semver in a different repo than the workflow
|
Delete all except latest 3 package versions excluding major versions as per semver in a different repo than the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
owner: 'github'
|
owner: 'github'
|
||||||
repo: 'packages'
|
package-name: 'test-package'
|
||||||
package-name: 'test-packae'
|
package-type: 'npm'
|
||||||
token: ${{ secrets.GITHUB_PAT }}
|
token: ${{ secrets.GITHUB_PAT }}
|
||||||
min-versions-to-keep: 3
|
min-versions-to-keep: 3
|
||||||
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
|
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
|
||||||
@@ -167,14 +176,15 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
Delete 3 oldest versions excluding major versions as per semver is the same repo as the workflow
|
Delete 3 oldest versions excluding major versions as per semver is the same repo as the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-name: 'test-packae'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
num-old-versions-to-delete: 3
|
num-old-versions-to-delete: 3
|
||||||
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
|
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
|
||||||
```
|
```
|
||||||
|
|
||||||
To delete oldest x number of versions while ignoring all the major package versions in a different repo than the workflow the __owner__, __repo__, __package-name__, __token__, __num-oldest-versions-to-delete__ and __ignore-versions__ inputs are required.
|
To delete oldest x number of versions while ignoring all the major package versions in a different repo than the workflow the __owner__, __package-name__, __token__, __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 get deleted will be less than x.
|
There is a possibility if the oldest x number of versions contain ignored package versions, actual package versions to get deleted will be less than x.
|
||||||
|
|
||||||
@@ -182,14 +192,14 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
|
|
||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
Delete 3 oldest versions excluding major versions as per semver is a differernt repo than the workflow
|
Delete 3 oldest versions excluding major versions as per semver is a different repo than the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
owner: 'github'
|
owner: 'github'
|
||||||
repo: 'packages'
|
package-name: 'test-package'
|
||||||
package-name: 'test-packae'
|
package-type: 'npm'
|
||||||
token: ${{ secrets.PAT }}
|
token: ${{ secrets.PAT }}
|
||||||
num-old-versions-to-delete: 3
|
num-old-versions-to-delete: 3
|
||||||
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
|
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
|
||||||
@@ -206,13 +216,14 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
Delete all except latest 2 versions of a package hosted in the same repo as the workflow
|
Delete all except latest 2 versions of a package hosted in the same repo as the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-name: 'test-package'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
min-versions-to-keep: 2
|
min-versions-to-keep: 2
|
||||||
```
|
```
|
||||||
|
|
||||||
To delete all except y latest versions of a package hosted in a repo other than the workflow the __owner__, __repo__, __package-name__, __token__ and __min-versions-to-keep__ inputs are required.
|
To delete all except y latest versions of a package hosted in a repo other than the workflow the __owner__, __package-name__, __token__ and __min-versions-to-keep__ inputs are required.
|
||||||
|
|
||||||
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
||||||
|
|
||||||
@@ -221,11 +232,11 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
Delete all except latest 2 versions of a package hosted in a repo other than the workflow
|
Delete all except latest 2 versions of a package hosted in a repo other than the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
owner: 'github'
|
owner: 'github'
|
||||||
repo: 'packages'
|
|
||||||
package-name: 'test-package'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
token: ${{ secrets.PAT }}
|
token: ${{ secrets.PAT }}
|
||||||
min-versions-to-keep: 2
|
min-versions-to-keep: 2
|
||||||
```
|
```
|
||||||
@@ -241,13 +252,14 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
Delete the oldest 3 version of a package hosted in the same repo as the workflow
|
Delete the oldest 3 version of a package hosted in the same repo as the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-name: 'test-package'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
num-old-versions-to-delete: 3
|
num-old-versions-to-delete: 3
|
||||||
```
|
```
|
||||||
|
|
||||||
To delete the oldest x number of versions of a package hosted in a different repo than the workflow the __owner__, __repo__, __package-name__, __token__ and __num-old-versions-to-delete__ inputs are required.
|
To delete the oldest x number of versions of a package hosted in a different repo than the workflow the __owner__, __package-name__, __token__ and __num-old-versions-to-delete__ inputs are required.
|
||||||
|
|
||||||
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
||||||
|
|
||||||
@@ -256,11 +268,11 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
Delete the oldest 3 version of a package hosted in a different repo than the one executing the workflow
|
Delete the oldest 3 version of a package hosted in a different repo than the one executing the workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
owner: 'github'
|
owner: 'github'
|
||||||
repo: 'packages'
|
|
||||||
package-name: 'test-package'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
num-old-versions-to-delete: 3
|
num-old-versions-to-delete: 3
|
||||||
token: ${{ secrets.GITHUB_PAT }}
|
token: ${{ secrets.GITHUB_PAT }}
|
||||||
```
|
```
|
||||||
@@ -274,23 +286,24 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-name: 'test-package'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
```
|
```
|
||||||
|
|
||||||
To delete the oldest version of a package that is hosted in a different repo than the workflow the __owner__, __repo__, __package-name__, __token__ inputs are required.
|
To delete the oldest version of a package that is hosted in a different repo than the workflow the __owner__, __package-name__, __token__ inputs are required.
|
||||||
|
|
||||||
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
The [token][token] needs the delete packages and read packages scope. It is recommended [to store the token as a secret][secret]. In this example the [token][token] was stored as a secret named __GITHUB_PAT__.
|
||||||
|
|
||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
owner: 'github'
|
owner: 'github'
|
||||||
repo: 'packages'
|
|
||||||
package-name: 'test-package'
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
token: ${{ secrets.PAT }}
|
token: ${{ secrets.PAT }}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -305,9 +318,11 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3'
|
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3'
|
||||||
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
```
|
```
|
||||||
|
|
||||||
To delete a specific version of a package that is hosted in a different repo than the workflow the __package-version-ids__ and __token__ inputs are required.
|
To delete a specific version of a package that is hosted in a different repo than the workflow the __package-version-ids__ and __token__ inputs are required.
|
||||||
@@ -319,9 +334,11 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3'
|
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3'
|
||||||
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
token: ${{ secrets.PAT }}
|
token: ${{ secrets.PAT }}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -329,19 +346,21 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
|
|
||||||
### Delete multiple specific versions of a package
|
### Delete multiple specific versions of a package
|
||||||
|
|
||||||
To delete multiple specifc versions of a package that is hosted in the same repo as the workflow the __package-version-ids__ input is required.
|
To delete multiple specific versions of a package that is hosted in the same repo as the workflow the __package-version-ids__ input is required.
|
||||||
|
|
||||||
The __package-version-ids__ input should be a comma separated string of package version ids. Package version ids can be retrieved via the [GitHub GraphQL API][api].
|
The __package-version-ids__ input should be a comma separated string of package version ids. Package version ids can be retrieved via the [GitHub GraphQL API][api].
|
||||||
|
|
||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw'
|
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw'
|
||||||
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
```
|
```
|
||||||
|
|
||||||
To delete multiple specifc versions of a package that is hosted in a repo other than the workflow the __package-version-ids__, __token__ inputs are required.
|
To delete multiple specific versions of a package that is hosted in a repo other than the workflow the __package-version-ids__, __token__ inputs are required.
|
||||||
|
|
||||||
The __package-version-ids__ input should be a comma separated string of package version ids. Package version ids can be retrieved via the [GitHub GraphQL API][api].
|
The __package-version-ids__ input should be a comma separated string of package version ids. Package version ids can be retrieved via the [GitHub GraphQL API][api].
|
||||||
|
|
||||||
@@ -350,9 +369,11 @@ This action deletes versions of a package from [GitHub Packages](https://github.
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/delete-package-versions@v2
|
- uses: actions/delete-package-versions@v3
|
||||||
with:
|
with:
|
||||||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw'
|
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw'
|
||||||
|
package-name: 'test-package'
|
||||||
|
package-type: 'npm'
|
||||||
token: ${{ secrets.PAT }}
|
token: ${{ secrets.PAT }}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -363,3 +384,4 @@ The scripts and documentation in this project are released under the [MIT Licens
|
|||||||
[api]: https://developer.github.com/v4/previews/#github-packages
|
[api]: https://developer.github.com/v4/previews/#github-packages
|
||||||
[token]: https://help.github.com/en/packages/publishing-and-managing-packages/about-github-packages#about-tokens
|
[token]: https://help.github.com/en/packages/publishing-and-managing-packages/about-github-packages#about-tokens
|
||||||
[secret]: https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
|
[secret]: https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
|
||||||
|
|
||||||
|
|||||||
+38
-35
@@ -1,37 +1,40 @@
|
|||||||
import {Input, InputParams} from '../src/input'
|
import {Input, InputParams} from '../src/input'
|
||||||
import {deleteVersions, getVersionIds} from '../src/delete'
|
import {deleteVersions, finalIds} from '../src/delete'
|
||||||
|
|
||||||
describe.skip('index tests -- call graphql', () => {
|
describe.skip('index tests -- call graphql', () => {
|
||||||
it('getVersionIds test -- get oldest version', done => {
|
it('finalIds test -- get oldest version', done => {
|
||||||
const numVersions = 1
|
const numVersions = 1
|
||||||
|
|
||||||
getVersionIds(getInput({numOldVersionsToDelete: numVersions})).subscribe(
|
finalIds(getInput({numOldVersionsToDelete: numVersions})).subscribe(ids => {
|
||||||
ids => {
|
expect(ids.length).toBe(numVersions)
|
||||||
expect(ids.length).toBeLessThanOrEqual(numVersions)
|
|
||||||
done()
|
done()
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('getVersionIds test -- get oldest 3 versions', done => {
|
it.skip('finalIds test -- get oldest 3 versions', done => {
|
||||||
const numVersions = 3
|
const numVersions = 3
|
||||||
|
finalIds(getInput({numOldVersionsToDelete: numVersions})).subscribe(ids => {
|
||||||
getVersionIds(getInput({numOldVersionsToDelete: numVersions})).subscribe(
|
expect(ids.length).toBe(numVersions)
|
||||||
ids => {
|
|
||||||
expect(ids.length).toBeLessThanOrEqual(numVersions)
|
|
||||||
done()
|
done()
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('getVersionIds test -- supplied package version id', done => {
|
it.skip('finalIds test -- get oldest 110 versions', done => {
|
||||||
|
const numVersions = 110
|
||||||
|
|
||||||
|
finalIds(getInput({numOldVersionsToDelete: numVersions})).subscribe(ids => {
|
||||||
|
expect(ids.length).toBe(99), async () => done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('finalIds test -- supplied package version id', done => {
|
||||||
const suppliedIds = [
|
const suppliedIds = [
|
||||||
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||||
'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
|
'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
|
||||||
'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC'
|
'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC'
|
||||||
]
|
]
|
||||||
|
|
||||||
getVersionIds(getInput({packageVersionIds: suppliedIds})).subscribe(ids => {
|
finalIds(getInput({packageVersionIds: suppliedIds})).subscribe(ids => {
|
||||||
expect(ids).toBe(suppliedIds)
|
expect(ids).toBe(suppliedIds)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
@@ -58,38 +61,38 @@ describe.skip('index tests -- call graphql', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it.skip('deleteVersions test -- delete oldest version', done => {
|
it.skip('deleteVersions test -- delete oldest version', done => {
|
||||||
deleteVersions(
|
deleteVersions(getInput({numOldVersionsToDelete: 1})).subscribe(
|
||||||
getInput({numOldVersionsToDelete: 2, minVersionsToKeep: 1})
|
isSuccess => {
|
||||||
).subscribe(isSuccess => {
|
expect(isSuccess)
|
||||||
expect(isSuccess).toBe(true)
|
},
|
||||||
done()
|
async () => done()
|
||||||
})
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it.skip('deleteVersions test -- delete 3 oldest versions', done => {
|
it.skip('deleteVersions test -- delete 3 oldest versions', done => {
|
||||||
deleteVersions(
|
deleteVersions(getInput({numOldVersionsToDelete: 3})).subscribe(
|
||||||
getInput({numOldVersionsToDelete: 3, minVersionsToKeep: 1})
|
isSuccess => {
|
||||||
).subscribe(isSuccess => {
|
expect(isSuccess)
|
||||||
expect(isSuccess).toBe(true)
|
},
|
||||||
done()
|
async () => done()
|
||||||
})
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('deleteVersions test -- keep 5 versions', done => {
|
it.skip('deleteVersions test -- keep 5 versions', done => {
|
||||||
deleteVersions(getInput({minVersionsToKeep: 5})).subscribe(isSuccess => {
|
deleteVersions(getInput({minVersionsToKeep: 100})).subscribe(isSuccess => {
|
||||||
expect(isSuccess).toBe(true)
|
expect(isSuccess).toBe(true)
|
||||||
done()
|
}),
|
||||||
})
|
async () => done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const defaultInput: InputParams = {
|
const defaultInput: InputParams = {
|
||||||
packageVersionIds: [],
|
packageVersionIds: [],
|
||||||
owner: 'namratajha',
|
owner: 'namratajha',
|
||||||
repo: 'only-pkg',
|
packageName: 'only-pkg',
|
||||||
packageName: 'onlypkg.maven',
|
|
||||||
numOldVersionsToDelete: 1,
|
numOldVersionsToDelete: 1,
|
||||||
minVersionsToKeep: 1,
|
minVersionsToKeep: -1,
|
||||||
|
ignoreVersions: RegExp('^$'),
|
||||||
token: process.env.GITHUB_TOKEN as string
|
token: process.env.GITHUB_TOKEN as string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import {deletePackageVersion, deletePackageVersions} from '../../src/version'
|
|
||||||
|
|
||||||
const githubToken = process.env.GITHUB_TOKEN as string
|
|
||||||
|
|
||||||
describe.skip('delete tests', () => {
|
|
||||||
it('deletePackageVersion', async () => {
|
|
||||||
const response = await deletePackageVersion(
|
|
||||||
'MDE0OlBhY2thZ2VWZXJzaW9uNjg5OTU1',
|
|
||||||
githubToken
|
|
||||||
).toPromise()
|
|
||||||
expect(response).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('deletePackageVersions', async () => {
|
|
||||||
const response = await deletePackageVersions(
|
|
||||||
[
|
|
||||||
'MDE0OlBhY2thZ2VWZXJzaW9uNjk4Mjc0',
|
|
||||||
'MDE0OlBhY2thZ2VWZXJzaW9uNjk4Mjcx',
|
|
||||||
'MDE0OlBhY2thZ2VWZXJzaW9uNjk4MjY3'
|
|
||||||
],
|
|
||||||
githubToken
|
|
||||||
).toPromise()
|
|
||||||
expect(response).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
||||||
// @ts-ignore
|
|
||||||
import {mockOldestQueryResponse} from './graphql.mock'
|
|
||||||
import {
|
|
||||||
getOldestVersions as _getOldestVersions,
|
|
||||||
VersionInfo
|
|
||||||
} from '../../src/version'
|
|
||||||
import {Observable} from 'rxjs'
|
|
||||||
|
|
||||||
describe.skip('get versions tests -- call graphql', () => {
|
|
||||||
it('getOldestVersions -- succeeds', done => {
|
|
||||||
const numVersions = 1
|
|
||||||
|
|
||||||
getOldestVersions({numVersions}).subscribe(versions => {
|
|
||||||
expect(versions.length).toBe(numVersions)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('getOldestVersions -- fails for invalid repo', done => {
|
|
||||||
getOldestVersions({repo: 'actions-testin'}).subscribe({
|
|
||||||
error: err => {
|
|
||||||
expect(err).toBeTruthy()
|
|
||||||
done()
|
|
||||||
},
|
|
||||||
complete: async () => done.fail('no error thrown')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('get versions tests -- mock graphql', () => {
|
|
||||||
it('getOldestVersions -- success', done => {
|
|
||||||
const numVersions = 5
|
|
||||||
mockOldestQueryResponse(numVersions)
|
|
||||||
|
|
||||||
getOldestVersions({numVersions}).subscribe(versions => {
|
|
||||||
expect(versions.length).toBe(numVersions)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
interface Params {
|
|
||||||
owner?: string
|
|
||||||
repo?: string
|
|
||||||
packageName?: string
|
|
||||||
numVersions?: number
|
|
||||||
token?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultParams = {
|
|
||||||
owner: 'namratajha',
|
|
||||||
repo: 'only-pkg',
|
|
||||||
packageName: 'onlypkg.maven',
|
|
||||||
numVersions: 3,
|
|
||||||
token: process.env.GITHUB_TOKEN as string
|
|
||||||
}
|
|
||||||
|
|
||||||
function getOldestVersions(params?: Params): Observable<VersionInfo[]> {
|
|
||||||
const p: Required<Params> = {...defaultParams, ...params}
|
|
||||||
return _getOldestVersions(
|
|
||||||
p.owner,
|
|
||||||
p.repo,
|
|
||||||
p.packageName,
|
|
||||||
p.numVersions,
|
|
||||||
p.token
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ export function getMockedOldestQueryResponse(
|
|||||||
numVersions: number
|
numVersions: number
|
||||||
): GetVersionsQueryResponse {
|
): GetVersionsQueryResponse {
|
||||||
const versions = []
|
const versions = []
|
||||||
|
numVersions = numVersions < 100 ? numVersions : numVersions
|
||||||
for (let i = 1; i <= numVersions; ++i) {
|
for (let i = 1; i <= numVersions; ++i) {
|
||||||
versions.push({
|
versions.push({
|
||||||
node: {
|
node: {
|
||||||
@@ -28,7 +28,12 @@ export function getMockedOldestQueryResponse(
|
|||||||
node: {
|
node: {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
versions: {
|
versions: {
|
||||||
edges: versions.reverse()
|
totalCount: 200,
|
||||||
|
edges: versions.reverse(),
|
||||||
|
pageInfo: {
|
||||||
|
startCursor: 'AAA',
|
||||||
|
hasPreviousPage: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,12 +43,13 @@ export function getMockedOldestQueryResponse(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockOldestQueryResponse(
|
export function mockOldestQueryResponse(numVersions: number): void {
|
||||||
numVersions: number
|
const response = new Promise<GetVersionsQueryResponse>(resolve => {
|
||||||
) {
|
|
||||||
const response = new Promise((resolve) => {
|
|
||||||
resolve(getMockedOldestQueryResponse(numVersions))
|
resolve(getMockedOldestQueryResponse(numVersions))
|
||||||
}) as Promise<GraphQlQueryResponseData>
|
}) as Promise<GraphQlQueryResponseData>
|
||||||
jest.spyOn(Graphql, 'graphql').mockImplementation(
|
jest
|
||||||
(token: string, query: string, parameters: RequestParameters) => response)
|
.spyOn(Graphql, 'graphql')
|
||||||
|
.mockImplementation(
|
||||||
|
(token: string, query: string, parameters: RequestParameters) => response
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-6
@@ -24,8 +24,12 @@ inputs:
|
|||||||
package-name:
|
package-name:
|
||||||
description: >
|
description: >
|
||||||
Name of the package containing the version to delete.
|
Name of the package containing the version to delete.
|
||||||
Required if dynamically deleting oldest versions.
|
required: true
|
||||||
required: false
|
|
||||||
|
package-type:
|
||||||
|
description: >
|
||||||
|
Type of the package containing the version to delete.
|
||||||
|
required: true
|
||||||
|
|
||||||
num-old-versions-to-delete:
|
num-old-versions-to-delete:
|
||||||
description: >
|
description: >
|
||||||
@@ -37,9 +41,10 @@ inputs:
|
|||||||
min-versions-to-keep:
|
min-versions-to-keep:
|
||||||
description: >
|
description: >
|
||||||
Number of versions to keep starting with the latest version
|
Number of versions to keep starting with the latest version
|
||||||
Defaults to 0.
|
By default keeps no version.
|
||||||
|
To delete all versions set this as 0.
|
||||||
required: false
|
required: false
|
||||||
default: "0"
|
default: "-1"
|
||||||
|
|
||||||
ignore-versions:
|
ignore-versions:
|
||||||
description: >
|
description: >
|
||||||
@@ -50,7 +55,7 @@ inputs:
|
|||||||
|
|
||||||
delete-only-pre-release-versions:
|
delete-only-pre-release-versions:
|
||||||
description: >
|
description: >
|
||||||
Deletes only pre-release versions upto. The number of pre-release versions to keep can be specified by min-versions-to-keep.
|
Deletes only pre-release versions. The number of pre-release versions to keep can be specified by min-versions-to-keep.
|
||||||
When this is set num-old-versions-to-delete and ignore-versions will not be taken into account.
|
When this is set num-old-versions-to-delete and ignore-versions will not be taken into account.
|
||||||
By default this is set to false
|
By default this is set to false
|
||||||
required: false
|
required: false
|
||||||
@@ -66,7 +71,7 @@ inputs:
|
|||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: node12
|
using: node16
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
|
|||||||
Vendored
+11121
-7543
File diff suppressed because one or more lines are too long
Generated
+13705
-3844
File diff suppressed because it is too large
Load Diff
+8
-6
@@ -7,9 +7,10 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check **/*.ts",
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts --fix",
|
||||||
|
"lint-check": "eslint src/**/*.ts",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"build": "npm run format-check && npm run lint && npm run test && tsc",
|
"build": "npm run format-check && npm run lint-check && npm run test && tsc",
|
||||||
"pack": "rm -rf ./lib ./dist && npm run build && ncc build"
|
"pack": "rm -rf ./lib ./dist && npm run build && ncc build"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -24,17 +25,18 @@
|
|||||||
"author": "YourNameOrOrganization",
|
"author": "YourNameOrOrganization",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.6.0",
|
"@actions/core": "^1.9.1",
|
||||||
"@actions/github": "^2.1.1",
|
"@actions/github": "^2.1.1",
|
||||||
|
"@octokit/rest": "^19.0.5",
|
||||||
"rxjs": "^6.5.4"
|
"rxjs": "^6.5.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^24.0.23",
|
"@types/jest": "^27.4.0",
|
||||||
"@types/node": "^12.7.12",
|
"@types/node": "^12.7.12",
|
||||||
"@typescript-eslint/parser": "^2.8.0",
|
"@typescript-eslint/parser": "^2.8.0",
|
||||||
"@vercel/ncc": "^0.31.1",
|
"@vercel/ncc": "^0.31.1",
|
||||||
"eslint": "^5.16.0",
|
"eslint": "^8.9.0",
|
||||||
"eslint-plugin-github": "^2.0.0",
|
"eslint-plugin-github": "^4.3.5",
|
||||||
"eslint-plugin-jest": "^22.21.0",
|
"eslint-plugin-jest": "^22.21.0",
|
||||||
"jest": "^27.3.1",
|
"jest": "^27.3.1",
|
||||||
"jest-circus": "^27.3.1",
|
"jest-circus": "^27.3.1",
|
||||||
|
|||||||
+94
-30
@@ -1,46 +1,96 @@
|
|||||||
|
/* eslint-disable i18n-text/no-en */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
import {Input} from './input'
|
import {Input} from './input'
|
||||||
import {Observable, of, throwError} from 'rxjs'
|
import {EMPTY, Observable, of, throwError} from 'rxjs'
|
||||||
import {deletePackageVersions, getOldestVersions} from './version'
|
import {reduce} from 'rxjs/operators'
|
||||||
import {concatMap, map} from 'rxjs/operators'
|
import {
|
||||||
|
deletePackageVersions,
|
||||||
|
getOldestVersions,
|
||||||
|
RestVersionInfo
|
||||||
|
} from './version'
|
||||||
|
import {concatMap, map, expand, tap} from 'rxjs/operators'
|
||||||
|
|
||||||
export function getVersionIds(input: Input): Observable<string[]> {
|
const RATE_LIMIT = 99
|
||||||
|
let totalCount = 0
|
||||||
|
|
||||||
|
export function getVersionIds(
|
||||||
|
owner: string,
|
||||||
|
packageName: string,
|
||||||
|
packageType: string,
|
||||||
|
numVersions: number,
|
||||||
|
page: number,
|
||||||
|
token: string
|
||||||
|
): Observable<RestVersionInfo[]> {
|
||||||
|
return getOldestVersions(
|
||||||
|
owner,
|
||||||
|
packageName,
|
||||||
|
packageType,
|
||||||
|
numVersions,
|
||||||
|
page,
|
||||||
|
token
|
||||||
|
).pipe(
|
||||||
|
expand(value =>
|
||||||
|
value.paginate
|
||||||
|
? getOldestVersions(
|
||||||
|
owner,
|
||||||
|
packageName,
|
||||||
|
packageType,
|
||||||
|
numVersions,
|
||||||
|
value.page + 1,
|
||||||
|
token
|
||||||
|
)
|
||||||
|
: EMPTY
|
||||||
|
),
|
||||||
|
tap(value => (totalCount = totalCount + value.totalCount)),
|
||||||
|
reduce((acc, value) => acc.concat(value.versions), [] as RestVersionInfo[])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function finalIds(input: Input): Observable<string[]> {
|
||||||
if (input.packageVersionIds.length > 0) {
|
if (input.packageVersionIds.length > 0) {
|
||||||
return of(input.packageVersionIds)
|
return of(input.packageVersionIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.hasOldestVersionQueryInfo()) {
|
if (input.hasOldestVersionQueryInfo()) {
|
||||||
return getOldestVersions(
|
return getVersionIds(
|
||||||
input.owner,
|
input.owner,
|
||||||
input.repo,
|
|
||||||
input.packageName,
|
input.packageName,
|
||||||
input.numOldVersionsToDelete + input.minVersionsToKeep,
|
input.packageType,
|
||||||
|
RATE_LIMIT,
|
||||||
|
1,
|
||||||
input.token
|
input.token
|
||||||
).pipe(
|
).pipe(
|
||||||
map(versionInfo => {
|
// This code block executes on all versions of a package starting from oldest
|
||||||
const numberVersionsToDelete =
|
map(value => {
|
||||||
versionInfo.length - input.minVersionsToKeep
|
// we need to delete oldest versions first
|
||||||
|
value.sort((a, b) => {
|
||||||
if (input.minVersionsToKeep > 0) {
|
return (
|
||||||
return numberVersionsToDelete <= 0
|
new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
|
||||||
? []
|
)
|
||||||
: versionInfo
|
})
|
||||||
.filter(info => !input.ignoreVersions.test(info.version))
|
/*
|
||||||
.map(info => info.id)
|
Here first filter out the versions that are to be ignored.
|
||||||
.slice(0, -input.minVersionsToKeep)
|
Then update input.numOldeVersionsToDelete to the no of versions deleted from the next 100 versions batch.
|
||||||
|
*/
|
||||||
|
value = value.filter(info => !input.ignoreVersions.test(info.version))
|
||||||
|
let toDelete = 0
|
||||||
|
if (input.minVersionsToKeep < 0) {
|
||||||
|
toDelete = Math.min(
|
||||||
|
value.length,
|
||||||
|
Math.min(input.numOldVersionsToDelete, RATE_LIMIT)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
return numberVersionsToDelete <= 0
|
toDelete = Math.min(
|
||||||
? []
|
value.length - input.minVersionsToKeep,
|
||||||
: versionInfo
|
RATE_LIMIT
|
||||||
.filter(info => !input.ignoreVersions.test(info.version))
|
)
|
||||||
.map(info => info.id)
|
|
||||||
.slice(0, numberVersionsToDelete)
|
|
||||||
}
|
}
|
||||||
|
if (toDelete < 0) return []
|
||||||
|
return value.map(info => info.id.toString()).slice(0, toDelete)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return throwError(
|
return throwError(
|
||||||
"Could not get packageVersionIds. Explicitly specify using the 'package-version-ids' input or provide the 'package-name' and 'num-old-versions-to-delete' inputs to dynamically retrieve oldest versions"
|
"Could not get packageVersionIds. Explicitly specify using the 'package-version-ids' input"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,14 +99,28 @@ export function deleteVersions(input: Input): Observable<boolean> {
|
|||||||
return throwError('No token found')
|
return throwError('No token found')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.numOldVersionsToDelete <= 0) {
|
if (!input.checkInput()) {
|
||||||
|
return throwError('Invalid input combination')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.numOldVersionsToDelete <= 0 && input.minVersionsToKeep < 0) {
|
||||||
console.log(
|
console.log(
|
||||||
'Number of old versions to delete input is 0 or less, no versions will be deleted'
|
'Number of old versions to delete input is 0 or less, no versions will be deleted'
|
||||||
)
|
)
|
||||||
return of(true)
|
return of(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
return getVersionIds(input).pipe(
|
const result = finalIds(input)
|
||||||
concatMap(ids => deletePackageVersions(ids, input.token))
|
|
||||||
|
return result.pipe(
|
||||||
|
concatMap(ids =>
|
||||||
|
deletePackageVersions(
|
||||||
|
ids,
|
||||||
|
input.owner,
|
||||||
|
input.packageName,
|
||||||
|
input.packageType,
|
||||||
|
input.token
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-16
@@ -1,8 +1,8 @@
|
|||||||
export interface InputParams {
|
export interface InputParams {
|
||||||
packageVersionIds?: string[]
|
packageVersionIds?: string[]
|
||||||
owner?: string
|
owner?: string
|
||||||
repo?: string
|
|
||||||
packageName?: string
|
packageName?: string
|
||||||
|
packageType?: string
|
||||||
numOldVersionsToDelete?: number
|
numOldVersionsToDelete?: number
|
||||||
minVersionsToKeep?: number
|
minVersionsToKeep?: number
|
||||||
ignoreVersions?: RegExp
|
ignoreVersions?: RegExp
|
||||||
@@ -13,8 +13,8 @@ export interface InputParams {
|
|||||||
const defaultParams = {
|
const defaultParams = {
|
||||||
packageVersionIds: [],
|
packageVersionIds: [],
|
||||||
owner: '',
|
owner: '',
|
||||||
repo: '',
|
|
||||||
packageName: '',
|
packageName: '',
|
||||||
|
packageType: '',
|
||||||
numOldVersionsToDelete: 0,
|
numOldVersionsToDelete: 0,
|
||||||
minVersionsToKeep: 0,
|
minVersionsToKeep: 0,
|
||||||
ignoreVersions: new RegExp(''),
|
ignoreVersions: new RegExp(''),
|
||||||
@@ -25,45 +25,61 @@ const defaultParams = {
|
|||||||
export class Input {
|
export class Input {
|
||||||
packageVersionIds: string[]
|
packageVersionIds: string[]
|
||||||
owner: string
|
owner: string
|
||||||
repo: string
|
|
||||||
packageName: string
|
packageName: string
|
||||||
|
packageType: string
|
||||||
numOldVersionsToDelete: number
|
numOldVersionsToDelete: number
|
||||||
minVersionsToKeep: number
|
minVersionsToKeep: number
|
||||||
ignoreVersions: RegExp
|
ignoreVersions: RegExp
|
||||||
deletePreReleaseVersions: string
|
deletePreReleaseVersions: string
|
||||||
token: string
|
token: string
|
||||||
|
numDeleted: number
|
||||||
|
|
||||||
constructor(params?: InputParams) {
|
constructor(params?: InputParams) {
|
||||||
const validatedParams: Required<InputParams> = {...defaultParams, ...params}
|
const validatedParams: Required<InputParams> = {...defaultParams, ...params}
|
||||||
|
|
||||||
this.packageVersionIds = validatedParams.packageVersionIds
|
this.packageVersionIds = validatedParams.packageVersionIds
|
||||||
this.owner = validatedParams.owner
|
this.owner = validatedParams.owner
|
||||||
this.repo = validatedParams.repo
|
|
||||||
this.packageName = validatedParams.packageName
|
this.packageName = validatedParams.packageName
|
||||||
|
this.packageType = validatedParams.packageType
|
||||||
this.numOldVersionsToDelete = validatedParams.numOldVersionsToDelete
|
this.numOldVersionsToDelete = validatedParams.numOldVersionsToDelete
|
||||||
this.minVersionsToKeep = validatedParams.minVersionsToKeep
|
this.minVersionsToKeep = validatedParams.minVersionsToKeep
|
||||||
this.ignoreVersions = validatedParams.ignoreVersions
|
this.ignoreVersions = validatedParams.ignoreVersions
|
||||||
this.deletePreReleaseVersions = validatedParams.deletePreReleaseVersions
|
this.deletePreReleaseVersions = validatedParams.deletePreReleaseVersions
|
||||||
this.token = validatedParams.token
|
this.token = validatedParams.token
|
||||||
|
this.numDeleted = 0
|
||||||
if (this.minVersionsToKeep > 0) {
|
|
||||||
this.numOldVersionsToDelete = 100 - this.minVersionsToKeep
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.deletePreReleaseVersions == 'true') {
|
|
||||||
this.numOldVersionsToDelete = 100 - this.minVersionsToKeep
|
|
||||||
this.ignoreVersions = new RegExp('^(0|[1-9]\\d*)((\\.(0|[1-9]\\d*))*)$')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hasOldestVersionQueryInfo(): boolean {
|
hasOldestVersionQueryInfo(): boolean {
|
||||||
return !!(
|
return !!(
|
||||||
this.owner &&
|
this.owner &&
|
||||||
this.repo &&
|
|
||||||
this.packageName &&
|
this.packageName &&
|
||||||
this.numOldVersionsToDelete > 0 &&
|
this.numOldVersionsToDelete >= 0 &&
|
||||||
this.minVersionsToKeep >= 0 &&
|
|
||||||
this.token
|
this.token
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkInput(): boolean {
|
||||||
|
if (
|
||||||
|
this.numOldVersionsToDelete > 1 &&
|
||||||
|
(this.minVersionsToKeep >= 0 || this.deletePreReleaseVersions === 'true')
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.packageType === '' || this.packageName === '') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.deletePreReleaseVersions === 'true') {
|
||||||
|
this.minVersionsToKeep =
|
||||||
|
this.minVersionsToKeep > 0 ? this.minVersionsToKeep : 0
|
||||||
|
this.ignoreVersions = new RegExp('^(0|[1-9]\\d*)((\\.(0|[1-9]\\d*))*)$')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.minVersionsToKeep >= 0) {
|
||||||
|
this.numOldVersionsToDelete = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
import {getInput, setFailed} from '@actions/core'
|
import {getInput, setFailed} from '@actions/core'
|
||||||
import {context} from '@actions/github'
|
import {context} from '@actions/github'
|
||||||
import {Input} from './input'
|
import {Input} from './input'
|
||||||
@@ -11,8 +12,8 @@ function getActionInput(): Input {
|
|||||||
? getInput('package-version-ids').split(',')
|
? getInput('package-version-ids').split(',')
|
||||||
: [],
|
: [],
|
||||||
owner: getInput('owner') ? getInput('owner') : context.repo.owner,
|
owner: getInput('owner') ? getInput('owner') : context.repo.owner,
|
||||||
repo: getInput('repo') ? getInput('repo') : context.repo.repo,
|
|
||||||
packageName: getInput('package-name'),
|
packageName: getInput('package-name'),
|
||||||
|
packageType: getInput('package-type'),
|
||||||
numOldVersionsToDelete: Number(getInput('num-old-versions-to-delete')),
|
numOldVersionsToDelete: Number(getInput('num-old-versions-to-delete')),
|
||||||
minVersionsToKeep: Number(getInput('min-versions-to-keep')),
|
minVersionsToKeep: Number(getInput('min-versions-to-keep')),
|
||||||
ignoreVersions: RegExp(getInput('ignore-versions')),
|
ignoreVersions: RegExp(getInput('ignore-versions')),
|
||||||
@@ -29,8 +30,11 @@ function run(): Observable<boolean> {
|
|||||||
catchError(err => throwError(err))
|
catchError(err => throwError(err))
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
return throwError(error.message)
|
return throwError(error.message)
|
||||||
}
|
}
|
||||||
|
return throwError(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run().subscribe({
|
run().subscribe({
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import * as github from '@actions/github'
|
||||||
|
|
||||||
|
// Centralize all Octokit references by re-exporting
|
||||||
|
export {Octokit} from '@octokit/rest'
|
||||||
|
|
||||||
|
export interface OctokitOptions {
|
||||||
|
baseUrl?: string
|
||||||
|
userAgent?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getOctokit(
|
||||||
|
authToken: string,
|
||||||
|
opts: OctokitOptions
|
||||||
|
): github.GitHub {
|
||||||
|
const options: OctokitOptions = {
|
||||||
|
baseUrl: 'https://api.github.com'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts.userAgent) {
|
||||||
|
options.userAgent = opts.userAgent
|
||||||
|
}
|
||||||
|
|
||||||
|
return new github.GitHub(authToken, options)
|
||||||
|
}
|
||||||
@@ -1,65 +1,66 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
import {from, Observable, merge, throwError, of} from 'rxjs'
|
import {from, Observable, merge, throwError, of} from 'rxjs'
|
||||||
import {catchError, map, tap} from 'rxjs/operators'
|
import {catchError, map, tap} from 'rxjs/operators'
|
||||||
import {GraphQlQueryResponse} from '@octokit/graphql/dist-types/types'
|
import {Octokit} from '@octokit/rest'
|
||||||
import {graphql} from './graphql'
|
import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types'
|
||||||
|
|
||||||
export interface DeletePackageVersionMutationResponse {
|
let deleted = 0
|
||||||
deletePackageVersion: {
|
type PackageType = RestEndpointMethodTypes['packages']['getAllPackageVersionsForPackageOwnedByUser']['parameters']['package_type']
|
||||||
success: boolean
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const mutation = `
|
|
||||||
mutation deletePackageVersion($packageVersionId: String!) {
|
|
||||||
deletePackageVersion(input: {packageVersionId: $packageVersionId}) {
|
|
||||||
success
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
export function deletePackageVersion(
|
export function deletePackageVersion(
|
||||||
packageVersionId: string,
|
packageVersionId: string,
|
||||||
|
owner: string,
|
||||||
|
packageName: string,
|
||||||
|
packageType: string,
|
||||||
token: string
|
token: string
|
||||||
): Observable<boolean> {
|
): Observable<boolean> {
|
||||||
|
const octokit = new Octokit({
|
||||||
|
auth: token
|
||||||
|
})
|
||||||
|
const package_version_id = +packageVersionId
|
||||||
|
const package_type: PackageType = packageType as PackageType
|
||||||
|
deleted += 1
|
||||||
|
|
||||||
return from(
|
return from(
|
||||||
graphql(token, mutation, {
|
octokit.rest.packages.deletePackageVersionForUser({
|
||||||
packageVersionId,
|
package_type,
|
||||||
headers: {
|
package_name: packageName,
|
||||||
Accept: 'application/vnd.github.package-deletes-preview+json'
|
username: owner,
|
||||||
}
|
package_version_id
|
||||||
}) as Promise<DeletePackageVersionMutationResponse>
|
})
|
||||||
).pipe(
|
).pipe(
|
||||||
catchError((err: GraphQlQueryResponse) => {
|
catchError(err => {
|
||||||
const msg = 'delete version mutation failed.'
|
const msg = 'delete version API failed.'
|
||||||
return throwError(
|
return throwError(
|
||||||
err.errors && err.errors.length > 0
|
err.errors && err.errors.length > 0
|
||||||
? `${msg} ${err.errors[0].message}`
|
? `${msg} ${err.errors[0].message}`
|
||||||
: `${msg} verify input parameters are correct`
|
: `${msg} ${err.message} \n${deleted - 1} versions deleted till now.`
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
map(response => response.deletePackageVersion.success)
|
map(response => response.status === 204)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deletePackageVersions(
|
export function deletePackageVersions(
|
||||||
packageVersionIds: string[],
|
packageVersionIds: string[],
|
||||||
|
owner: string,
|
||||||
|
packageName: string,
|
||||||
|
packageType: string,
|
||||||
token: string
|
token: string
|
||||||
): Observable<boolean> {
|
): Observable<boolean> {
|
||||||
if (packageVersionIds.length === 0) {
|
if (packageVersionIds.length === 0) {
|
||||||
console.log('no package version ids found, no versions will be deleted')
|
|
||||||
return of(true)
|
return of(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const deletes = packageVersionIds.map(id =>
|
const deletes = packageVersionIds.map(id =>
|
||||||
deletePackageVersion(id, token).pipe(
|
deletePackageVersion(id, owner, packageName, packageType, token).pipe(
|
||||||
tap(result => {
|
tap(result => {
|
||||||
if (result) {
|
if (!result) {
|
||||||
console.log(`version with id: ${id}, deleted`)
|
|
||||||
} else {
|
|
||||||
console.log(`version with id: ${id}, not deleted`)
|
console.log(`version with id: ${id}, not deleted`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
console.log(`Total versions deleted till now: ${deleted}`)
|
||||||
return merge(...deletes)
|
return merge(...deletes)
|
||||||
}
|
}
|
||||||
|
|||||||
+49
-91
@@ -1,111 +1,69 @@
|
|||||||
import {GraphQlQueryResponse} from '@octokit/graphql/dist-types/types'
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
import {Observable, from, throwError} from 'rxjs'
|
import {from, Observable, merge, throwError, of} from 'rxjs'
|
||||||
import {catchError, map} from 'rxjs/operators'
|
import {catchError, map} from 'rxjs/operators'
|
||||||
import {graphql} from './graphql'
|
import {Octokit} from '@octokit/rest'
|
||||||
|
import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types'
|
||||||
|
|
||||||
export interface VersionInfo {
|
export interface RestVersionInfo {
|
||||||
id: string
|
id: number
|
||||||
version: string
|
version: string
|
||||||
|
created_at: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetVersionsQueryResponse {
|
export interface RestQueryInfo {
|
||||||
repository: {
|
versions: RestVersionInfo[]
|
||||||
packages: {
|
page: number
|
||||||
edges: {
|
paginate: boolean
|
||||||
node: {
|
totalCount: number
|
||||||
name: string
|
|
||||||
versions: {
|
|
||||||
edges: {node: VersionInfo}[]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}[]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = `
|
type PackageType = RestEndpointMethodTypes['packages']['getAllPackageVersionsForPackageOwnedByUser']['parameters']['package_type']
|
||||||
query getVersions($owner: String!, $repo: String!, $package: String!, $last: Int!) {
|
type GetVersionsResponse = RestEndpointMethodTypes['packages']['getAllPackageVersionsForPackageOwnedByUser']['response']['data']
|
||||||
repository(owner: $owner, name: $repo) {
|
|
||||||
packages(first: 1, names: [$package]) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
name
|
|
||||||
versions(last: $last) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
id
|
|
||||||
version
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
export function queryForOldestVersions(
|
|
||||||
owner: string,
|
|
||||||
repo: string,
|
|
||||||
packageName: string,
|
|
||||||
numVersions: number,
|
|
||||||
token: string
|
|
||||||
): Observable<GetVersionsQueryResponse> {
|
|
||||||
return from(
|
|
||||||
graphql(token, query, {
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
package: packageName,
|
|
||||||
last: numVersions,
|
|
||||||
headers: {
|
|
||||||
Accept: 'application/vnd.github.packages-preview+json'
|
|
||||||
}
|
|
||||||
}) as Promise<GetVersionsQueryResponse>
|
|
||||||
).pipe(
|
|
||||||
catchError((err: GraphQlQueryResponse) => {
|
|
||||||
const msg = 'query for oldest version failed.'
|
|
||||||
return throwError(
|
|
||||||
err.errors && err.errors.length > 0
|
|
||||||
? `${msg} ${err.errors[0].message}`
|
|
||||||
: `${msg} verify input parameters are correct`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getOldestVersions(
|
export function getOldestVersions(
|
||||||
owner: string,
|
owner: string,
|
||||||
repo: string,
|
|
||||||
packageName: string,
|
packageName: string,
|
||||||
|
packageType: string,
|
||||||
numVersions: number,
|
numVersions: number,
|
||||||
|
page: number,
|
||||||
token: string
|
token: string
|
||||||
): Observable<VersionInfo[]> {
|
): Observable<RestQueryInfo> {
|
||||||
return queryForOldestVersions(
|
const octokit = new Octokit({
|
||||||
owner,
|
auth: token
|
||||||
repo,
|
})
|
||||||
packageName,
|
const package_type: PackageType = packageType as PackageType
|
||||||
numVersions,
|
|
||||||
token
|
return from(
|
||||||
|
octokit.rest.packages.getAllPackageVersionsForPackageOwnedByUser({
|
||||||
|
package_type,
|
||||||
|
package_name: packageName,
|
||||||
|
username: owner,
|
||||||
|
per_page: numVersions,
|
||||||
|
page
|
||||||
|
})
|
||||||
).pipe(
|
).pipe(
|
||||||
map(result => {
|
catchError(err => {
|
||||||
if (result.repository.packages.edges.length < 1) {
|
const msg = 'get versions API failed.'
|
||||||
console.log(
|
return throwError(
|
||||||
`package: ${packageName} not found for owner: ${owner} in repo: ${repo}`
|
err.errors && err.errors.length > 0
|
||||||
|
? `${msg} ${err.errors[0].message}`
|
||||||
|
: `${msg} ${err.message}`
|
||||||
)
|
)
|
||||||
return []
|
}),
|
||||||
|
map(response => {
|
||||||
|
const resp = {
|
||||||
|
versions: response.data.map((version: GetVersionsResponse[0]) => {
|
||||||
|
return {
|
||||||
|
id: version.id,
|
||||||
|
version: version.name,
|
||||||
|
created_at: version.created_at
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
const versions = result.repository.packages.edges[0].node.versions.edges
|
page,
|
||||||
|
paginate: response.data.length === numVersions,
|
||||||
if (versions.length !== numVersions) {
|
totalCount: response.data.length
|
||||||
console.log(
|
|
||||||
`number of versions requested was: ${numVersions}, but found: ${versions.length}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
return resp
|
||||||
return versions
|
|
||||||
.map(value => ({id: value.node.id, version: value.node.version}))
|
|
||||||
.reverse()
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
import {GitHub} from '@actions/github'
|
import {GitHub} from '@actions/github'
|
||||||
import {GraphQlQueryResponseData} from '@octokit/graphql/dist-types/types'
|
import {GraphQlQueryResponseData} from '@octokit/graphql/dist-types/types'
|
||||||
import {RequestParameters} from '@octokit/types/dist-types/RequestParameters'
|
import {RequestParameters} from '@octokit/types/dist-types/RequestParameters'
|
||||||
|
|||||||
Reference in New Issue
Block a user