Skip to content

Commit

Permalink
change update-go-mod.sh to use head of main for fosite via config file
Browse files Browse the repository at this point in the history
  • Loading branch information
cfryanr committed Dec 5, 2023
1 parent e1954b1 commit 3bd89c2
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 10 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ replace (

require (
github.com/MakeNowJust/heredoc/v2 v2.0.1
github.com/chromedp/cdproto v0.0.0-20231126232103-8e31ff06e23b
github.com/chromedp/cdproto v0.0.0-20231205062650-00455a960d61
github.com/chromedp/chromedp v0.9.3
github.com/coreos/go-oidc/v3 v3.8.0
github.com/coreos/go-semver v0.3.1
Expand All @@ -50,7 +50,7 @@ require (
github.com/gorilla/websocket v1.5.1
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/ory/fosite v0.0.0-20231113125121-dfa2c0a1b63c
github.com/ory/fosite v0.44.1-0.20231113125121-dfa2c0a1b63c
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/pkg/errors v0.9.1
github.com/sclevine/spec v1.4.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chromedp/cdproto v0.0.0-20231011050154-1d073bb38998/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/cdproto v0.0.0-20231126232103-8e31ff06e23b h1:SywfM3985mh0PaXhiZbgR+VQFSfFXJSNLX2p+3vBvOc=
github.com/chromedp/cdproto v0.0.0-20231126232103-8e31ff06e23b/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/cdproto v0.0.0-20231205062650-00455a960d61 h1:XD280QPATe9jaz20dylKe3vBsNcH1w3mkssGY0lidn8=
github.com/chromedp/cdproto v0.0.0-20231205062650-00455a960d61/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/chromedp v0.9.3 h1:Wq58e0dZOdHsxaj9Owmfcf+ibtpYN1N0FWVbaxa/esg=
github.com/chromedp/chromedp v0.9.3/go.mod h1:NipeUkUcuzIdFbBP8eNNvl9upcceOfWzoJn6cRe4ksA=
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
Expand Down Expand Up @@ -429,8 +429,8 @@ github.com/openzipkin/zipkin-go v0.4.1 h1:kNd/ST2yLLWhaWrkgchya40TJabe8Hioj9udfP
github.com/openzipkin/zipkin-go v0.4.1/go.mod h1:qY0VqDSN1pOBN94dBc6w2GJlWLiovAyg7Qt6/I9HecM=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
github.com/ory/fosite v0.0.0-20231113125121-dfa2c0a1b63c h1:6uLFYRLJINWw1NzUJUxrSihHBs/2l2U0FFZjhBH2WsI=
github.com/ory/fosite v0.0.0-20231113125121-dfa2c0a1b63c/go.mod h1:fkMPsnm/UjiefE9dE9CdZQGOH48TWJLIzUcdGIXg8Kk=
github.com/ory/fosite v0.44.1-0.20231113125121-dfa2c0a1b63c h1:F44CFBukG42RKXwuBLmbADDQI9rFhTZJQEsedOmuYaA=
github.com/ory/fosite v0.44.1-0.20231113125121-dfa2c0a1b63c/go.mod h1:fkMPsnm/UjiefE9dE9CdZQGOH48TWJLIzUcdGIXg8Kk=
github.com/ory/go-acc v0.2.9-0.20230103102148-6b1c9a70dbbe h1:rvu4obdvqR0fkSIJ8IfgzKOWwZ5kOT2UNfLq81Qk7rc=
github.com/ory/go-acc v0.2.9-0.20230103102148-6b1c9a70dbbe/go.mod h1:z4n3u6as84LbV4YmgjHhnwtccQqzf4cZlSk9f1FhygI=
github.com/ory/go-convenience v0.1.0 h1:zouLKfF2GoSGnJwGq+PE/nJAE6dj2Zj5QlTgmMTsTS8=
Expand Down
54 changes: 51 additions & 3 deletions hack/update-go-mod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,37 @@ import (
"log"
"os"
"path/filepath"
"strings"

"golang.org/x/mod/modfile"
)

func main() {
goModFilepath := filepath.Clean(os.Args[1])
overridesFilepath := filepath.Clean(os.Args[2])

if _, err := os.Stat(goModFilepath); err != nil {
log.Fatalf("File '%s' does not exist\n", goModFilepath)
}

if _, err := os.Stat(overridesFilepath); err != nil {
log.Fatalf("File '%s' does not exist\n", overridesFilepath)
}

var (
bytes []byte
err error
bytes []byte
overrides map[string]string
err error
)

if bytes, err = os.ReadFile(overridesFilepath); err != nil {
log.Fatalf("Unable to read file '%s'\n", overridesFilepath)
}

if overrides, err = parseOverrides(string(bytes)); err != nil {
log.Fatalf("Parse error in file '%s': %s\n", overridesFilepath, err.Error())
}

if bytes, err = os.ReadFile(goModFilepath); err != nil {
log.Fatalf("Unable to read file '%s'\n", goModFilepath)
}
Expand All @@ -34,9 +50,41 @@ func main() {

for _, require := range file.Require {
if !require.Indirect {
fmt.Printf("go get %s &&\n", require.Mod.Path)
mod := require.Mod.Path
overrideMod, hasOverride := overrides[mod]
if hasOverride {
mod = overrideMod
}
fmt.Printf("go get %s &&\n", mod)
}
}

fmt.Printf("./hack/module.sh tidy\n")
}

func parseOverrides(overridesText string) (map[string]string, error) {
overridesMap := map[string]string{}

lines := strings.Split(overridesText, "\n")

for i, line := range lines {
trimmedLine := strings.TrimSpace(line)

if strings.HasPrefix(trimmedLine, "#") || len(trimmedLine) == 0 {
continue
}

splitLine := strings.Split(trimmedLine, " ")

if len(splitLine) != 2 {
return nil, fmt.Errorf(
"error on line %d: found %d tokens instead of 2 tokens",
i+1, len(splitLine),
)
}

overridesMap[splitLine[0]] = splitLine[1]
}

return overridesMap, nil
}
5 changes: 5 additions & 0 deletions hack/update-go-mod/overrides.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Format:
# package_name_as_it_appears_in_go_mod package_name_as_it_should_be_used_with_go_get

# Fosite has not had a release for a long time, so use the head of their main branch.
github.com/ory/fosite github.com/ory/fosite@master
5 changes: 4 additions & 1 deletion hack/update-go-mod/update-go-mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ ROOT_DIR="$SCRIPT_DIR/../.."
GO_MOD="${ROOT_DIR}/go.mod"

pushd "${SCRIPT_DIR}" > /dev/null
script=$(go run . "${GO_MOD}")
script=$(go run . "${GO_MOD}" overrides.conf)
popd > /dev/null

# Print to screen for debugging purposes.
echo "$script"

pushd "${ROOT_DIR}" > /dev/null
eval "$script"
popd > /dev/null

0 comments on commit 3bd89c2

Please sign in to comment.