From 947b4fd5792410f9435a6675816f2b1f2342190e Mon Sep 17 00:00:00 2001 From: Joshua Casey Date: Wed, 1 Mar 2023 16:18:25 -0600 Subject: [PATCH] Add helper script to give you all the commands to update all go mod dependencies --- .github/dependabot.yml | 6 +++++ hack/update-go-mod/go.mod | 5 ++++ hack/update-go-mod/go.sum | 2 ++ hack/update-go-mod/main.go | 42 +++++++++++++++++++++++++++++ hack/update-go-mod/update-go-mod.sh | 14 ++++++++++ 5 files changed, 69 insertions(+) create mode 100644 hack/update-go-mod/go.mod create mode 100644 hack/update-go-mod/go.sum create mode 100644 hack/update-go-mod/main.go create mode 100755 hack/update-go-mod/update-go-mod.sh diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b67bf4f5..c106b0f1 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,6 +8,12 @@ updates: schedule: interval: "daily" + - package-ecosystem: "gomod" + open-pull-requests-limit: 2 + directory: "/hack/update-go-mod" + schedule: + interval: "daily" + - package-ecosystem: "docker" directory: "/" schedule: diff --git a/hack/update-go-mod/go.mod b/hack/update-go-mod/go.mod new file mode 100644 index 00000000..29351324 --- /dev/null +++ b/hack/update-go-mod/go.mod @@ -0,0 +1,5 @@ +module go.pinniped.dev/update-go-mod + +go 1.18 + +require golang.org/x/mod v0.8.0 diff --git a/hack/update-go-mod/go.sum b/hack/update-go-mod/go.sum new file mode 100644 index 00000000..083110b4 --- /dev/null +++ b/hack/update-go-mod/go.sum @@ -0,0 +1,2 @@ +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= diff --git a/hack/update-go-mod/main.go b/hack/update-go-mod/main.go new file mode 100644 index 00000000..ce61031c --- /dev/null +++ b/hack/update-go-mod/main.go @@ -0,0 +1,42 @@ +package main + +// Copyright 2023 the Pinniped contributors. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import ( + "fmt" + "log" + "os" + "path/filepath" + + "golang.org/x/mod/modfile" +) + +func main() { + goModFilepath := filepath.Clean(os.Args[1]) + + if _, err := os.Stat(goModFilepath); err != nil { + log.Fatalf("File '%s' does not exist\n", goModFilepath) + } + + var ( + bytes []byte + err error + ) + if bytes, err = os.ReadFile(goModFilepath); err != nil { + log.Fatalf("Unable to read file '%s'\n", goModFilepath) + } + + file, err := modfile.Parse(goModFilepath, bytes, nil) + if err != nil { + log.Fatalf("Unable to parse file '%s'\n", goModFilepath) + } + + for _, require := range file.Require { + if !require.Indirect { + fmt.Printf("go get %s &&\n", require.Mod.Path) + } + } + + fmt.Printf("./hack/module.sh tidy\n") +} diff --git a/hack/update-go-mod/update-go-mod.sh b/hack/update-go-mod/update-go-mod.sh new file mode 100755 index 00000000..7abde96c --- /dev/null +++ b/hack/update-go-mod/update-go-mod.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Copyright 2023 the Pinniped contributors. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +GO_MOD="${SCRIPT_DIR}/../../go.mod" + +pushd "${SCRIPT_DIR}" > /dev/null + go run . "${GO_MOD}" +popd > /dev/null