GithubHelp home page GithubHelp logo

delete-package-versions's Introduction

Delete Package Versions

This action deletes versions of a package from GitHub Packages. This action will only delete a maximum of 100 versions in one run.

What It Can Do

  • Create a retention policy (delete all except n most recent pre-release versions)
  • Delete all package versions except n most recent versions
  • Delete oldest version(s)
  • Ignore version(s) from deletion through regex
  • Delete version(s) of a package that is hosted from a repo having access to package
  • Delete version(s) of a package that is hosted from a repo not having access to package
  • Delete a single version
  • Delete multiple versions
  • Delete specific version(s)

Usage

- uses: actions/delete-package-versions@v5
  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 package.
  # Defaults to the owner of the repo executing the workflow.
  # Required if deleting a version from a package hosted in a different org than the one executing the workflow.
  owner:

  # Name of the package.
  # Required
  package-name:

  # Type of the package. Can be one of docker (v4 or older), container (v5 or newer), maven, npm, nuget, or rubygems.
  # Required
  package-type:

  # The number of old versions to delete starting from the oldest version.
  # Defaults to 1.
  num-old-versions-to-delete:

  # The number of latest versions to keep.
  # This cannot be specified with `num-old-versions-to-delete`. By default, `min-versions-to-keep` takes precedence over `num-old-versions-to-delete`.
  # When set to 0, all deletable versions will be deleted.
  # When set greater than 0, all deletable package versions except the specified number will be deleted.
  min-versions-to-keep:

  # The package versions to exclude from deletion.
  # Takes regex for the version name as input.
  # By default nothing is ignored. This is ignored when `delete-only-pre-release-versions` is true
  ignore-versions:

  # If true it will delete only the pre-release versions.
  # 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.
  # Defaults to false.
  # Cannot be used with `num-old-versions-to-delete` and `ignore-versions`.
  delete-only-pre-release-versions:

  # If true it will delete only the untagged versions in case of container package.
  # Does not work for other package types and will be ignored.
  # The number of untagged versions to keep can be set by using `min-versions-to-keep` value with this.
  # When `min-versions-to-keep` is 0, all untagged versions get deleted.
  # Defaults to false.
  # Cannot be used with `num-old-versions-to-delete`.
  delete-only-untagged-versions:

  # The token used to authenticate with GitHub Packages.
  # Defaults to github.token.
  # Required if the repo running the workflow does not have access to delete the package.
  #   For rubygems and maven package, repo has access if package is hosted in the same repo as the workflow.
  #   For container, npm and nuget package, repo has access if assigned **Admin** role under Package Settings > Manage Actions Access.
  #   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:

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
  • delete-only-untagged-versions
  • min-versions-to-keep + delete-only-untagged-versions

