Skip to content

Commit

Permalink
chore: generate-formulas improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
petethepig committed Oct 11, 2023
1 parent 9814290 commit 21ea4f5
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
13 changes: 12 additions & 1 deletion scripts/generate-formulas/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@ module github.com/grafana/pyroscope/homebrew-brew/scripts/generate-formulas

go 1.19

require github.com/jzelinskie/must v0.0.1
require (
github.com/google/go-github/v55 v55.0.0
github.com/jzelinskie/must v0.0.1
)

require (
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
)
25 changes: 25 additions & 0 deletions scripts/generate-formulas/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-github/v55 v55.0.0 h1:4pp/1tNMB9X/LuAhs5i0KQAE40NmiR/y6prLNb9x9cg=
github.com/google/go-github/v55 v55.0.0/go.mod h1:JLahOTA1DnXzhxEymmFF5PP2tSS9JVNj68mSZNDwskA=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/jzelinskie/must v0.0.1 h1:LT7fxrQCW9yWDkjnF75XFvODjKb6Su7qlx2LO8967Y8=
github.com/jzelinskie/must v0.0.1/go.mod h1:BTPQ0S/fIbENkk9zFU4JBtdtB+B4vibfTyeDC48z6zc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
48 changes: 46 additions & 2 deletions scripts/generate-formulas/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
Expand All @@ -11,6 +12,7 @@ import (
"strings"
"text/template"

"github.com/google/go-github/v55/github"
"github.com/jzelinskie/must"
)

Expand Down Expand Up @@ -44,10 +46,52 @@ func main() {
return
}

githubToken := os.Getenv("GITHUB_TOKEN")
if githubToken == "" {
panic("Please specify GITHUB_TOKEN env variable")
return
}

// at this point the releases are not public, so we have to be logged in to github
// and exchange a tag for a browser download url
ghClient := github.NewClient(nil).WithAuthToken(githubToken)
// orgs, _, err := client.Organizations.List(context.Background(), "willnorris", nil)
releases, _, err := ghClient.Repositories.ListReleases(context.Background(), "grafana", "pyroscope", nil)
if err != nil {
panic(err)
}

tag := os.Args[1]
url := fmt.Sprintf("https://github.com/grafana/pyroscope/releases/download/%s/checksums.txt", tag)

res := must.NotError(http.Get(url))
var targetRelease *github.RepositoryRelease
for _, release := range releases {
releaseTag := release.GetTagName()
if releaseTag == tag {
targetRelease = release
break
}
}
if targetRelease == nil {
panic(fmt.Errorf("could not find release: %s", tag))
}

var assetUrl string
for _, asset := range targetRelease.Assets {
if asset.GetName() == "checksums.txt" {
assetUrl = asset.GetURL()
break
}
}

if assetUrl == "" {
panic(fmt.Errorf("could not find checksums.txt file in release: %s", tag))
}

fmt.Printf("Downloading checksums.txt from %s\n", assetUrl)

req := must.NotError(http.NewRequest("GET", assetUrl, nil))
req.Header.Set("Accept", "application/octet-stream")
res := must.NotError(ghClient.BareDo(context.Background(), req))
if res.StatusCode != 200 {
panic(fmt.Errorf("got status code %d", res.StatusCode))
}
Expand Down

0 comments on commit 21ea4f5

Please sign in to comment.