Skip to content

Commit f45e67e

Browse files
Dentraxhectorj2f
andauthored
introduce new --skip-initial-tidy flag (#36)
* add --skip-initial-tidy flag This flag would be useful for the cases where old packages contains old dependencies that would require to do _replace_ or _update_ before running `go mod tidy`. Signed-off-by: Dentrax <[email protected]> * add test for skip tidy Signed-off-by: Dentrax <[email protected]> * set GoVersion Signed-off-by: Hector Fernandez <[email protected]> Signed-off-by: hectorj2f <[email protected]> --------- Signed-off-by: Dentrax <[email protected]> Signed-off-by: Hector Fernandez <[email protected]> Signed-off-by: hectorj2f <[email protected]> Co-authored-by: Hector Fernandez <[email protected]>
1 parent f403a69 commit f45e67e

File tree

7 files changed

+418
-15
lines changed

7 files changed

+418
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ gobump --packages=<package@version> ... --modroot=<path to go.mod>
1515
* `--go-version`: set the go-version for 'go mod tidy' command, default to the go version in the build environment.
1616
* `--show-diff`: Show the difference between the original and 'go.mod' files.
1717
* `--tidy`: Run 'go mod tidy' command.
18+
* `--skip-initial-tidy`: Skip the initial 'go mod tidy' command before updating and replacing the packages.
1819
* `--bump-file`: Specify the yaml file where to read the bump instructions from
1920

2021
## Example

cmd/gobump/root.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import (
1111
)
1212

1313
type rootCLIFlags struct {
14-
packages string
15-
bumpFile string
16-
modroot string
17-
replaces string
18-
goVersion string
19-
tidy bool
20-
showDiff bool
21-
tidyCompat string
14+
packages string
15+
bumpFile string
16+
modroot string
17+
replaces string
18+
goVersion string
19+
tidy bool
20+
skipInitialTidy bool
21+
showDiff bool
22+
tidyCompat string
2223
}
2324

2425
var rootFlags rootCLIFlags
@@ -88,7 +89,7 @@ var rootCmd = &cobra.Command{
8889
}
8990
}
9091