Scenarios

  • Delete Package Versions

  • Usage

  • Valid Input Combinations

  • Scenarios

  • License

    Delete all pre-release versions except y latest pre-release package versions

    To delete all pre release versions except y latest pre-release package versions, the package-name, min-versions-to-keep and delete-only-pre-release-versions inputs are required.

    Example

    Delete all pre-release package versions except latest 10

    - uses: actions/delete-package-versions@v5
      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 from a repo not having access to package, the owner, package-name, token, min-versions-to-keep and delete-only-pre-release-versions inputs are required.

    Example

    Delete all pre-release package versions except latest 10 from a repo not having access to package

    - uses: actions/delete-package-versions@v5
      with: 
        owner: 'github'
        package-name: 'test-package'
        package-type: 'npm'
        token: ${{ secrets.GITHUB_PAT }}
        min-versions-to-keep: 10
        delete-only-pre-release-versions: "true"

    Delete all untagged container versions except y latest untagged versions

    To delete all untagged versions of a container package except y latest untagged versions, the package-name, package-type, min-versions-to-keep and delete-only-untagged-versions inputs are required. package-type must be container for this scenario.

    Example

    Delete all untagged versions except latest 10

    - uses: actions/delete-package-versions@v5
      with: 
        package-name: 'test-package'
        package-type: 'container'
        min-versions-to-keep: 10
        delete-only-untagged-versions: 'true'

    Delete all except y latest versions while ignoring particular package versions

    To delete all except y latest versions while ignoring particular package versions, the package-name, min-versions-to-keep and ignore-versions inputs are required.

    Example

    Delete all except latest 3 package versions excluding major versions as per semver

    - uses: actions/delete-package-versions@v5
      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 from a repo not having access to package, the owner, package-name, token, min-versions-to-keep and ignore-versions inputs are required.

    The token needs the delete packages and read packages scope. It is recommended to store the token as a secret. In this example the token was stored as a secret named GITHUB_PAT.

    Example

    Delete all except latest 3 package versions excluding major versions as per semver from a repo not having access to package

    - uses: actions/delete-package-versions@v5
      with: 
        owner: 'github'
        package-name: 'test-package'
        package-type: 'npm'
        token: ${{ secrets.GITHUB_PAT }}
        min-versions-to-keep: 3
        ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'

    Delete oldest x number of versions while ignoring particular package versions

    To delete oldest x number of versions while ignoring all the major package versions, the package-name, num-oldest-versions-to-delete and ignore-versions inputs are required.

    There is a possibility if the oldest x number of versions contain ignored package versions, actual package versions to get deleted will be less than x.

    Example

    Delete 3 oldest versions excluding major versions as per semver

    - uses: actions/delete-package-versions@v5
      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 from a repo not having access to package, 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.

    Example

    Delete 3 oldest versions excluding major versions as per semver from a repo not having access to package

    - uses: actions/delete-package-versions@v5
      with: 
        owner: 'github'
        package-name: 'test-package'
        package-type: 'npm'
        token: ${{ secrets.PAT }}
        num-old-versions-to-delete: 3
        ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'

    Delete all except y latest versions of a package

    To delete all except y latest versions of a package hosted, the package-name and min-versions-to-keep inputs are required.

    Example

    Delete all except latest 2 versions of a package hosted

    - uses: actions/delete-package-versions@v5
      with:
        package-name: 'test-package'
        package-type: 'npm'
        min-versions-to-keep: 2

    To delete all except y latest versions of a package hosted from a repo not having access to package, the owner, package-name, token and min-versions-to-keep inputs are required.

    The token needs the delete packages and read packages scope. It is recommended to store the token as a secret. In this example the token was stored as a secret named GITHUB_PAT.

    Example

    Delete all except latest 2 versions of a package hosted from a repo not having access to package

    - uses: actions/delete-package-versions@v5
      with:
        owner: 'github'
        package-name: 'test-package'
        package-type: 'npm'
        token: ${{ secrets.PAT }}
        min-versions-to-keep: 2

    Delete oldest x number of versions of a package

    To delete the oldest x number of versions of a package hosted, the package-name, and num-old-versions-to-delete inputs are required.

    Example

    Delete the oldest 3 version of a package hosted

    - uses: actions/delete-package-versions@v5
      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 from a repo not having access to package, the owner, package-name, token and num-old-versions-to-delete inputs are required.

    The token needs the delete packages and read packages scope. It is recommended to store the token as a secret. In this example the token was stored as a secret named GITHUB_PAT.

    Example

    Delete the oldest 3 version of a package hosted from a repo not having access to package

    - uses: actions/delete-package-versions@v5
      with:
        owner: 'github'
        package-name: 'test-package'
        package-type: 'npm'
        num-old-versions-to-delete: 3
        token: ${{ secrets.GITHUB_PAT }}

    Delete oldest version of a package

    To delete the oldest version of a package that is hosted, the package-name input is required.

    Example

    - uses: actions/delete-package-versions@v5
      with:
        package-name: 'test-package'
        package-type: 'npm'

    To delete the oldest version of a package that is hosted from a repo not having access to package, the owner, package-name, token inputs are required.

    Example

    - uses: actions/delete-package-versions@v5
      with:
        owner: 'github'
        package-name: 'test-package'
        package-type: 'npm'
        token: ${{ secrets.PAT }}

    Delete a specific version of a package

    To delete a specific version of a package that is hosted, the package-version-ids input is required.

    Package version ids can be retrieved via the GitHub REST API

    Example

    - uses: actions/delete-package-versions@v5
      with:
        package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3'
        package-name: 'test-package'
        package-type: 'npm'

    To delete a specific version of a package that is hosted from a repo not having access to package, the package-version-ids and token inputs are required.

    Package version ids can be retrieved via the GitHub REST API

    Example

    - uses: actions/delete-package-versions@v5
      with:
        package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3'
        package-name: 'test-package'
        package-type: 'npm'
        token: ${{ secrets.PAT }}

    Delete multiple specific versions of a package

    To delete multiple specific versions of a package that is hosted, 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 REST API.

    Example

    - uses: actions/delete-package-versions@v5
      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 from a repo not having access to package, 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 REST API.

    Example

    - uses: actions/delete-package-versions@v5
      with:
        package-version-ids: 'MDE0OlBhY2thZ2VWZXJzaW9uOTcyMDY3, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzQ5, MDE0OlBhY2thZ2VWZXJzaW9uOTcyMzUw'
        package-name: 'test-package'
        package-type: 'npm'
        token: ${{ secrets.PAT }}

License

The scripts and documentation in this project are released under the MIT License

delete-package-versions's People

Contributors

