generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
Showing
21 changed files
with
38,303 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,4 +96,6 @@ Thumbs.db | |
|
||
# Ignore built ts files | ||
__tests__/runner/* | ||
lib/**/* | ||
lib/**/* | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
# Usage | ||
|
||
## Create an action from this template | ||
```yaml | ||
- 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: | ||
``` | ||
Click the `Use this Template` and provide the new repo details for your action | ||
# Scenarios | ||
## Code in Master | ||
* [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) | ||
Install the dependencies | ||
```bash | ||
$ npm install | ||
``` | ||
### Delete a specific version of a package hosted in the same repo as the workflow | ||
Build the typescript | ||
```bash | ||
$ npm run build | ||
``` | ||
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. | ||
Run the tests :heavy_check_mark: | ||
```bash | ||
$ npm test | ||
Package version ids can be retrieved via the [GitHub GraphQL API][api] | ||
PASS ./index.test.js | ||
✓ throws invalid number (3ms) | ||
✓ wait 500 ms (504ms) | ||
✓ test runs (95ms) | ||
__Example__ | ||
... | ||
```yaml | ||
- uses: actions/delete-package-versions@v1 | ||
with: | ||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3' | ||
``` | ||
## Change action.yml | ||
<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__. | ||
The action.yml contains defines the inputs and output for your action. | ||
__Example__ | ||
Update the action.yml with your name, description, inputs and outputs for your action. | ||
```yaml | ||
- uses: actions/delete-package-versions@v1 | ||
with: | ||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3' | ||
token: ${{ secrets.GITHUB_PAT }} | ||
``` | ||
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions) | ||
<br> | ||
## Change the Code | ||
### Delete multiple specific versions of a package hosted in the same repo as the workflow | ||
Most toolkit and CI/CD operations involve async operations so the action is run in an async function. | ||
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. | ||
```javascript | ||
import * as core from '@actions/core'; | ||
... | ||
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]. | ||
async function run() { | ||
try { | ||
... | ||
} | ||
catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
__Example__ | ||
run() | ||
```yaml | ||
- uses: actions/delete-package-versions@v1 | ||
with: | ||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw' | ||
``` | ||
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages. | ||
<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. | ||
## Publish to a distribution branch | ||
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]. | ||
Actions are run from GitHub repos. We will create a releases branch and only checkin production modules (core in this case). | ||
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__. | ||
Comment out node_modules in .gitignore and create a releases/v1 branch | ||
```bash | ||
# comment out in distribution branches | ||
# node_modules/ | ||
__Example__ | ||
```yaml | ||
- uses: actions/delete-package-versions@v1 | ||
with: | ||
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw' | ||
token: ${{ secrets.GITHUB_PAT }} | ||
``` | ||
```bash | ||
$ git checkout -b releases/v1 | ||
$ git commit -a -m "prod dependencies" | ||
<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' | ||
``` | ||
```bash | ||
$ npm prune --production | ||
$ git add node_modules | ||
$ git commit -a -m "prod dependencies" | ||
$ git push origin releases/v1 | ||
<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 }} | ||
``` | ||
Your action is now published! :rocket: | ||
<br> | ||
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) | ||
### Delete oldest x number of versions of a package hosted in the same repo as the workflow | ||
## Validate | ||
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. | ||
You can now validate the action by referencing the releases/v1 branch | ||
__Example__ | ||
Delete the oldest 3 version of a package hosted in the same repo as the workflow | ||
```yaml | ||
uses: actions/typescript-action@releases/v1 | ||
with: | ||
milliseconds: 1000 | ||
- uses: actions/delete-package-versions@v1 | ||
with: | ||
package-name: 'test-package' | ||
num-old-versions-to-delete: 3 | ||
``` | ||
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket: | ||
<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__. | ||
## Usage: | ||
__Example__ | ||
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 the oldest 3 version of a package hosted in a different repo than the one executing the workflow | ||
```yaml | ||
uses: actions/typescript-action@v1 | ||
with: | ||
milliseconds: 1000 | ||
- 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 | ||
Oops, something went wrong.