91-
if _, err := update.DoUpdate(pkgVersions, &types.Config{Modroot: rootFlags.modroot, Tidy: rootFlags.tidy, GoVersion: rootFlags.goVersion, ShowDiff: rootFlags.showDiff, TidyCompat: rootFlags.tidyCompat}); err != nil {
92+
if _, err := update.DoUpdate(pkgVersions, &types.Config{Modroot: rootFlags.modroot, Tidy: rootFlags.tidy, GoVersion: rootFlags.goVersion, ShowDiff: rootFlags.showDiff, TidyCompat: rootFlags.tidyCompat, TidySkipInitial: rootFlags.skipInitialTidy}); err != nil {
9293
return fmt.Errorf("Failed to running update. Error: %v", err)
9394
}
9495
return nil
@@ -110,6 +111,7 @@ func init() {
110111
flagSet.StringVar(&rootFlags.modroot, "modroot", "", "path to the go.mod root")
111112
flagSet.StringVar(&rootFlags.replaces, "replaces", "", "A space-separated list of packages to replace")
112113
flagSet.BoolVar(&rootFlags.tidy, "tidy", false, "Run 'go mod tidy' command")
114+
flagSet.BoolVar(&rootFlags.skipInitialTidy, "skip-initial-tidy", false, "Skip running 'go mod tidy' command before updating the go.mod file")
113115
flagSet.BoolVar(&rootFlags.showDiff, "show-diff", false, "Show the difference between the original and 'go.mod' files")
114116
flagSet.StringVar(&rootFlags.goVersion, "go-version", "", "set the go-version for go-mod-tidy")
115117
flagSet.StringVar(&rootFlags.tidyCompat, "compat", "", "set the go version for which the tidied go.mod and go.sum files should be compatible")

pkg/types/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ type Package struct {
1010
}
1111

1212
type Config struct {
13-
Modroot string
14-
GoVersion string
15-
ShowDiff bool
16-
Tidy bool
17-
TidyCompat string
13+
Modroot string
14+
GoVersion string
15+
ShowDiff bool
16+
Tidy bool
17+
TidyCompat string
18+
TidySkipInitial bool
1819
}
1920

2021
// Used to marshal from yaml/json file to get the list of packages

pkg/update/testdata/confd/go.mod

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
module github.com/iwilltry42/confd
2+
3+
go 1.20
4+
5+
require (
6+
bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898 // indirect
7+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
8+
github.com/BurntSushi/toml v0.3.1
9+
github.com/Microsoft/go-winio v0.5.0 // indirect
10+
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
11+
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
12+
github.com/aws/aws-sdk-go v1.13.41
13+
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
14+
github.com/coreos/bbolt v1.3.2 // indirect
15+
github.com/coreos/etcd v3.3.10+incompatible
16+
github.com/coreos/go-etcd v2.0.0+incompatible // indirect
17+
github.com/coreos/go-semver v0.2.0 // indirect
18+
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
19+
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
20+
github.com/cpuguy83/go-md2man v1.0.10 // indirect
21+
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
22+
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
23+
github.com/docker/go-connections v0.4.0 // indirect
24+
github.com/docker/go-units v0.4.0 // indirect
25+
github.com/dustin/go-humanize v1.0.0 // indirect
26+
github.com/fsnotify/fsnotify v1.4.9
27+
github.com/garyburd/redigo v1.6.0
28+
github.com/go-ini/ini v1.36.0 // indirect
29+
github.com/gogo/protobuf v1.2.1 // indirect
30+
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
31+
github.com/golang/protobuf v1.3.5 // indirect
32+
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 // indirect
33+
github.com/google/btree v1.0.0 // indirect
34+
github.com/gorilla/websocket v1.4.0 // indirect
35+
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 // indirect
36+
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
37+
github.com/grpc-ecosystem/grpc-gateway v1.9.0 // indirect
38+
github.com/hashicorp/consul v1.0.7
39+
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect
40+
github.com/hashicorp/go-cleanhttp v0.0.0-20171218145408-d5fe4b57a186 // indirect
41+
github.com/hashicorp/go-multierror v0.0.0-20171204182908-b7773ae21874 // indirect
42+
github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 // indirect
43+
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 // indirect
44+
github.com/hashicorp/serf v0.8.1 // indirect
45+
github.com/hashicorp/vault v0.10.1
46+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
47+
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 // indirect
48+
github.com/jonboulle/clockwork v0.1.0 // indirect
49+
github.com/kelseyhightower/memkv v0.1.1
50+
github.com/mitchellh/go-homedir v1.1.0 // indirect
51+
github.com/mitchellh/mapstructure v1.1.2 // indirect
52+
github.com/opencontainers/go-digest v1.0.0 // indirect
53+
github.com/opencontainers/image-spec v1.0.1 // indirect
54+
github.com/opencontainers/runc v0.1.1 // indirect
55+
github.com/ory/dockertest v3.3.5+incompatible // indirect
56+
github.com/prometheus/client_golang v0.9.3 // indirect
57+
github.com/ryanuber/go-glob v0.0.0-20160226084822-572520ed46db // indirect
58+
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec
59+
github.com/sethgrid/pester v0.0.0-20180430140037-03e26c9abbbf // indirect
60+
github.com/sirupsen/logrus v1.7.0
61+
github.com/soheilhy/cmux v0.1.4 // indirect
62+
github.com/spf13/cast v1.3.0 // indirect
63+
github.com/spf13/cobra v0.0.3 // indirect
64+
github.com/spf13/pflag v1.0.3 // indirect
65+
github.com/spf13/viper v1.2.1 // indirect
66+
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
67+
github.com/ugorji/go v1.1.1 // indirect
68+
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
69+
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77
70+
go.etcd.io/bbolt v1.3.2 // indirect
71+
go.uber.org/atomic v1.4.0 // indirect
72+
go.uber.org/multierr v1.1.0 // indirect
73+
go.uber.org/zap v1.10.0 // indirect
74+
golang.org/x/net v0.0.0-20190522155817-f3200d17e092
75+
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
76+
golang.org/x/text v0.3.0 // indirect
77+
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
78+
google.golang.org/grpc v1.21.0 // indirect
79+
gopkg.in/yaml.v2 v2.2.2
80+
)
81+
82+
replace (
83+
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.6
84+
gopkg.in/ory-am/dockertest.v3 => github.com/ory/dockertest/v3 v3.7.0
85+
)

0 commit comments

Comments
 (0)