mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-01-07 14:05:50 +00:00
change update-go-mod.sh to use head of main for fosite via config file
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -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
hack/update-go-mod/overrides.conf
Normal file
5
hack/update-go-mod/overrides.conf
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user