From fcf22f706df475908a31416b98b6436460780bef Mon Sep 17 00:00:00 2001 From: Ross Kirkpatrick Date: Wed, 17 Aug 2022 21:09:26 -0400 Subject: [PATCH] fix dirty repo in drone CI (#140) * improve logic for detecting dirty repo, add verbosity * clean up drone.yml --- .dockerignore | 2 ++ .drone.yml | 31 +++++++++++++++++-------------- .gitignore | 2 +- go.mod | 6 +++--- go.sum | 11 ++++++----- magefiles/magefile.go | 39 ++++++++++++++++++++++++--------------- magetools/gotool.go | 8 +++++--- 7 files changed, 58 insertions(+), 41 deletions(-) diff --git a/.dockerignore b/.dockerignore index c67f7369..2b859628 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,8 @@ .idea/ # CMake +*.exe~ +*.exe cmake-build-debug/ cmake-build-release/ diff --git a/.drone.yml b/.drone.yml index 2d531527..43e14800 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,16 +13,18 @@ steps: image: golang:1.18-windowsservercore environment: MAGEFILE_CACHE: C:/Drone/.magefile + MAGEFILE_VERBOSE: 1 + MAGEFILE_DEBUG: false commands: - - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.0 - - go install github.com/onsi/ginkgo/ginkgo@latest - - go get -u github.com/onsi/gomega/... - - cd .. - - git clone https://github.com/magefile/mage.git - - cd mage - - go run bootstrap.go install - - cd C:/Drone/src - - mage ci + - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.0 + - go install github.com/onsi/ginkgo/ginkgo@latest + - go get github.com/onsi/gomega/... + - cd .. + - git clone https://github.com/magefile/mage.git + - cd mage + - go run bootstrap.go install + - cd C:/Drone/src + - mage ci - name: publish image: plugins/docker @@ -31,7 +33,7 @@ steps: build_args: - SERVERCORE_VERSION=1809 - ARCH=amd64 - - MAINTAINERS=ross.kirkpatrick@suse.com jamie.phillips@suse.com + - MAINTAINERS=rosskirkpat@outlook.com cphill11@gmail.com luther.monson@gmail.com - REPO=https://github.com/rancher/wins custom_dns: 1.1.1.1 dockerfile: Dockerfile @@ -106,10 +108,12 @@ steps: image: golang:1.18-windowsservercore environment: MAGEFILE_CACHE: C:/Drone/.magefile + MAGEFILE_VERBOSE: 1 + MAGEFILE_DEBUG: false commands: - - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.0 + - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.0 - go install github.com/onsi/ginkgo/ginkgo@latest - - go get -u github.com/onsi/gomega/... + - go get github.com/onsi/gomega/... - cd .. - git clone https://github.com/magefile/mage.git - cd mage @@ -117,7 +121,6 @@ steps: - cd C:/Drone/src - mage ci - - name: publish image: rancher/drone-images:docker-amd64-ltsc2022 settings: @@ -125,7 +128,7 @@ steps: build_args: - SERVERCORE_VERSION=ltsc2022 - ARCH=amd64 - - MAINTAINERS=ross.kirkpatrick@suse.com jamie.phillips@suse.com + - MAINTAINERS=rosskirkpat@outlook.com cphill11@gmail.com luther.monson@gmail.com - REPO=https://github.com/rancher/wins custom_dns: 1.1.1.1 dockerfile: Dockerfile diff --git a/.gitignore b/.gitignore index a0a0af68..9f806fbf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ cmake-build-debug/ cmake-build-release/ # Binaries for programs and plugins -bin/* +bin/ !.gitkeep *.exe *.exe~ diff --git a/go.mod b/go.mod index 56144e77..f183fb16 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( github.com/sirupsen/logrus v1.8.1 github.com/urfave/cli/v2 v2.3.0 golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f - golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b + golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 google.golang.org/grpc v1.45.0 inet.af/tcpproxy v0.0.0-20200125044825-b6bb9b5b8252 @@ -116,7 +116,7 @@ require ( github.com/urfave/cli v1.22.9 // indirect github.com/vbatts/tar-split v0.11.2 // indirect go.opencensus.io v0.23.0 // indirect - golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect + golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect golang.org/x/oauth2 v0.0.0-20220628200809-02e64fa58f26 // indirect golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect golang.org/x/text v0.3.7 // indirect @@ -124,7 +124,7 @@ require ( golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20220421151946-72621c1f0bd3 // indirect - google.golang.org/protobuf v1.28.0 // indirect + google.golang.org/protobuf v1.28.1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 0127e277..b6ee8b00 100644 --- a/go.sum +++ b/go.sum @@ -1147,8 +1147,8 @@ golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= +golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401 h1:zwrSfklXn0gxyLRX/aR+q6cgHbV/ItVyzbPlbA+dkAw= golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4= @@ -1254,8 +1254,8 @@ golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b h1:2n253B2r0pYSmEV+UNCQoPfU/FiaizQEK5Gu4Bq4JE8= -golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1554,8 +1554,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/magefiles/magefile.go b/magefiles/magefile.go index 7e04eb35..68e8a082 100644 --- a/magefiles/magefile.go +++ b/magefiles/magefile.go @@ -54,13 +54,23 @@ func Version() error { return nil } - version = commit + "-dirty" + version = commit + if !isClean { + version = commit + "-dirty" + log.Printf("[Version] dirty version encountered: %s \n", version) + } + // check if this is a release version and fail if the version contains `dirty` + if strings.Contains(version, "dirty") && os.Getenv("DRONE_TAG") != "" || tag != "" { + return fmt.Errorf("[Version] releases require a non-dirty tag: %s", version) + } + log.Printf("[Version] version: %s \n", version) + return nil } func Setup() { mg.Deps(Version) - g = magetools.NewGo("amd64", "windows", version, commit, "0") + g = magetools.NewGo("amd64", "windows", version, commit, "0", "1") } func Dependencies() error { @@ -69,14 +79,14 @@ func Dependencies() error { } func Validate() error { - envs := map[string]string{"GOOS": "windows", "ARCH": "amd64", "CGO_ENABLED": "0"} + envs := map[string]string{"GOOS": "windows", "ARCH": "amd64", "CGO_ENABLED": "0", "MAGEFILE_VERBOSE": "1"} - log.Printf("[build] Running: golangci-lint \n") + log.Printf("[Validate] Running: golangci-lint \n") if err := sh.RunWithV(envs, "golangci-lint", "run"); err != nil { return err } - log.Printf("[build] Running: go fmt \n") + log.Printf("[Validate] Running: go fmt \n") if err := sh.RunWithV(envs, "go", "fmt", "./..."); err != nil { return err } @@ -87,17 +97,16 @@ func Validate() error { func Build() error { mg.Deps(Clean, Dependencies, Validate) - winsOutput := filepath.Join("bin", "wins.exe") - log.Printf("[build] Building wins version %s \n", version) - log.Printf("[build] Output: %s \n", winsOutput) + log.Printf("[Build] Building wins version: %s \n", version) + log.Printf("[Build] Output: %s \n", winsOutput) if err := g.Build(flags, "cmd/main.go", winsOutput); err != nil { return err } - log.Printf("[build] successfully built wins version version %s \n", version) + log.Printf("[Build] successfully built wins version %s \n", version) - log.Printf("[build] now staging build artifacts \n") + log.Printf("[Build] now staging build artifacts \n") if err := os.MkdirAll(artifactOutput, os.ModePerm); err != nil { return err } @@ -114,14 +123,14 @@ func Build() error { return err } - log.Printf("[build] all required build artifacts have been staged \n") + log.Printf("[Build] all required build artifacts have been staged \n") files, err := os.ReadDir(artifactOutput) if err != nil { return err } if len(files) != 3 { - return errors.New("[package] a required build artifact is missing, exiting now \n") + return errors.New("[Build] a required build artifact is missing, exiting now \n") } var artifacts strings.Builder @@ -129,18 +138,18 @@ func Build() error { artifacts.WriteString(file.Name() + " ,") } - log.Printf("[build] artifacts copied: %s \n", artifacts.String()) + log.Printf("[Build] artifacts copied: %s \n", artifacts.String()) return nil } func Test() error { mg.Deps(Build) - log.Printf("[build] Testing wins version %s \n", version) + log.Printf("[Test] Testing wins version %s \n", version) if err := g.Test(flags, "./..."); err != nil { return err } - log.Printf("[build] successfully tested wins version version %s \n", version) + log.Printf("[Test] successfully tested wins version version %s \n", version) return nil } diff --git a/magetools/gotool.go b/magetools/gotool.go index d4e1b781..07d66c4c 100644 --- a/magetools/gotool.go +++ b/magetools/gotool.go @@ -10,25 +10,27 @@ type Go struct { Version string Commit string CGoEnabled string + Verbose string } -func NewGo(arch, goos, version, commit, cgoEnabled string) *Go { +func NewGo(arch, goos, version, commit, cgoEnabled, verbose string) *Go { return &Go{ Arch: arch, OS: goos, Version: version, Commit: commit, CGoEnabled: cgoEnabled, + Verbose: verbose, } } func (g *Go) Build(flags func(string, string) string, target, output string) error { - envs := map[string]string{"GOOS": g.OS, "ARCH": g.Arch, "CGO_ENABLED": g.CGoEnabled} + envs := map[string]string{"GOOS": g.OS, "ARCH": g.Arch, "CGO_ENABLED": g.CGoEnabled, "MAGEFILE_VERBOSE": g.Verbose} return sh.RunWithV(envs, "go", "build", "-o", output, "--ldflags="+flags(g.Version, g.Commit), target) } func (g *Go) Test(flags func(string, string) string, target string) error { - envs := map[string]string{"GOOS": g.OS, "ARCH": g.Arch, "CGO_ENABLED": g.CGoEnabled} + envs := map[string]string{"GOOS": g.OS, "ARCH": g.Arch, "CGO_ENABLED": g.CGoEnabled, "MAGEFILE_VERBOSE": g.Verbose} return sh.RunWithV(envs, "go", "test", "-v", "-cover", "--ldflags="+flags(g.Version, g.Commit), target) }