sops icon indicating copy to clipboard operation
sops copied to clipboard

programmatically get latest sops stable release

Open roblon opened this issue 3 years ago • 2 comments

Can you please provide a way to get Sops latest stable release programmatically?

With a REST request for instance, something like so:

curl -L https://github.com/mozilla/sops/releases/download?version=latest&system=win

Thanks!

roblon avatar Nov 09 '22 14:11 roblon

Not part of the team, just stumbled on the issue. Github already provides you with an API to list releases (GraphQL: https://docs.github.com/en/graphql/overview/about-the-graphql-api)

I was looking at something similar and basically this is roughly how to do it: Contents of /tmp/sops.q

{
    "query": "{
        repository(owner: \"mozilla\", name: \"sops\") {
            releases(first: 1, orderBy: {field: CREATED_AT, direction: DESC}) {
                nodes {
                    releaseAssets(first: 20) {
                        nodes {
                            downloadUrl
                        }
                    }
                }
            }
        }
    }"
}

Then you can run something like this:

$ curl -sH 'Authorization: Bearer <YOUR TOKEN>' -X POST -d @sops.q https://api.github.com/graphql | jq -r '..| select (.downloadUrl?) |.downloadUrl |match(".*exe$")|.string'

This will output URL of the latest windows release of sops. One way to do it anyway...

sochotnicky avatar Nov 20 '22 12:11 sochotnicky

The easiest way would be if the assets would be available like sops.linux.amd64 (in order to prevent breaking existing scripts the old asset names should still be available). This way one could just run curl -Lo /usr/local/bin/sops https://github.com/getsops/sops/releases/latest/download/sops.linux.amd64. Currently in a container with no package manager one must run the following instead of the one-liner (or two when counting chmod in):

set -euo pipefail

curl -Lo /usr/local/bin/jq https://github.com/jqlang/jq/releases/latest/download/jq-linux-amd64
chmod +x /usr/local/bin/jq

tagName="$(curl https://api.github.com/repos/getsops/sops/releases/latest | jq -r .tag_name)"
curl -Lo /usr/local/bin/sops "https://github.com/getsops/sops/releases/download/$tagName/sops-$tagName.linux.amd64"
chmod +x /usr/local/bin/sops

Is there any chance to include assets without a version in their name @felixfontein (only pinging you as you released version 3.11.0)?

ProbstDJakob avatar Oct 28 '25 11:10 ProbstDJakob