brcrista avatar chrispat avatar cwille97 avatar dependabot[bot] avatar ericsciple avatar gaelgoth avatar jidicula avatar kgrzebien avatar nadesu avatar namratajha avatar nishthagupta avatar nweiler avatar ralfstuckert avatar s-anupam avatar shyam-grover avatar starkej2 avatar takost avatar thboop avatar tinaheidinger avatar trent-j avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

delete-package-versions's Issues

No way to only keep tagged versions with `min-versions-to-keep`

We were trying to use this action to clean up a Docker package/repo we use exclusively for build cache. This is because our actual images to go AWS ECR, which does not have production ready build cache support. aws/containers-roadmap#876

We also chose this over using GH Actions cache, as we haven't optimised our container size and filled the Actions cache quota very quickly.

We were trying to run this action twice in a workflow to one to delete all the untagged versions and one to clear out old tagged versions.

Because we've let our build cache images pile up, not all untagged images were deleted, and the second action, which uses min-versions-to-keep removed some tagged images. This was unexpected for us, as we thought that the action would ignore untagged images when considering which images to keep.

Essentially this change to src/delete.ts is what we expected.
image

However, I understand changing this behaviour would be a breaking change, and add further complexity to this action. It could instead be part of another input, but the inputs are very complex already. #110

We've also realised that this action is better used as an ongoing cleanup, rather than trying to make it go back and clean up what's already piled up. Perhaps some mention of this in the documentation could be helpful.

Feature request: Keep specific versions

It would be nice that we can specify versions to keep. For example within the docker universe is package called latest which points to/contains the last stable version. For every push there will be at least one version added and the latest version updated.

At the moment the "latest" version will be deleted because it is the oldest created version.

Need some help to configure variables

I use github packages to store docker images.
Imagine I have this package ghcr.io/alpha/beta:latest
When I execute this command: docker pull ghcr.io/alpha/beta:latest everything is working, it means that the package itself is correctly resolved.

So, according to the data I provided, what values should I set to variables: owner, repo, package-name ?

This configuration did not work for me:

      - name: Cleanup package registry
        uses: actions/delete-package-versions@v3
        with:
          owner: 'alpha'
          repo: 'beta'
          package-name: 'beta'
          token: ${{ secrets.GH_PAT_PACKAGES }}
          min-versions-to-keep: 2

with flags are underindented

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:

Feature request: Delete preview versions from previous releases

It would be helpful in managing packages using semantic versioning 2 and preview packages to be able to automatically drop the preview versions once a release version is out. For example, I'm working on bug fixes for a package that is currently released at version 1.2.3 and so I've been pushing previews like 1.2.4-build.1, 1.2.4-build.2, etc. as I go. Once I release 1.2.4 I'd like all those previews (build.1, build.2, etc.) to be removed.

Rename default branch

๐Ÿ‘‹ This issue is to track the move over to using main as the default branch for this repo. Weโ€™d love your team's help in completing this transition.

Do not remove your old default branch, customers are going to be using it. We will be sending messages out about these changes, but if you want to message in your repository, that's fine as well.

  • Create a main branch.
  • You might need to rebase any pull requests you want to merge before changing the default branch.
  • Change the default branch in settings to main.
  • Update any documentation in this repo to refer to the new branch name, although using the version tag is still preferred.
  • Check that this Action works correctly for users who have a repository with a custom default branch name.
  • Close this issue and celebrate ๐ŸŽ‰

We are aiming to complete this work by July 17th July 24th.

Ignore-Versions parameter is not support for random version numbers.

Hi, I have tried to delete the packages with the random version numbers like 3.5.4, 3.6.5, 3.7.21, and 3.8.6 in the ignore-versions parameter. It deletes all the packages in my repository except the latest version. As Guideline said, we need to use the regex for the ignore-versions parameter, but there are fewer possibilities to use the regex in our case. Is there any option to pass the random versions in the ignore-versions parameter?

My Workflow:

name: Removing old artifacts
on:
  registry_package:
    types: [published]
jobs:
  delete-old-packages:
    runs-on: ubuntu-latest
    steps:
      - name: Delete package
        uses: actions/delete-package-versions@v4
        with:
          package-name:  com.sample.test.app
          package-type: maven
          token: ${{ secrets.TOKEN }}
          min-versions-to-keep: 1
          ignore-versions: 2.3.6 

I tried to pass the ignore-versions parameter like below:
ignore-versions: '2.3.6,2.3.1,2.3.5'
ignore-versions: "2.3.6,2.3.1,2.3.5"
ignore-versions: '2.3.6 2.3.1 2.3.5'
ignore-versions: 2.3.6, 2.3.1, 2.3.5

Multi-arch containers

It's cumbersome to know how many versions make up a single build of a multi-arch container. It seems that each distro needs it's own version, but then there are some magic ones that are also around. It could be that I'm misconfiguring my build. Here's my jobs:

