Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add support for deleting packages on new GitHub Packages architecture #83

Merged
merged 26 commits into from Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -7,6 +7,9 @@ on: # rebuild any PRs and main branch changes
- main
- 'releases/*'

permissions:
packages: write

jobs:

package: # make sure build/ci work properly
Expand All @@ -29,6 +32,6 @@ jobs:
- uses: ./
name: Smoke Test Delete Package Versions Action
with:
package-name: 'com.github.actions.test-package'
package-name: 'action-ci-test-package'
package-type: 'npm'
num-old-versions-to-delete: 0
min-versions-to-keep: 0
2 changes: 1 addition & 1 deletion .licenses/npm/@octokit/rest.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 32 additions & 22 deletions README.md
Expand Up @@ -2,8 +2,6 @@

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.

_This action does currently not support deleting packages from the GitHub Container Registry. As the npm registry is about to be migrated to the same new architecture as GHCR, this action won't work for npm soon too (see [#74](https://github.com/actions/delete-package-versions/issues/74))._

### What It Can Do

* Create a retention policy (delete all except n most recent pre-release versions)
Expand All @@ -30,16 +28,14 @@ _This action does currently not support deleting packages from the GitHub Contai
# 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.
# Required
package-name:

# Type of the package.
# Required
package-type:

# The number of old versions to delete starting from the oldest version.
# Defaults to 1.
num-old-versions-to-delete:
Expand Down Expand Up @@ -72,7 +68,7 @@ _This action does currently not support deleting packages from the GitHub Contai

# Valid Input Combinations

`owner`, `repo`, `package-name` and `token` can be used with the following combinations in a workflow -
`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`
Expand Down Expand Up @@ -106,10 +102,11 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
package-name: 'test-package'
package-type: 'npm'
min-versions-to-keep: 10
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__.

Expand All @@ -121,8 +118,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
owner: 'github'
repo: 'packages'
package-name: 'test-package'
package-type: 'npm'
token: ${{ secrets.GITHUB_PAT }}
min-versions-to-keep: 10
delete-only-pre-release-versions: "true"
Expand All @@ -142,11 +139,12 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
package-name: 'test-package'
package-type: 'npm'
min-versions-to-keep: 3
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__.

Expand All @@ -158,8 +156,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
owner: 'github'
repo: 'packages'
package-name: 'test-package'
package-type: 'npm'
token: ${{ secrets.GITHUB_PAT }}
min-versions-to-keep: 3
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
Expand All @@ -181,11 +179,12 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
package-name: 'test-package'
package-type: 'npm'
num-old-versions-to-delete: 3
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.

Expand All @@ -199,8 +198,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
owner: 'github'
repo: 'packages'
package-name: 'test-package'
package-type: 'npm'
token: ${{ secrets.PAT }}
num-old-versions-to-delete: 3
ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
Expand All @@ -220,10 +219,11 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
package-name: 'test-package'
package-type: 'npm'
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__.

Expand All @@ -235,8 +235,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
owner: 'github'
repo: 'packages'
package-name: 'test-package'
package-type: 'npm'
token: ${{ secrets.PAT }}
min-versions-to-keep: 2
```
Expand All @@ -255,10 +255,11 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
package-name: 'test-package'
package-type: 'npm'
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__.

Expand All @@ -270,8 +271,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
owner: 'github'
repo: 'packages'
package-name: 'test-package'
package-type: 'npm'
num-old-versions-to-delete: 3
token: ${{ secrets.GITHUB_PAT }}
```
Expand All @@ -288,9 +289,10 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
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__.

Expand All @@ -300,8 +302,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
owner: 'github'
repo: 'packages'
package-name: 'test-package'
package-type: 'npm'
token: ${{ secrets.PAT }}
```

Expand All @@ -319,6 +321,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
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.
Expand All @@ -333,6 +337,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3'
package-name: 'test-package'
package-type: 'npm'
token: ${{ secrets.PAT }}
```

Expand All @@ -350,6 +356,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw'
package-name: 'test-package'
package-type: 'npm'
```

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.
Expand All @@ -364,6 +372,8 @@ _This action does currently not support deleting packages from the GitHub Contai
- uses: actions/delete-package-versions@v3
with:
package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw'
package-name: 'test-package'
package-type: 'npm'
token: ${{ secrets.PAT }}
```

Expand Down