Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 2

how to list packages and versions in github package registry?

Solved! Go to Solution.

What is the best way to list github packages in a script?

 

Thanks,

Tom

1 Reply
Solution
Copilot Lvl 3
Message 2 of 2

Re: how to list packages and versions in github package registry?

...after a little bit of hacking I came up with the following bash script, using GraphQL/curl/jq:

graphqlQuery() {
  local query="$1"; shift

  curl -s -H "Authorization: bearer $INPUT_TOKEN" -X POST -d '{"query":"'"$query"'"}' 'https://api.github.com/graphql'
}
listPackageVersions() {
  local g="$1"; shift
  local a="$1"; shift

  local query="$(cat <<EOF | sed 's/"/\\"/g' | tr '\n\r' '  '
query {
    repository(owner:"$USERNAME", name:"$REPOSNAME"){
        registryPackages(name:"$g.$a",first:1) {
            nodes {
                versions(last:100) {
                    nodes {
                        version
                    }
                }
            }
        }
    }
}
EOF
)"
  graphqlQuery "$query" | jq -r '.data.repository.registryPackages.nodes[0].versions.nodes[].version'
}

just thought I'd share it.

 

-Tom