jobs:
  docker:
    name: Docker
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v3
      - uses: docker/setup-qemu-action@v2
      - uses: docker/setup-buildx-action@v2
        with:
          platforms: 'linux/amd64,linux/arm64'
      - id: version
        shell: bash
        run: echo "version=$(date +%Y%m%d%H%M%S)" >> $GITHUB_OUTPUT
      - uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GH_TOKEN }}
      - uses: docker/build-push-action@v3
        with:
          context: '.'
          push: true
          platforms: 'linux/amd64,linux/arm64'
          tags: ${{ env.BUILD_DOCKER_IMAGE }}:${{ steps.version.outputs.version }},${{ env.BUILD_DOCKER_IMAGE }}:latest
          cache-from: type=registry,ref=${{ env.BUILD_DOCKER_IMAGE }}:latest
          cache-to: type=inline
      - uses: actions/delete-package-versions@v4
        with:
          package-name: ${{ env.APP_NAME }}
          package-type: container
          min-versions-to-keep: 1
          token: ${{ secrets.GH_TOKEN }}

When this runs and I try to pull afterward, I get manifest unknown. When I bump it to 2, same thing. 3, sometimes works but sometimes not. 4 seemed to consistently work until this morning. My goal is to only store the latest docker image but I'm having trouble figuring out how to selectively keep all the "latest" images for the various architectures I need to support.

All packages get deleted recursively

Hello developers,

Hope you're having a nice day. I got a problem while using this action which I have described below

I have created an action where I want to delete the oldest version of the same package which is updated.

Let's say I have 3 versions 1.0, 1.1, 1.2 and then when I update the package to v1.4, v1.0 should get deleted. But I realized that with each delete, same action is triggered again and it goes in infinite loop.

So is there any workaround for this? May be you include a new type like new_version or something. Just an idea.

Content of YAML file looks something like this

name: Delete oldest package

on:
  registry_package:
   type: [updated]

jobs:
  delete_package:
    runs-on: ubuntu-latest
    steps:
      - name: Delete package version
        uses: actions/[email protected]
        with:
          package-name: com.md.calculator
          num-old-versions-to-delete: 1

invalid input min-versions-to-keep

I am getting the following warning with

    - uses: actions/delete-package-versions@v1
      with: 
        package-name: 'com.integ.auto-task'
        min-versions-to-keep: 35
        num-old-versions-to-delete: 0

image
Not sure if need to reference a new version or something.

Error when using delete-package-versions from a different repo

I'm using delete-package-versions as part of a reusable workflow that I call from others. It works as long as my reusable workflow and the calling workflow are in the same repo as the package is hosted. But when I try to call it from a workflow in a different repo (owned by the same account), it fails with Error: get versions API failed. Resource not accessible by integration

Here's my reusable workflow:

name: _ Publish with Gradle

on:
  workflow_call:
    inputs:
      project-folder:
        required: false
        type: string
        default: .
      package-name:
        required: true
        type: string
      java-version:
        type: string
        default: '17'

jobs:
  gradle-publish:

    runs-on: ubuntu-latest

    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up JDK ${{ inputs.java-version}}
        uses: actions/setup-java@v3
        with:
          java-version: ${{ inputs.java-version}}
          distribution: 'temurin'

      - name: Gradle publish
        uses: gradle/gradle-build-action@v2
        with:
          arguments: publish --scan
          build-root-directory: ${{ inputs.project-folder }}

      - name: 'Clean old pre-release versions'
        uses: actions/delete-package-versions@v4
        with: 
          package-name: ${{ inputs.package-name }}
          package-type: 'maven'
          min-versions-to-keep: 10
          delete-only-pre-release-versions: true

Here's an example of calling that workflow:

name: Publish my-lib library

