Skip to content

Commit

Permalink
fix dirty repo in drone CI (#140)
Browse files Browse the repository at this point in the history
* improve logic for detecting dirty repo, add verbosity

* clean up drone.yml
  • Loading branch information
rosskirkpat authored Aug 18, 2022
1 parent c799597 commit fcf22f7
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.idea/

# CMake
*.exe~
*.exe
cmake-build-debug/
cmake-build-release/

Expand Down
31 changes: 17 additions & 14 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -106,26 +108,27 @@ 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
- go run bootstrap.go install
- cd C:/Drone/src
- mage ci


- name: publish
image: rancher/drone-images:docker-amd64-ltsc2022
settings:
no_cache: true
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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cmake-build-debug/
cmake-build-release/

# Binaries for programs and plugins
bin/*
bin/
!.gitkeep
*.exe
*.exe~
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -116,15 +116,15 @@ 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
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
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
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
39 changes: 24 additions & 15 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -114,33 +123,33 @@ 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
for _, file := range files {
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
}

Expand Down
8 changes: 5 additions & 3 deletions magetools/gotool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit fcf22f7

Please sign in to comment.