Releases/v1 (#1)
* delete package versions action v1 * updated action for build and smoke test * test and error message update * test fix * ci testing * ci testing * ci testing * ci testing * ci test * ci testing * ci test name * docs * docs * docs * test * test * test * docs * usage doc * doc * docs * format test * doc update * doc test * formatting check * scenario update * usage update * format * test * test * test * test * test * table test * test * format update * links * test * test * test * test * test * docs update * test * formatting * fix broken links * doc update * test * table test * test * test * test * test * test * test * test * test * test * test * doc test * test * test * test * test * test * test * test t * test * test * test * test * test * test * docs * doc update
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
"project": "./tsconfig.json",
|
||||
"createDefaultProgram": true
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
@@ -48,7 +49,8 @@
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": ["error", "never"],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
"@typescript-eslint/unbound-method": "error",
|
||||
"no-console": "off"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
|
||||
38
.github/workflows/test.yml
vendored
38
.github/workflows/test.yml
vendored
@@ -1,23 +1,33 @@
|
||||
name: "build-test"
|
||||
name: Package and Smoke Test
|
||||
|
||||
on: # rebuild any PRs and main branch changes
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- 'releases/*'
|
||||
# push:
|
||||
# branches:
|
||||
# - master
|
||||
# - 'releases/*'
|
||||
|
||||
jobs:
|
||||
build: # make sure build/ci work properly
|
||||
|
||||
package: # make sure build/ci work properly
|
||||
name: Package
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- run: |
|
||||
npm install
|
||||
npm run all
|
||||
test: # make sure the action works on a clean machine without building
|
||||
- uses: actions/checkout@v2
|
||||
name: Checkout Delete Package Versions Repo
|
||||
- run: npm install
|
||||
name: NPM Install
|
||||
- run: npm run pack
|
||||
name: Check Format, Lint, Run Unit Tests, Build and Package
|
||||
|
||||
smoke-test: # make sure the action works on a clean machine without building
|
||||
name: Smoke Test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
name: Checkout Delete Package Versions Repo
|
||||
- uses: ./
|
||||
with:
|
||||
milliseconds: 1000
|
||||
name: Smoke Test Delete Package Versions Action
|
||||
with:
|
||||
package-name: 'com.github.actions.test-package'
|
||||
num-old-versions-to-delete: 0
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -96,4 +96,6 @@ Thumbs.db
|
||||
|
||||
# Ignore built ts files
|
||||
__tests__/runner/*
|
||||
lib/**/*
|
||||
lib/**/*
|
||||
|
||||
.idea
|
||||
298
README.md
298
README.md
@@ -1,117 +1,207 @@
|
||||
<p align="center">
|
||||
<a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a>
|
||||
</p>
|
||||
# Delete Package Versions
|
||||
|
||||
# Create a JavaScript Action using TypeScript
|
||||
This action deletes versions of a package from [GitHub Packages](https://github.com/features/packages).
|
||||
|
||||
Use this template to bootstrap the creation of a JavaScript action.:rocket:
|
||||
### What It Can Do
|
||||
|
||||
This template includes compilication support, tests, a validation workflow, publishing, and versioning guidance.
|
||||
* Delete a single version
|
||||
* Delete multiple versions
|
||||
* Delete specific version(s)
|
||||
* Delete oldest version(s)
|
||||
* 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
|
||||
|
||||
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
|
||||
|
||||
## Create an action from this template
|
||||
|
||||
Click the `Use this Template` and provide the new repo details for your action
|
||||
|
||||
## Code in Master
|
||||
|
||||
Install the dependencies
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
Build the typescript
|
||||
```bash
|
||||
$ npm run build
|
||||
```
|
||||
|
||||
Run the tests :heavy_check_mark:
|
||||
```bash
|
||||
$ npm test
|
||||
|
||||
PASS ./index.test.js
|
||||
✓ throws invalid number (3ms)
|
||||
✓ wait 500 ms (504ms)
|
||||
✓ test runs (95ms)
|
||||
|
||||
...
|
||||
```
|
||||
|
||||
## Change action.yml
|
||||
|
||||
The action.yml contains defines the inputs and output for your action.
|
||||
|
||||
Update the action.yml with your name, description, inputs and outputs for your action.
|
||||
|
||||
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
|
||||
|
||||
## Change the Code
|
||||
|
||||
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
|
||||
|
||||
```javascript
|
||||
import * as core from '@actions/core';
|
||||
...
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
...
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
```
|
||||
|
||||
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
|
||||
|
||||
## Publish to a distribution branch
|
||||
|
||||
Actions are run from GitHub repos. We will create a releases branch and only checkin production modules (core in this case).
|
||||
|
||||
Comment out node_modules in .gitignore and create a releases/v1 branch
|
||||
```bash
|
||||
# comment out in distribution branches
|
||||
# node_modules/
|
||||
```
|
||||
|
||||
```bash
|
||||
$ git checkout -b releases/v1
|
||||
$ git commit -a -m "prod dependencies"
|
||||
```
|
||||
|
||||
```bash
|
||||
$ npm prune --production
|
||||
$ git add node_modules
|
||||
$ git commit -a -m "prod dependencies"
|
||||
$ git push origin releases/v1
|
||||
```
|
||||
|
||||
Your action is now published! :rocket:
|
||||
|
||||
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
|
||||
|
||||
## Validate
|
||||
|
||||
You can now validate the action by referencing the releases/v1 branch
|
||||
# Usage
|
||||
|
||||
```yaml
|
||||
uses: actions/typescript-action@releases/v1
|
||||
with:
|
||||
milliseconds: 1000
|
||||
- uses: actions/delete-package-versions@v1
|
||||
with:
|
||||
# Can be a single package version id, or a comma separated list of package version ids.
|
||||
# Defaults to an empty string.
|
||||
package-version-ids:
|
||||
|
||||
# Owner of the repo hosting the package.
|
||||
# Defaults to the owner of the repo executing the workflow.
|
||||
# Required if deleting a version from a package hosted in a different repo than the one executing the workflow.
|
||||
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.
|
||||
# Defaults to an empty string.
|
||||
# Required if `package-version-ids` input is not given.
|
||||
package-name:
|
||||
|
||||
# The number of old versions to delete starting from the oldest version.
|
||||
# Defaults to 1.
|
||||
num-old-versions-to-delete:
|
||||
|
||||
# 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.
|
||||
# If `package-version-ids` is given the token only needs the delete packages scope.
|
||||
# If `package-version-ids` is not given the token needs the delete packages scope and the read packages scope
|
||||
token:
|
||||
```
|
||||
|
||||
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
|
||||
# Scenarios
|
||||
|
||||
## Usage:
|
||||
* [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 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)
|
||||
|
||||
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and tested action
|
||||
### Delete a specific version of a package hosted in the same repo as the workflow
|
||||
|
||||
To delete a specific version of a package that is hosted in the same repo as the one executing the workflow the __package-version-ids__ input is required.
|
||||
|
||||
Package version ids can be retrieved via the [GitHub GraphQL API][api]
|
||||
|
||||
__Example__
|
||||
|
||||
```yaml
|
||||
uses: actions/typescript-action@v1
|
||||
with:
|
||||
milliseconds: 1000
|
||||
- uses: actions/delete-package-versions@v1
|
||||
with:
|
||||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3'
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### Delete a specific version of a package hosted in a different repo than the workflow
|
||||
|
||||
To delete a specific version of a package that is hosted in a different repo than the one executing the workflow the __package-version-ids__, and __token__ inputs are required.
|
||||
|
||||
Package version ids can be retrieved via the [GitHub GraphQL API][api].
|
||||
|
||||
The [token][token] only needs the delete 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__
|
||||
|
||||
```yaml
|
||||
- uses: actions/delete-package-versions@v1
|
||||
with:
|
||||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3'
|
||||
token: ${{ secrets.GITHUB_PAT }}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### Delete multiple specific versions of a package hosted in the same repo as the workflow
|
||||
|
||||
To delete multiple specifc versions of a package that is hosted in the same repo that is executing 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].
|
||||
|
||||
__Example__
|
||||
|
||||
```yaml
|
||||
- uses: actions/delete-package-versions@v1
|
||||
with:
|
||||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw'
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### Delete multiple specific versions of a package hosted in a different repo than the workflow
|
||||
|
||||
To delete multiple specifc versions of a package that is hosted in a different repo than the one executing the workflow the __package-version-ids__, and __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 [token][token] only needs the delete 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__
|
||||
|
||||
```yaml
|
||||
- uses: actions/delete-package-versions@v1
|
||||
with:
|
||||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw'
|
||||
token: ${{ secrets.GITHUB_PAT }}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### Delete oldest version of a package hosted in the same repo as the workflow
|
||||
|
||||
To delete the oldest version of a package that is hosted in the same repo that is executing the workflow the __package-name__ input is required.
|
||||
|
||||
__Example__
|
||||
|
||||
```yaml
|
||||
- uses: actions/delete-package-versions@v1
|
||||
with:
|
||||
package-name: 'test-package'
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### Delete oldest version of a package hosted in a different repo than the workflow
|
||||
|
||||
To delete the oldest version of a package that is hosted in a different repo than the one executing the workflow the __package-name__, __owner__, __repo__, and __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__.
|
||||
|
||||
__Example__
|
||||
|
||||
```yaml
|
||||
- uses: actions/delete-package-versions@v1
|
||||
with:
|
||||
owner: 'github'
|
||||
repo: 'packages'
|
||||
package-name: 'test-package'
|
||||
token: ${{ secrets.GITHUB_PAT }}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### Delete oldest x number of versions of a package hosted in the same repo as the workflow
|
||||
|
||||
To delete the oldest x number of versions of a package hosted in the same repo that is executing the workflow the __package-name__, and __num-old-versions-to-delete__ inputs are required.
|
||||
|
||||
__Example__
|
||||
|
||||
Delete the oldest 3 version of a package hosted in the same repo as the workflow
|
||||
|
||||
```yaml
|
||||
- uses: actions/delete-package-versions@v1
|
||||
with:
|
||||
package-name: 'test-package'
|
||||
num-old-versions-to-delete: 3
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### Delete oldest x number of versions of a package hosted in a different repo than the workflow
|
||||
|
||||
To delete the oldest x number of versions of a package hosted in a different repo than the one executing the workflow the __package-name__, __num-old-versions-to-delete__, __owner__, __repo__, and __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__.
|
||||
|
||||
__Example__
|
||||
|
||||
Delete the oldest 3 version of a package hosted in a different repo than the one executing the workflow
|
||||
|
||||
```yaml
|
||||
- uses: actions/delete-package-versions@v1
|
||||
with:
|
||||
owner: 'github'
|
||||
repo: 'packages'
|
||||
package-name: 'test-package'
|
||||
num-old-versions-to-delete: 3
|
||||
token: ${{ secrets.GITHUB_PAT }}
|
||||
```
|
||||
|
||||
# License
|
||||
|
||||
The scripts and documentation in this project are released under the [MIT License](https://github.com/actions/delete-package-versions/blob/master/LICENSE)
|
||||
|
||||
[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
|
||||
[secret]: https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
|
||||
|
||||
|
||||
90
__tests__/delete.test.ts
Normal file
90
__tests__/delete.test.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import {Input, InputParams} from '../src/input'
|
||||
import {deleteVersions, getVersionIds} from '../src/delete'
|
||||
|
||||
describe.skip('index tests -- call graphql', () => {
|
||||
it('getVersionIds test -- get oldest version', done => {
|
||||
const numVersions = 1
|
||||
|
||||
getVersionIds(getInput({numOldVersionsToDelete: numVersions})).subscribe(
|
||||
ids => {
|
||||
expect(ids.length).toBe(numVersions)
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('getVersionIds test -- get oldest 3 versions', done => {
|
||||
const numVersions = 3
|
||||
|
||||
getVersionIds(getInput({numOldVersionsToDelete: numVersions})).subscribe(
|
||||
ids => {
|
||||
expect(ids.length).toBe(numVersions)
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('getVersionIds test -- supplied package version id', done => {
|
||||
const suppliedIds = [
|
||||
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||
'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
|
||||
'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC'
|
||||
]
|
||||
|
||||
getVersionIds(getInput({packageVersionIds: suppliedIds})).subscribe(ids => {
|
||||
expect(ids).toBe(suppliedIds)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('deleteVersions test -- missing token', done => {
|
||||
deleteVersions(getInput({token: ''})).subscribe({
|
||||
error: err => {
|
||||
expect(err).toBeTruthy()
|
||||
done()
|
||||
},
|
||||
complete: async () => done.fail('no error thrown')
|
||||
})
|
||||
})
|
||||
|
||||
it('deleteVersions test -- missing packageName', done => {
|
||||
deleteVersions(getInput({packageName: ''})).subscribe({
|
||||
error: err => {
|
||||
expect(err).toBeTruthy()
|
||||
done()
|
||||
},
|
||||
complete: async () => done.fail('no error thrown')
|
||||
})
|
||||
})
|
||||
|
||||
it('deleteVersions test -- delete oldest version', done => {
|
||||
deleteVersions(getInput({numOldVersionsToDelete: 1})).subscribe(
|
||||
isSuccess => {
|
||||
expect(isSuccess).toBe(true)
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('deleteVersions test -- delete 3 oldest versions', done => {
|
||||
deleteVersions(getInput({numOldVersionsToDelete: 3})).subscribe(
|
||||
isSuccess => {
|
||||
expect(isSuccess).toBe(true)
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
const defaultInput: InputParams = {
|
||||
packageVersionIds: [],
|
||||
owner: 'trent-j',
|
||||
repo: 'actions-testing',
|
||||
packageName: 'com.github.trent-j.actions-test',
|
||||
numOldVersionsToDelete: 1,
|
||||
token: process.env.GITHUB_TOKEN as string
|
||||
}
|
||||
|
||||
function getInput(params?: InputParams): Input {
|
||||
return new Input({...defaultInput, ...params})
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import {wait} from '../src/wait'
|
||||
import * as process from 'process'
|
||||
import * as cp from 'child_process'
|
||||
import * as path from 'path'
|
||||
|
||||
test('throws invalid number', async () => {
|
||||
const input = parseInt('foo', 10)
|
||||
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
|
||||
})
|
||||
|
||||
test('wait 500 ms', async () => {
|
||||
const start = new Date()
|
||||
await wait(500)
|
||||
const end = new Date()
|
||||
var delta = Math.abs(end.getTime() - start.getTime())
|
||||
expect(delta).toBeGreaterThan(450)
|
||||
})
|
||||
|
||||
// shows how the runner will run a javascript action with env / stdout protocol
|
||||
test('test runs', () => {
|
||||
process.env['INPUT_MILLISECONDS'] = '500'
|
||||
const ip = path.join(__dirname, '..', 'lib', 'main.js')
|
||||
const options: cp.ExecSyncOptions = {
|
||||
env: process.env
|
||||
}
|
||||
console.log(cp.execSync(`node ${ip}`, options).toString())
|
||||
})
|
||||
25
__tests__/version/delete-version.test.ts
Normal file
25
__tests__/version/delete-version.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
68
__tests__/version/get-version.test.ts
Normal file
68
__tests__/version/get-version.test.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
// 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: 'trent-j',
|
||||
repo: 'actions-testing',
|
||||
packageName: 'com.github.trent-j.actions-test',
|
||||
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
|
||||
)
|
||||
}
|
||||
56
__tests__/version/graphql.mock.ts
Normal file
56
__tests__/version/graphql.mock.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
GraphQlQueryResponseData,
|
||||
RequestParameters
|
||||
} from '@octokit/graphql/dist-types/types'
|
||||
|
||||
import * as Graphql from '@octokit/graphql'
|
||||
import {GetVersionsQueryResponse} from '../../src/version'
|
||||
|
||||
import SpyInstance = jest.SpyInstance
|
||||
|
||||
export function mockGraphql(): SpyInstance<
|
||||
Promise<GraphQlQueryResponseData>,
|
||||
[string, (RequestParameters | undefined)?]
|
||||
> {
|
||||
return jest.spyOn(Graphql, 'graphql')
|
||||
}
|
||||
|
||||
export function getMockedOldestQueryResponse(
|
||||
numVersions: number
|
||||
): GetVersionsQueryResponse {
|
||||
const versions = []
|
||||
|
||||
for (let i = 1; i <= numVersions; ++i) {
|
||||
versions.push({
|
||||
node: {
|
||||
id: i.toString(),
|
||||
version: `${i}.0.0`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
repository: {
|
||||
packages: {
|
||||
edges: [
|
||||
{
|
||||
node: {
|
||||
name: 'test',
|
||||
versions: {
|
||||
edges: versions.reverse()
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function mockOldestQueryResponse(
|
||||
numVersions: number
|
||||
): ReturnType<typeof mockGraphql> {
|
||||
return mockGraphql().mockResolvedValue(
|
||||
getMockedOldestQueryResponse(numVersions)
|
||||
)
|
||||
}
|
||||
54
action.yml
54
action.yml
@@ -1,10 +1,48 @@
|
||||
name: 'Your name here'
|
||||
description: 'Provide a description here'
|
||||
author: 'Your name or organization here'
|
||||
|
||||
name: Delete Package Versions
|
||||
|
||||
description: Deletes package versions
|
||||
|
||||
inputs:
|
||||
myInput: # change this
|
||||
description: 'input description here'
|
||||
default: 'default value if applicable'
|
||||
|
||||
package-version-ids:
|
||||
description: Comma separated string of package version ids to delete.
|
||||
required: false
|
||||
|
||||
owner:
|
||||
description: >
|
||||
Owner of the repo containing the package version to delete.
|
||||
Defaults to the owner of the repo running the action.
|
||||
required: false
|
||||
|
||||
repo:
|
||||
description: >
|
||||
Repo containing the package version to delete.
|
||||
Defaults to the repo running the action.
|
||||
required: false
|
||||
|
||||
package-name:
|
||||
description: >
|
||||
Name of the package containing the version to delete.
|
||||
Required if dynamically deleting oldest versions.
|
||||
required: false
|
||||
|
||||
num-old-versions-to-delete:
|
||||
description: >
|
||||
Number of versions to delete starting with the oldest version.
|
||||
Defaults to 1.
|
||||
required: false
|
||||
default: "1"
|
||||
|
||||
token:
|
||||
description: >
|
||||
Token with the necessary scopes to delete package versions.
|
||||
If num-old-versions-to-delete is used the token also needs the read packages scope.
|
||||
Defaults to github.token scoped to the repo running the action. To delete package versions
|
||||
of a package outside the repo the action is running in use a Personal Access Token stored as a secret.
|
||||
required: false
|
||||
default: ${{ github.token }}
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
using: node12
|
||||
main: dist/index.js
|
||||
|
||||
37476
dist/index.js
vendored
37476
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
302
package-lock.json
generated
302
package-lock.json
generated
@@ -9,6 +9,24 @@
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz",
|
||||
"integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw=="
|
||||
},
|
||||
"@actions/github": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-2.1.1.tgz",
|
||||
"integrity": "sha512-kAgTGUx7yf5KQCndVeHSwCNZuDBvPyxm5xKTswW2lofugeuC1AZX73nUUVDNaysnM9aKFMHv9YCdVJbg7syEyA==",
|
||||
"requires": {
|
||||
"@actions/http-client": "^1.0.3",
|
||||
"@octokit/graphql": "^4.3.1",
|
||||
"@octokit/rest": "^16.43.1"
|
||||
}
|
||||
},
|
||||
"@actions/http-client": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.6.tgz",
|
||||
"integrity": "sha512-LGmio4w98UyGX33b/W6V6Nx/sQHRXZ859YlMkn36wPsXPB82u8xTVlA/Dq2DXrm6lEq9RVmisRJa1c+HETAIJA==",
|
||||
"requires": {
|
||||
"tunnel": "0.0.6"
|
||||
}
|
||||
},
|
||||
"@babel/code-frame": {
|
||||
"version": "7.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz",
|
||||
@@ -411,6 +429,163 @@
|
||||
"@types/yargs": "^13.0.0"
|
||||
}
|
||||
},
|
||||
"@octokit/auth-token": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.4.0.tgz",
|
||||
"integrity": "sha512-eoOVMjILna7FVQf96iWc3+ZtE/ZT6y8ob8ZzcqKY1ibSQCnu4O/B7pJvzMx5cyZ/RjAff6DAdEb0O0Cjcxidkg==",
|
||||
"requires": {
|
||||
"@octokit/types": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"@octokit/endpoint": {
|
||||
"version": "5.5.3",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-5.5.3.tgz",
|
||||
"integrity": "sha512-EzKwkwcxeegYYah5ukEeAI/gYRLv2Y9U5PpIsseGSFDk+G3RbipQGBs8GuYS1TLCtQaqoO66+aQGtITPalxsNQ==",
|
||||
"requires": {
|
||||
"@octokit/types": "^2.0.0",
|
||||
"is-plain-object": "^3.0.0",
|
||||
"universal-user-agent": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-plain-object": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-3.0.0.tgz",
|
||||
"integrity": "sha512-tZIpofR+P05k8Aocp7UI/2UTa9lTJSebCXpFFoR9aibpokDj/uXBsJ8luUu0tTVYKkMU6URDUuOfJZ7koewXvg==",
|
||||
"requires": {
|
||||
"isobject": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"isobject": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isobject/-/isobject-4.0.0.tgz",
|
||||
"integrity": "sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA=="
|
||||
},
|
||||
"universal-user-agent": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-5.0.0.tgz",
|
||||
"integrity": "sha512-B5TPtzZleXyPrUMKCpEHFmVhMN6EhmJYjG5PQna9s7mXeSqGTLap4OpqLl5FCEFUI3UBmllkETwKf/db66Y54Q==",
|
||||
"requires": {
|
||||
"os-name": "^3.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@octokit/graphql": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.3.1.tgz",
|
||||
"integrity": "sha512-hCdTjfvrK+ilU2keAdqNBWOk+gm1kai1ZcdjRfB30oA3/T6n53UVJb7w0L5cR3/rhU91xT3HSqCd+qbvH06yxA==",
|
||||
"requires": {
|
||||
"@octokit/request": "^5.3.0",
|
||||
"@octokit/types": "^2.0.0",
|
||||
"universal-user-agent": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"@octokit/plugin-paginate-rest": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-1.1.2.tgz",
|
||||
"integrity": "sha512-jbsSoi5Q1pj63sC16XIUboklNw+8tL9VOnJsWycWYR78TKss5PVpIPb1TUUcMQ+bBh7cY579cVAWmf5qG+dw+Q==",
|
||||
"requires": {
|
||||
"@octokit/types": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"@octokit/plugin-request-log": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-1.0.0.tgz",
|
||||
"integrity": "sha512-ywoxP68aOT3zHCLgWZgwUJatiENeHE7xJzYjfz8WI0goynp96wETBF+d95b8g/uL4QmS6owPVlaxiz3wyMAzcw=="
|
||||
},
|
||||
"@octokit/plugin-rest-endpoint-methods": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-2.4.0.tgz",
|
||||
"integrity": "sha512-EZi/AWhtkdfAYi01obpX0DF7U6b1VRr30QNQ5xSFPITMdLSfhcBqjamE3F+sKcxPbD7eZuMHu3Qkk2V+JGxBDQ==",
|
||||
"requires": {
|
||||
"@octokit/types": "^2.0.1",
|
||||
"deprecation": "^2.3.1"
|
||||
}
|
||||
},
|
||||
"@octokit/request": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.3.2.tgz",
|
||||
"integrity": "sha512-7NPJpg19wVQy1cs2xqXjjRq/RmtSomja/VSWnptfYwuBxLdbYh2UjhGi0Wx7B1v5Iw5GKhfFDQL7jM7SSp7K2g==",
|
||||
"requires": {
|
||||
"@octokit/endpoint": "^5.5.0",
|
||||
"@octokit/request-error": "^1.0.1",
|
||||
"@octokit/types": "^2.0.0",
|
||||
"deprecation": "^2.0.0",
|
||||
"is-plain-object": "^3.0.0",
|
||||
"node-fetch": "^2.3.0",
|
||||
"once": "^1.4.0",
|
||||
"universal-user-agent": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-plain-object": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-3.0.0.tgz",
|
||||
"integrity": "sha512-tZIpofR+P05k8Aocp7UI/2UTa9lTJSebCXpFFoR9aibpokDj/uXBsJ8luUu0tTVYKkMU6URDUuOfJZ7koewXvg==",
|
||||
"requires": {
|
||||
"isobject": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"isobject": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isobject/-/isobject-4.0.0.tgz",
|
||||
"integrity": "sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA=="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
||||
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
|
||||
},
|
||||
"universal-user-agent": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-5.0.0.tgz",
|
||||
"integrity": "sha512-B5TPtzZleXyPrUMKCpEHFmVhMN6EhmJYjG5PQna9s7mXeSqGTLap4OpqLl5FCEFUI3UBmllkETwKf/db66Y54Q==",
|
||||
"requires": {
|
||||
"os-name": "^3.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@octokit/request-error": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-1.2.1.tgz",
|
||||
"integrity": "sha512-+6yDyk1EES6WK+l3viRDElw96MvwfJxCt45GvmjDUKWjYIb3PJZQkq3i46TwGwoPD4h8NmTrENmtyA1FwbmhRA==",
|
||||
"requires": {
|
||||
"@octokit/types": "^2.0.0",
|
||||
"deprecation": "^2.0.0",
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"@octokit/rest": {
|
||||
"version": "16.43.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.43.1.tgz",
|
||||
"integrity": "sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==",
|
||||
"requires": {
|
||||
"@octokit/auth-token": "^2.4.0",
|
||||
"@octokit/plugin-paginate-rest": "^1.1.1",
|
||||
"@octokit/plugin-request-log": "^1.0.0",
|
||||
"@octokit/plugin-rest-endpoint-methods": "2.4.0",
|
||||
"@octokit/request": "^5.2.0",
|
||||
"@octokit/request-error": "^1.0.2",
|
||||
"atob-lite": "^2.0.0",
|
||||
"before-after-hook": "^2.0.0",
|
||||
"btoa-lite": "^1.0.0",
|
||||
"deprecation": "^2.0.0",
|
||||
"lodash.get": "^4.4.2",
|
||||
"lodash.set": "^4.3.2",
|
||||
"lodash.uniq": "^4.5.0",
|
||||
"octokit-pagination-methods": "^1.1.0",
|
||||
"once": "^1.4.0",
|
||||
"universal-user-agent": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"@octokit/types": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-2.3.1.tgz",
|
||||
"integrity": "sha512-rvJP1Y9A/+Cky2C3var1vsw3Lf5Rjn/0sojNl2AjCX+WbpIHYccaJ46abrZoIxMYnOToul6S9tPytUVkFI7CXQ==",
|
||||
"requires": {
|
||||
"@types/node": ">= 8"
|
||||
}
|
||||
},
|
||||
"@types/babel__core": {
|
||||
"version": "7.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.3.tgz",
|
||||
@@ -501,8 +676,7 @@
|
||||
"@types/node": {
|
||||
"version": "12.12.14",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.14.tgz",
|
||||
"integrity": "sha512-u/SJDyXwuihpwjXy7hOOghagLEV1KdAST6syfnOk6QZAMzZuWZqXy5aYYZbh8Jdpd4escVFP0MvftHNDb9pruA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-u/SJDyXwuihpwjXy7hOOghagLEV1KdAST6syfnOk6QZAMzZuWZqXy5aYYZbh8Jdpd4escVFP0MvftHNDb9pruA=="
|
||||
},
|
||||
"@types/stack-utils": {
|
||||
"version": "1.0.1",
|
||||
@@ -808,6 +982,11 @@
|
||||
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==",
|
||||
"dev": true
|
||||
},
|
||||
"atob-lite": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/atob-lite/-/atob-lite-2.0.0.tgz",
|
||||
"integrity": "sha1-D+9a1G8b16hQLGVyfwNn1e5D1pY="
|
||||
},
|
||||
"aws-sign2": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz",
|
||||
@@ -1005,6 +1184,11 @@
|
||||
"tweetnacl": "^0.14.3"
|
||||
}
|
||||
},
|
||||
"before-after-hook": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.1.0.tgz",
|
||||
"integrity": "sha512-IWIbu7pMqyw3EAJHzzHbWa85b6oud/yfKYg5rqB5hNE8CeMi3nX+2C2sj0HswfblST86hpVEOAb9x34NZd6P7A=="
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
@@ -1085,6 +1269,11 @@
|
||||
"node-int64": "^0.4.0"
|
||||
}
|
||||
},
|
||||
"btoa-lite": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/btoa-lite/-/btoa-lite-1.0.0.tgz",
|
||||
"integrity": "sha1-M3dm2hWAEhD92VbCLpxokaudAzc="
|
||||
},
|
||||
"buffer-from": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||
@@ -1334,7 +1523,6 @@
|
||||
"version": "6.0.5",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",
|
||||
"integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"nice-try": "^1.0.4",
|
||||
"path-key": "^2.0.1",
|
||||
@@ -1346,8 +1534,7 @@
|
||||
"semver": {
|
||||
"version": "5.7.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
|
||||
"integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1488,6 +1675,11 @@
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
|
||||
"dev": true
|
||||
},
|
||||
"deprecation": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz",
|
||||
"integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ=="
|
||||
},
|
||||
"detect-newline": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-2.1.0.tgz",
|
||||
@@ -1538,7 +1730,6 @@
|
||||
"version": "1.4.4",
|
||||
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
|
||||
"integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
@@ -2116,7 +2307,6 @@
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz",
|
||||
"integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"cross-spawn": "^6.0.0",
|
||||
"get-stream": "^4.0.0",
|
||||
@@ -3020,7 +3210,6 @@
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz",
|
||||
"integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"pump": "^3.0.0"
|
||||
}
|
||||
@@ -3552,8 +3741,7 @@
|
||||
"is-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
|
||||
"dev": true
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
|
||||
},
|
||||
"is-symbol": {
|
||||
"version": "1.0.3",
|
||||
@@ -3591,8 +3779,7 @@
|
||||
"isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
|
||||
"dev": true
|
||||
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
|
||||
},
|
||||
"isobject": {
|
||||
"version": "3.0.1",
|
||||
@@ -4336,12 +4523,22 @@
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.get": {
|
||||
"version": "4.4.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
|
||||
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
|
||||
},
|
||||
"lodash.memoize": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
|
||||
"integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.set": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz",
|
||||
"integrity": "sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM="
|
||||
},
|
||||
"lodash.sortby": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
|
||||
@@ -4354,6 +4551,11 @@
|
||||
"integrity": "sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.uniq": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz",
|
||||
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M="
|
||||
},
|
||||
"loose-envify": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
||||
@@ -4363,6 +4565,11 @@
|
||||
"js-tokens": "^3.0.0 || ^4.0.0"
|
||||
}
|
||||
},
|
||||
"macos-release": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/macos-release/-/macos-release-2.3.0.tgz",
|
||||
"integrity": "sha512-OHhSbtcviqMPt7yfw5ef5aghS2jzFVKEFyCJndQt2YpSQ9qRVSEv2axSJI1paVThEu+FFGs584h/1YhxjVqajA=="
|
||||
},
|
||||
"make-dir": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz",
|
||||
@@ -4563,8 +4770,7 @@
|
||||
"nice-try": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
|
||||
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.1.2",
|
||||
@@ -4638,7 +4844,6 @@
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
|
||||
"integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"path-key": "^2.0.0"
|
||||
}
|
||||
@@ -4780,11 +4985,15 @@
|
||||
"has": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"octokit-pagination-methods": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/octokit-pagination-methods/-/octokit-pagination-methods-1.1.0.tgz",
|
||||
"integrity": "sha512-fZ4qZdQ2nxJvtcasX7Ghl+WlWS/d9IgnBIwFZXVNNZUmzpno91SX5bc5vuxiuKoCtK78XxGGNuSCrDC7xYB3OQ=="
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
@@ -4822,6 +5031,15 @@
|
||||
"word-wrap": "~1.2.3"
|
||||
}
|
||||
},
|
||||
"os-name": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/os-name/-/os-name-3.1.0.tgz",
|
||||
"integrity": "sha512-h8L+8aNjNcMpo/mAIBPn5PXCM16iyPGjHNWo6U1YO8sJTMHtEtyczI6QJnLoplswm6goopQkqc7OAnjhWcugVg==",
|
||||
"requires": {
|
||||
"macos-release": "^2.2.0",
|
||||
"windows-release": "^3.1.0"
|
||||
}
|
||||
},
|
||||
"os-tmpdir": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
|
||||
@@ -4840,8 +5058,7 @@
|
||||
"p-finally": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
|
||||
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=",
|
||||
"dev": true
|
||||
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4="
|
||||
},
|
||||
"p-limit": {
|
||||
"version": "1.3.0",
|
||||
@@ -4924,8 +5141,7 @@
|
||||
"path-key": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz",
|
||||
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=",
|
||||
"dev": true
|
||||
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A="
|
||||
},
|
||||
"path-parse": {
|
||||
"version": "1.0.6",
|
||||
@@ -5054,7 +5270,6 @@
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
||||
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"end-of-stream": "^1.1.0",
|
||||
"once": "^1.3.1"
|
||||
@@ -5398,10 +5613,9 @@
|
||||
}
|
||||
},
|
||||
"rxjs": {
|
||||
"version": "6.5.3",
|
||||
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.3.tgz",
|
||||
"integrity": "sha512-wuYsAYYFdWTAnAaPoKGNhfpWwKZbJW+HgAJ+mImp+Epl7BG8oNWBCTyRM8gba9k4lk8BgWdoYm21Mo/RYhhbgA==",
|
||||
"dev": true,
|
||||
"version": "6.5.4",
|
||||
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz",
|
||||
"integrity": "sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==",
|
||||
"requires": {
|
||||
"tslib": "^1.9.0"
|
||||
}
|
||||
@@ -5497,7 +5711,6 @@
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
|
||||
"integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"shebang-regex": "^1.0.0"
|
||||
}
|
||||
@@ -5505,8 +5718,7 @@
|
||||
"shebang-regex": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz",
|
||||
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
|
||||
"dev": true
|
||||
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM="
|
||||
},
|
||||
"shellwords": {
|
||||
"version": "0.1.1",
|
||||
@@ -5517,8 +5729,7 @@
|
||||
"signal-exit": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
|
||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
|
||||
"dev": true
|
||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
|
||||
},
|
||||
"sisteransi": {
|
||||
"version": "1.0.4",
|
||||
@@ -5871,8 +6082,7 @@
|
||||
"strip-eof": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
|
||||
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8="
|
||||
},
|
||||
"strip-json-comments": {
|
||||
"version": "2.0.1",
|
||||
@@ -6091,8 +6301,7 @@
|
||||
"tslib": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz",
|
||||
"integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ=="
|
||||
},
|
||||
"tsutils": {
|
||||
"version": "3.17.1",
|
||||
@@ -6103,6 +6312,11 @@
|
||||
"tslib": "^1.8.1"
|
||||
}
|
||||
},
|
||||
"tunnel": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
||||
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
|
||||
},
|
||||
"tunnel-agent": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
|
||||
@@ -6165,6 +6379,14 @@
|
||||
"set-value": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"universal-user-agent": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-4.0.1.tgz",
|
||||
"integrity": "sha512-LnST3ebHwVL2aNe4mejI9IQh2HfZ1RLo8Io2HugSif8ekzD1TlWpHpColOB/eh8JHMLkGH3Akqf040I+4ylNxg==",
|
||||
"requires": {
|
||||
"os-name": "^3.1.0"
|
||||
}
|
||||
},
|
||||
"unset-value": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unset-value/-/unset-value-1.0.0.tgz",
|
||||
@@ -6323,7 +6545,6 @@
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
|
||||
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"isexe": "^2.0.0"
|
||||
}
|
||||
@@ -6334,6 +6555,14 @@
|
||||
"integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=",
|
||||
"dev": true
|
||||
},
|
||||
"windows-release": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/windows-release/-/windows-release-3.2.0.tgz",
|
||||
"integrity": "sha512-QTlz2hKLrdqukrsapKsINzqMgOUpQW268eJ0OaOpJN32h272waxR9fkB9VoWRtK7uKHG5EHJcTXQBD8XZVJkFA==",
|
||||
"requires": {
|
||||
"execa": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"word-wrap": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
|
||||
@@ -6382,8 +6611,7 @@
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
},
|
||||
"write": {
|
||||
"version": "1.0.3",
|
||||
|
||||
@@ -5,13 +5,12 @@
|
||||
"description": "TypeScript template action",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"pack": "ncc build",
|
||||
"test": "jest",
|
||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
||||
"build": "npm run format-check && npm run lint && npm run test && tsc",
|
||||
"pack": "rm -rf ./lib ./dist && npm run build && ncc build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -25,7 +24,9 @@
|
||||
"author": "YourNameOrOrganization",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.0"
|
||||
"@actions/core": "^1.2.0",
|
||||
"@actions/github": "^2.1.1",
|
||||
"rxjs": "^6.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.23",
|
||||
|
||||
41
src/delete.ts
Normal file
41
src/delete.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import {Input} from './input'
|
||||
import {Observable, of, throwError} from 'rxjs'
|
||||
import {deletePackageVersions, getOldestVersions} from './version'
|
||||
import {concatMap, map} from 'rxjs/operators'
|
||||
|
||||
export function getVersionIds(input: Input): Observable<string[]> {
|
||||
if (input.packageVersionIds.length > 0) {
|
||||
return of(input.packageVersionIds)
|
||||
}
|
||||
|
||||
if (input.hasOldestVersionQueryInfo()) {
|
||||
return getOldestVersions(
|
||||
input.owner,
|
||||
input.repo,
|
||||
input.packageName,
|
||||
input.numOldVersionsToDelete,
|
||||
input.token
|
||||
).pipe(map(versionInfo => versionInfo.map(info => info.id)))
|
||||
}
|
||||
|
||||
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"
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteVersions(input: Input): Observable<boolean> {
|
||||
if (!input.token) {
|
||||
return throwError('No token found')
|
||||
}
|
||||
|
||||
if (input.numOldVersionsToDelete <= 0) {
|
||||
console.log(
|
||||
'Number of old versions to delete input is 0 or less, no versions will be deleted'
|
||||
)
|
||||
return of(true)
|
||||
}
|
||||
|
||||
return getVersionIds(input).pipe(
|
||||
concatMap(ids => deletePackageVersions(ids, input.token))
|
||||
)
|
||||
}
|
||||
47
src/input.ts
Normal file
47
src/input.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
export interface InputParams {
|
||||
packageVersionIds?: string[]
|
||||
owner?: string
|
||||
repo?: string
|
||||
packageName?: string
|
||||
numOldVersionsToDelete?: number
|
||||
token?: string
|
||||
}
|
||||
|
||||
const defaultParams = {
|
||||
packageVersionIds: [],
|
||||
owner: '',
|
||||
repo: '',
|
||||
packageName: '',
|
||||
numOldVersionsToDelete: 0,
|
||||
token: ''
|
||||
}
|
||||
|
||||
export class Input {
|
||||
packageVersionIds: string[]
|
||||
owner: string
|
||||
repo: string
|
||||
packageName: string
|
||||
numOldVersionsToDelete: number
|
||||
token: string
|
||||
|
||||
constructor(params?: InputParams) {
|
||||
const validatedParams: Required<InputParams> = {...defaultParams, ...params}
|
||||
|
||||
this.packageVersionIds = validatedParams.packageVersionIds
|
||||
this.owner = validatedParams.owner
|
||||
this.repo = validatedParams.repo
|
||||
this.packageName = validatedParams.packageName
|
||||
this.numOldVersionsToDelete = validatedParams.numOldVersionsToDelete
|
||||
this.token = validatedParams.token
|
||||
}
|
||||
|
||||
hasOldestVersionQueryInfo(): boolean {
|
||||
return !!(
|
||||
this.owner &&
|
||||
this.repo &&
|
||||
this.packageName &&
|
||||
this.numOldVersionsToDelete > 0 &&
|
||||
this.token
|
||||
)
|
||||
}
|
||||
}
|
||||
42
src/main.ts
42
src/main.ts
@@ -1,19 +1,35 @@
|
||||
import * as core from '@actions/core'
|
||||
import {wait} from './wait'
|
||||
import {getInput, setFailed} from '@actions/core'
|
||||
import {context} from '@actions/github'
|
||||
import {Input} from './input'
|
||||
import {Observable, throwError} from 'rxjs'
|
||||
import {deleteVersions} from './delete'
|
||||
import {catchError} from 'rxjs/operators'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
function getActionInput(): Input {
|
||||
return new Input({
|
||||
packageVersionIds: getInput('package-version-ids')
|
||||
? getInput('package-version-ids').split(',')
|
||||
: [],
|
||||
owner: getInput('owner') ? getInput('owner') : context.repo.owner,
|
||||
repo: getInput('repo') ? getInput('repo') : context.repo.repo,
|
||||
packageName: getInput('package-name'),
|
||||
numOldVersionsToDelete: Number(getInput('num-old-versions-to-delete')),
|
||||
token: getInput('token')
|
||||
})
|
||||
}
|
||||
|
||||
function run(): Observable<boolean> {
|
||||
try {
|
||||
const ms: string = core.getInput('milliseconds')
|
||||
core.debug(`Waiting ${ms} milliseconds ...`)
|
||||
|
||||
core.debug(new Date().toTimeString())
|
||||
await wait(parseInt(ms, 10))
|
||||
core.debug(new Date().toTimeString())
|
||||
|
||||
core.setOutput('time', new Date().toTimeString())
|
||||
return deleteVersions(getActionInput()).pipe(
|
||||
catchError(err => throwError(err))
|
||||
)
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
return throwError(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
run().subscribe({
|
||||
error: err => {
|
||||
setFailed(err)
|
||||
}
|
||||
})
|
||||
|
||||
66
src/version/delete-version.ts
Normal file
66
src/version/delete-version.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import {from, Observable, merge, throwError, of} from 'rxjs'
|
||||
import {graphql} from '@octokit/graphql'
|
||||
import {catchError, map, tap} from 'rxjs/operators'
|
||||
import {GraphQlQueryResponse} from '@octokit/graphql/dist-types/types'
|
||||
|
||||
export interface DeletePackageVersionMutationResponse {
|
||||
deletePackageVersion: {
|
||||
success: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = `
|
||||
mutation deletePackageVersion($packageVersionId: String!) {
|
||||
deletePackageVersion(input: {packageVersionId: $packageVersionId}) {
|
||||
success
|
||||
}
|
||||
}`
|
||||
|
||||
export function deletePackageVersion(
|
||||
packageVersionId: string,
|
||||
token: string
|
||||
): Observable<boolean> {
|
||||
return from(
|
||||
graphql(mutation, {
|
||||
packageVersionId,
|
||||
headers: {
|
||||
authorization: `token ${token}`,
|
||||
Accept: 'application/vnd.github.package-deletes-preview+json'
|
||||
}
|
||||
}) as Promise<DeletePackageVersionMutationResponse>
|
||||
).pipe(
|
||||
catchError((err: GraphQlQueryResponse) => {
|
||||
const msg = 'delete version mutation failed.'
|
||||
return throwError(
|
||||
err.errors && err.errors.length > 0
|
||||
? `${msg} ${err.errors[0].message}`
|
||||
: `${msg} verify input parameters are correct`
|
||||
)
|
||||
}),
|
||||
map(response => response.deletePackageVersion.success)
|
||||
)
|
||||
}
|
||||
|
||||
export function deletePackageVersions(
|
||||
packageVersionIds: string[],
|
||||
token: string
|
||||
): Observable<boolean> {
|
||||
if (packageVersionIds.length === 0) {
|
||||
console.log('no package version ids found, no versions will be deleted')
|
||||
return of(true)
|
||||
}
|
||||
|
||||
const deletes = packageVersionIds.map(id =>
|
||||
deletePackageVersion(id, token).pipe(
|
||||
tap(result => {
|
||||
if (result) {
|
||||
console.log(`version with id: ${id}, deleted`)
|
||||
} else {
|
||||
console.log(`version with id: ${id}, not deleted`)
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
return merge(...deletes)
|
||||
}
|
||||
111
src/version/get-versions.ts
Normal file
111
src/version/get-versions.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import {graphql} from '@octokit/graphql'
|
||||
import {GraphQlQueryResponse} from '@octokit/graphql/dist-types/types'
|
||||
import {Observable, from, throwError} from 'rxjs'
|
||||
import {catchError, map} from 'rxjs/operators'
|
||||
|
||||
export interface VersionInfo {
|
||||
id: string
|
||||
version: string
|
||||
}
|
||||
|
||||
export interface GetVersionsQueryResponse {
|
||||
repository: {
|
||||
packages: {
|
||||
edges: {
|
||||
node: {
|
||||
name: string
|
||||
versions: {
|
||||
edges: {node: VersionInfo}[]
|
||||
}
|
||||
}
|
||||
}[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const query = `
|
||||
query getVersions($owner: String!, $repo: String!, $package: String!, $last: Int!) {
|
||||
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(query, {
|
||||
owner,
|
||||
repo,
|
||||
package: packageName,
|
||||
last: numVersions,
|
||||
headers: {
|
||||
authorization: `token ${token}`,
|
||||
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(
|
||||
owner: string,
|
||||
repo: string,
|
||||
packageName: string,
|
||||
numVersions: number,
|
||||
token: string
|
||||
): Observable<VersionInfo[]> {
|
||||
return queryForOldestVersions(
|
||||
owner,
|
||||
repo,
|
||||
packageName,
|
||||
numVersions,
|
||||
token
|
||||
).pipe(
|
||||
map(result => {
|
||||
if (result.repository.packages.edges.length < 1) {
|
||||
throwError(
|
||||
`package: ${packageName} not found for owner: ${owner} in repo: ${repo}`
|
||||
)
|
||||
}
|
||||
|
||||
const versions = result.repository.packages.edges[0].node.versions.edges
|
||||
|
||||
if (versions.length !== numVersions) {
|
||||
console.log(
|
||||
`number of versions requested was: ${numVersions}, but found: ${versions.length}`
|
||||
)
|
||||
}
|
||||
|
||||
return versions
|
||||
.map(value => ({id: value.node.id, version: value.node.version}))
|
||||
.reverse()
|
||||
})
|
||||
)
|
||||
}
|
||||
2
src/version/index.ts
Normal file
2
src/version/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './get-versions'
|
||||
export * from './delete-version'
|
||||
@@ -1,9 +0,0 @@
|
||||
export async function wait(milliseconds: number): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
if (isNaN(milliseconds)) {
|
||||
throw new Error('milliseconds not a number')
|
||||
}
|
||||
|
||||
setTimeout(() => resolve('done!'), milliseconds)
|
||||
})
|
||||
}
|
||||
@@ -8,5 +8,5 @@
|
||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
"exclude": ["node_modules", "__tests__"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user