on:
  workflow_dispatch:
  push:
    branches:
      - master
      - release/**

jobs:
  publish_my-lib:
    uses: ./.github/workflows/gradle-publish-project.yml
    with:
      java-version: '17'
      package-name: 'com.me.my-lib'

The actual publish works correctly, but for some reason the delete-package-versions step fails when it's cross-repo. I've enabled read-write permissions on the repos.

Feature Request: Delete unused packages

When browsing the package registry on GitHub Packages I can see an indicator on how often a certain package version has been downloaded. I have several packages that have never been downloaded. They have been built before I fully setup a CI pipeline.

I don't know if this is a nice feature to have, but maybe you could implement a "delete packages that have been downloaded fewer than X times" feature? Defaults to zero. Maybe in conjunction with the "older than X days" feature? Would look like this: "Delete packages that are older than X days and have been downloaded Y times or less".

Delete by version name

Would be nice to have an option to delete version by version name (not version id which is hard to fetch based on name). In my workflow I publish packages upon new release based on tag name. And upon release deletion I remove tag and associated with it deployed version.
Currently I has to resort to regex negative look-ahead to achieve this feature:

- name: Delete published package
  uses: actions/delete-package-versions@v2
  with:
    package-name: "${{ github.event.repository.name }}"
    ignore-versions: ^(?!${{ github.event.release.tag_name }}).*$
    token: ${{ secrets.GITHUB_TOKEN }}

Since you already checking version names via regex, wouldn't it be easy to implement
package-version-names which would work same way as package-version-ids except would match version names ?

Thanks in advance

Package not found

I'm trying to delete old package versions in a GitHub Actions workflow on private repository. Packages are under the same repository where GitHub Actions run. I can see them in the repository home page and by making API call with GH CLI.

I'm using the autogenerated GITHUB_TOKEN.

When I run the step with this action i get the following:

Run actions/delete-package-versions@v2
  with:
    package-name: sylius-project.php
    min-versions-to-keep: 5
    ignore-versions: latest
    num-old-versions-to-delete: 1
    delete-only-pre-release-versions: false
    token: ***

(node:35689) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
package: sylius-project.php not found for owner: webgriffe in repo: sylius-project
no package version ids found, no versions will be deleted

As you can see I get a deprecation warning but what is worst is that it says that the package syliu-project.php cannot be found for that repository.

I cannot understand why. Anyone could help me?

Is it possible to delete superfluous artifacts from a snapshot version?

Hi there,

Sorry to raise an issue for this but I can't figure it out using the readme alone. When you publish snapshots using maven you end up with an entire set of artifacts against a package with a different timestamp for every single build, this is resulting in me having a package version of say, 0.0.2-SNAPSHOT but it has a billion artifacts underneath it, a full set from each time the snapshot was built.

Is it possible to retain only the latest set of artifacts against a package version with this action? I only ever need the latest snapshot, I'm going to max my GitHub storage on one snapshot version at this rate :(

Thanks for your time,
Fhox

[Feature Request] Support multiple packages

Right now just a single package is supported with package-name. I tried specifying a list but that doesn't work. It would be great if multiple packages could be supported.

Container Registry Support

Is there a plan to update this action to support container registry, or make a delete-container-versions action?

Keep N versions of both release and pre-release packages

Is it possible to keep N versions of both release and pre-release packages rather than any version.

Scenario:
I would like to delete both old release and pre-release packages. However, with the current set-up there is a possibility of losing either all release or all pre-release packages. This would mainly be used for private packages.

Thanks!

Action failing with Unexpected input(s) 'min-versions-to-keep'.

I have a simple private package being published. Since I'm the only user, I don't want to bother with versioning and want to keep it as v1.0.0 always.

My workflow is as follows:

name: Build and Deploy

on:
  push:
    branches:
      - master
jobs:
  publish-gpr:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/delete-package-versions@v1
        with:
          package-name: 'lullo-utils'
          min-versions-to-keep: 1
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 16
          registry-url: https://npm.pkg.github.com/
          scope: '@LulloIO'
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.LULLO_PKG_TOKENREADONLY}}

But the action fails with:
Unexpected input(s) 'min-versions-to-keep', valid inputs are ['package-version-ids', 'owner', 'repo', 'package-name', 'num-old-versions-to-delete', 'token']

I got this idea from the README.

Is this some bug?

ignore-versions doesn't seem to work with container packages (ghcr)

Trying to use ignore-versions with the new support for ghcr container package types, but it doesn't seem to work. I am trying to delete beta packages when pushing into the develop branch, and non beta packages when pushing into main. But ATM it just deletes the packages regardless of the name.

My full example config is here:

name: CI

on:
  push:
    branches:
      - "**"
  pull_request:
    branches:
      - "**"

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: npm install
        run: npm install

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Docker build
        if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
        run: node ./node_modules/gulp/bin/gulp.js ci-docker-build
        env:
          DEBUG: true

      - name: Docker publish
        if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
        run: node ./node_modules/gulp/bin/gulp.js ci-docker-publish
        env:
          DEBUG: true

      - name: Docker cleanup develop images
        if: github.ref == 'refs/heads/develop'
        uses: actions/delete-package-versions@v4
        with:
          package-name: 'dave-test'
          package-type: 'container'
          min-versions-to-keep: 2
          ignore-versions: '^((?!beta).)*$'

      - name: Docker cleanup production images
        if: github.ref == 'refs/heads/main'
        uses: actions/delete-package-versions@v4
        with:
          package-name: 'dave-test'
          package-type: 'container'
          min-versions-to-keep: 3
          ignore-versions: 'beta'

TypeError: Cannot read property 'node' of undefined

My configuration

    - name: Delete old versions of this packages
      uses: actions/delete-package-versions@main
      with:
        owner: hyrendev
        repo: nexus
        package-name: |
          com.redefantasy.core-bungee
          com.redefantasy.core-shared
          com.redefantasy.core-spigot
        token: ${{ secrets.ACCESS_TOKEN }}

Action output:

Run actions/delete-package-versions@main
  with:
    owner: hyrendev
    repo: nexus
    package-name: com.redefantasy.core-bungee
  com.redefantasy.core-shared
  com.redefantasy.core-spigot
  
    token: ***
    num-old-versions-to-delete: 1
  env:
    MAVEN_USERNAME: ***
    MAVEN_PASSWORD: ***
    JAVA_HOME: /opt/hostedtoolcache/Java_Adopt_jdk/8.0.282-8/x64

Throws:

Error: TypeError: Cannot read property 'node' of undefined

Feature request - with include-versions regexp

Feature request, to have an additional input parameter include-versions with a regexp.

Have a regexp for versions that are to be included for deletion.
Similar to the ignore-versions but for inclusion instead.

In some cases one wants to delete based on a specific version regexp, and creating the ignore regexp is more complex.

Improve documentation/examples for dynamic version ids

Perhaps I'm too much of a n00b, but I'm finding it difficult to get this working with dynamic version ids.

My use case is that I build and push a docker container for every branch. The version (tag) on the container is the branch name.
What I'd like to do is delete the versions which match the branch name when I delete the branch.

Here's what I've attempted

name: Delete branch tag

on:
  delete:
    branches: [ '**' ]

jobs:
  cleanup:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/delete-package-versions@v1
        with:
          package-version-ids: ${GITHUB_REF##*/}

