Add helper script to give you all the commands to update all go mod dependencies

This commit is contained in:
Joshua Casey 2023-03-01 16:18:25 -06:00
parent 205559b4f3
commit 947b4fd579
5 changed files with 69 additions and 0 deletions

View File

@ -8,6 +8,12 @@ updates:
schedule: schedule:
interval: "daily" interval: "daily"
- package-ecosystem: "gomod"
open-pull-requests-limit: 2
directory: "/hack/update-go-mod"
schedule:
interval: "daily"
- package-ecosystem: "docker" - package-ecosystem: "docker"
directory: "/" directory: "/"
schedule: schedule:

View File

@ -0,0 +1,5 @@
module go.pinniped.dev/update-go-mod
go 1.18
require golang.org/x/mod v0.8.0

View File

@ -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=

View File

@ -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")
}

View File

@ -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