Manually deleting a package from GitHub Package Registry

November 1, 2019   ·   3 min read

github graphql package registry

You were so excited about the new Package Registry that you immediately added it to your build and published your first package. Unfortunately, it is the time when you realize you had a typo in the name or the group id of your package.

Let’s quickly delete the package and publish again. But not with GitHub. While the documentation states that deleting packages may be possible, it’s not easily available. You can either go through GitHub Support or use the GraphQL API. How to do the latter is something I tried and thought it would be useful to document here for others.

First off, we need to find the internal ids for the packages we want to delete. The easiest way to access data on GitHub using the GitHub GraphQL API is GitHubs GraphQL API Explorer.

Using the following GraphQL query we can find the packages currently available in our repository. Note that you need to change owner, name, version to match the package you want to find. In case you have a lot of packages, you may need to adapt the first filter as well. In order for this to work, you need to ensure that the token used by the API explorer does have the ['read:packages'] scope.

query {
  repository(owner:"bmuskalla", name:"package-test") {
    registryPackages(first:10){
      nodes {
        nameWithOwner
        packageType
        version(version:"0.1.0"){
          id
        }
      }
    }
  }
}

My current packages in that project I used for testing look like in the following screenshot. We have 2 packages using the maven package type.

GitHub Packages

Using the query above, you should see a a response similar to the following.

{
  "data": {
    "repository": {
      "registryPackages": {
        "nodes": [
          {
            "nameWithOwner": "bmuskalla/oopsi",
            "packageType": "MAVEN",
            "version": null
          },
          {
            "nameWithOwner": "bmuskalla/oopsi.package-test",
            "packageType": "MAVEN",
            "version": {
              "id": "MDE0OlBhY3thZ2VWZXJzaW9uMjMzMDUx"
            }
          }
        ]
      }
    }
  }
}

Above we can see the internal ids for each individual package (careful to use the version id). Using this identifier, we can come up with the right deletePackageVersion mutation to delete the package.

mutation {
  deletePackageVersion(input:{packageVersionId:"MDE0OlBhY3thZ2VWZXJzaW9uMjMxNDMw"}) {
    success
  }
}

Given the GitHub GraphQL API Explorer does not allow mutation requests out-of-the-box, you need to resort to the console or your GraphQL tool of choice. Personally, I use the Altair GraphQL client. Using that, you need to setup the proper token for authenticating against the GitHub API using:

Authorization: bearer <YOURTOKEN>

And to enable the developer preview for the API we’re using, you need to use the Accept header:

Accept: application/vnd.github.package-deletes-preview+json

If all worked out, you should get a confirmation that the package version got deleted.

{
  "data": {
    "deletePackageVersion": {
      "success": true
    }
  }
}

If there is nothing left in the package, it should be gone from the UI as well.

GitHub Packages

Happy Packaging!



comments powered by Disqus