But this results in an error:

Error: delete version mutation failed. Could not resolve to a node with the global id of '${GITHUB_REF##*/}'

The docs/examples don't give enough help/direction on how to get the version ids other than telling me to go look at the GH APIs. Is there a related action that I should use to get this, how have other people tackled deleting versions dynamically?

Action is very complex because of handling both packages and containers.

We're very glad to have an official action to handle this as we've just ignored this until it's become a problem.

However, the inputs are very complicated, and hard to reason about, and this mostly seems to be related to trying to handle containers.

It may be more maintainable in the long run to split this into two actions and simplify the inputs.

actions/delete-package-versions and actions/delete-container-versions

Packages are not deleted despite the success message being returned

I used this action to delete over 250 packages in 3 runs due to 99 limitations per run.
Each run correctly showed 99 removals + the last one 52 - as it removed it.

But all packages are still visible in a browser when I check it here:
https://github.com/OWNER/REPO/pkgs/npm/PACKAGE_NAME/versions

Re-running the action is not removing anything anymore.

Package not found when deleting oldest version of a package

Hi.
Since yesterday I have not been able to delete a package, 2 days ago it was working correctly.

My configuration

I want to delete oldest version of a package.

      - name: delete oldest version of a package
        uses: actions/delete-package-versions@v3
        with:
          package-name: "shared-all"

Output

Run actions/delete-package-versions@v3
  with:
    package-name: shared-all
    num-old-versions-to-delete: 1
    min-versions-to-keep: -1
    ignore-versions: ^$
    delete-only-pre-release-versions: false
    token: ***
package: shared-all not found for owner: Newt-Inc in repo: newt

I am not getting any errors, but I cannot find the package and delete it.

My package info

  • I use GitHub Packages Registry https://npm.pkg.github.com

I haven't changed any settings for the past two days.
Can you help fixing it?

Feature request: Delete specific package version

It would be cool if you could specify the package version number in the package-name like:

package-name: [email protected]
package-name: org.sample.artifact-name@latest

And then only that version of the package will be deleted

As it is not all package versions are deleted with the name org.sample.artifact-name

Doesn't delete the oldest version

The documentation states the following:

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:

- uses: actions/delete-package-versions@v1
  with:
    package-name: 'test-package'

Using this script will delete the newest - 1 package, rather than the oldest package. See here:

image

The action creates images tagged 1586947709 and latest. delete-package-versions runs and deletes latest, and it should have deleted 1583451815 according to the documentation.

num-old-versions-to-delete: 1 deletes `docker-base-layer`

After publishing 3 Docker images and using num-old-versions-to-delete: 1, I noticed that docker-base-layer was deleted rather than the oldest tag.

You can see it being deleted here:

image

The docker-base-layer no longer exists here:
https://github.com/jcansdale-test/delete-package-versions/runs/900578034?check_suite_focus=true#step:12:11

The issue can be reproduced with the following workflow:

on: [push, workflow_dispatch]

env:
  IMAGE_NAME: image-to-delete

jobs:
  push-and-delete:
    runs-on: ubuntu-latest

    steps:
    - run: docker pull alpine

    - run: docker login https://docker.pkg.github.com -u token --password-stdin <<< ${{ secrets.GITHUB_TOKEN }}

    - run: docker tag alpine:latest docker.pkg.github.com/${{ github.repository }}/${{ env.IMAGE_NAME }}:0.1
    - run: docker tag alpine:latest docker.pkg.github.com/${{ github.repository }}/${{ env.IMAGE_NAME }}:0.2
    - run: docker tag alpine:latest docker.pkg.github.com/${{ github.repository }}/${{ env.IMAGE_NAME }}:latest

    - run: docker push docker.pkg.github.com/${{ github.repository }}/${{ env.IMAGE_NAME }}:0.1
    - run: docker push docker.pkg.github.com/${{ github.repository }}/${{ env.IMAGE_NAME }}:0.2
    - run: docker push docker.pkg.github.com/${{ github.repository }}/${{ env.IMAGE_NAME }}:latest

    - run: docker run jcansdale/gpr files ${{ github.repository }} -k ${{ secrets.GITHUB_TOKEN }}

    - uses: actions/delete-package-versions@v1
      with:
        package-name: ${{ env.IMAGE_NAME }}
        num-old-versions-to-delete: 1

    - run: docker run jcansdale/gpr files ${{ github.repository }} -k ${{ secrets.GITHUB_TOKEN }}

delete-only-pre-release-versions throws Error: query for oldest version failed.

If there are too many steps in a workflow then it throws an error.

Run actions/[email protected]
  with:
    package-name: Package.Name
    min-versions-to-keep: 10
    delete-only-pre-release-versions: true
    num-old-versions-to-delete: 1
    ignore-versions: ^$
    token: ***
(node:1585) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Error: query for oldest version failed. verify input parameters are correct

I have 50 packages and noticed that the first five or so always seemed to run successfully, even when I changed the order in which packages were deleted. I have one step per package.
As a work around, I split the workflow into ten separate workflows, with five steps in each one. They all run successfully when the number of steps/packages is limited to a few per workflow.

Add support for deletion of container and npm packages

This action currently does not work with GitHub Container Registry packages. Also, the npm registry is about to be migrated to the same new architecture as GHCR, this action won't work for npm soon too.

To do: adapt this action to work with the new GitHub Package Registry achitecture in order to support deleting packages from container and npm registries.

Error when deleting packages

I'm using NuGet packages in my GitHub packages, and I've set up a manual workflow to allow me to delete all but the 5 latest versions. It looks like this

name: Delete Old CI Builds

on:
  workflow_dispatch:

jobs:
  DeleteOldCiBuilds:
	name: Delete old CI releases
	runs-on: ubuntu-latest
	steps:
	- name: Delete Package Versions
	  uses: actions/[email protected]
	  with:
		package-name: MyPackageName
		min-versions-to-keep: 5
		token: ${{ github.token }}

However, when it runs, I get the following error message

Error: delete version mutation failed. Type mismatch on variable $packageVersionId and argument packageVersionId (String! / ID!)

The only other strange thing I noticed is that even know I was only using min-versions-to-keep, num-old-versions-to-delete still showed up in the full output.

Full output

Run actions/[email protected]
  with:
	package-name: MyPackageName
	min-versions-to-keep: 5
	token: ***
	num-old-versions-to-delete: 1
	ignore-versions: ^$
	delete-only-pre-release-versions: false
(node:1564) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Total versions deleted till now: 2
Error: delete version mutation failed. Type mismatch on variable $packageVersionId and argument packageVersionId (String! / ID!)

Also, even though it says Total versions deleted till now: 2, I checked my package versions, and no versions have been deleted.

A sample of what the versioning looks like for the package is

  • 0.0.5-ci-2215317956
  • 0.0.5
  • 0.0.4
  • 0.0.2-ci-2215161916
  • 0.0.2-ci-2215112987

I'd really appreciate any help fixing the issue as I would like to add this to one of my scheduled workflows, but it was causing it to fail.

Delete packages by download count

I use GitHub Actions for automated publishing of prereleases and releases, and find that I want to automate purging of unused prereleases.

Would it be possible to add download count as a filter to which packages to delete with this Action?

Cannot read property 'packages' of null

Hi!

I'm using the following code to remove old versions from another repository wich is private:

 - uses: actions/delete-package-versions@v1
    with:
      owner: '---'
      repo: '---'
      package-name: '---'
      num-old-versions-to-delete: 1
      token: ${{ secrets.CI_PACKAGES_READ_DELETE_TOKEN }}

I have created a personal access token with read and write packages permissions and stored as secret on the repository that is firing the action, but this error is thrown:

Cannot read property 'packages' of null

Any help on this?

Thank you!

Delete oldest x number of versions of a package but keep a minimum

Honestly this could probably be more easily accomplished with implementing #5 (keep only N latest versions of package) but how would I keep a minimum number of versions of a package?

If I just use the example:

- uses: actions/delete-package-versions@v1
  with:
    package-name: 'test-package'
    num-old-versions-to-delete: 10

This would delete the 10 oldest versions. But what if I only have 8 versions?

What if I want to at least keep the last three versions around?

Mark this repository as unmaintained

Sadly we haven't got the time to maintain this repository as an official GitHub Action. In the last year or two since we originally published this, a large number of really good community Actions have appeared on the Marketplace. There's likely some good alternatives that are maintained that we could recommend instead.

We'd like to mark this repository as unmaintained and make it clear to users what their expectations should be. When its archived, it will continue to work for all existing Actions users, but won't receive any updates.

People are of course free to fork this repository and maintain those forks if they like.

To do this we'll:

  • Remove it from the Marketplace
  • Remove from any official GitHub documentation.
  • Change the README.md to clearly reflect its new state.
  • Update the README.md to point to other community Actions.
  • Archive this repository, putting it read-only mode.

API rate limit exceeded

I keep getting an error about an API rate limit.

query for oldest version failed. API rate limit exceeded for installation ID 20433984.

name: Delete Package Versions

on:
  push:
    branches:
      - main

jobs:
  delete:
    runs-on: ubuntu-latest
    name: Remove 100
    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
      - uses: actions/setup-node@v2
        with:
          node-version: 14
      - uses: actions/delete-package-versions@v1
        with:
          owner: "lewismoten"
          repo: "MY_REPO_NAME"
          package-name: "MY_REPO_NAME"
          num-old-versions-to-delete: 100
          token: ${{ secrets.GITHUB_TOKEN }}

After I deleted versions I can't push anymore

I used github as a docker registry . I tried to cleanup using this package, after I deleted 100 + docker images , I can't no longer push from github actions and I keep getting 500 error code every time I try to push from github actions.

I'm pretty sure it is related with the deletion of images.

Any help is appreciated

Error: get versions API failed. Package not found.

I use delete-package-versions to remove NPM packages of previous builds. If there is no package left, then not only the version is gone but also the entire NPM package is gone. That is not necessarily a problem, but on rerunning builds which fail (after committing a fix) the delete-package-versions also fails since the entire package is not found:

Run actions/[email protected]
  with:
    package-name: my-awesome-library
    package-type: npm
    min-versions-to-keep: 0
    ignore-versions: ^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$
    num-old-versions-to-delete: 1
    delete-only-pre-release-versions: false
    delete-only-untagged-versions: false
    token: ***
  env:
    NODE_AUTH_TOKEN: XXXXX-XXXXX-XXXXX-XXXXX
Error: get versions API failed. Package not found.

Can you please treat this edge-case as there were no versions to delete?

Error: delete version mutation failed. Type mismatch on variable $packageVersionId and argument packageVersionId (String! / ID!)

Hi,
I got this error since today, two days ago the action was still working:

Run actions/delete-package-versions@v[2](https://github.com/philippthiele/local-frontend/runs/5343785718?check_suite_focus=true#step:7:2)
  with:
    package-name: local-frontend
    min-versions-to-keep: 1
    num-old-versions-to-delete: 1
    ignore-versions: ^$
    delete-only-pre-release-versions: false
    token: ***
  env:
    NPM_CONFIG_USERCONFIG: /home/runner/work/_temp/.npmrc
    NODE_AUTH_TOKEN: XXXXX-XXXXX-XXXXX-XXXXX
(node:28[3](https://github.com/philippthiele/local-frontend/runs/5343785718?check_suite_focus=true#step:7:3)0) [DEP000[5](https://github.com/philippthiele/local-frontend/runs/5343785718?check_suite_focus=true#step:7:5)] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Total versions deleted till now: 1
Error: delete version mutation failed. Type mismatch on variable $packageVersionId and argument packageVersionId (String! / ID!)

Can you help fixing it?
Thanks and BR

version_id parameter must be an integer

So I'm hitting this strange issue I can't quite explain when deleting a package version on ghcr.io:

Error: delete version API failed. The version_id parameter must be an integer. 

Full output:

Run actions/delete-package-versions@v4
  with:
    package-version-ids: gha4622410040-g3d94762cffc166ff549a28c3710ca44cdddc4f2a
    package-name: system-tests/runner
    package-type: container
    num-old-versions-to-delete: 1
    min-versions-to-keep: -1
    ignore-versions: ^$
    delete-only-pre-release-versions: false
    delete-only-untagged-versions: false
    token: ***
  env:
    REGISTRY: ghcr.io
Total versions deleted till now: 1
Error: delete version API failed. The version_id parameter must be an integer. 
0 versions deleted till now.

Usage in workflow:

    steps:
      ...
      - uses: actions/delete-package-versions@v4
        with:
          package-version-ids: gha${{ github.run_id }}-g${{ github.sha }}
          package-name: system-tests/${{ matrix.image }}
          package-type: 'container'
        continue-on-error: true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.