Skip to content

Commit

Permalink
fix: migrate tool into build-tools
Browse files Browse the repository at this point in the history
add add cmd and associated flag for running.
- `path` exists to supply a custom path

Signed-off-by: mikeee <hey@mike.ee>
  • Loading branch information
mikeee committed Oct 22, 2023
1 parent 17731b9 commit 43a2cdd
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main
package cmd

import (
"fmt"
"log"
"os"
"os/exec"
"regexp"

"github.com/spf13/cobra"
"golang.org/x/mod/semver"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -76,6 +76,22 @@ func compareVersions(path string) string {
return fmt.Sprintf("Linter version is valid (MajorMinor): %s", currentVersion)
}

func main() {
log.Println(compareVersions("../../.github/workflows/dapr.yml"))
func getCmdCheckLint(cmdType string) *cobra.Command {
// Base command
cmd := &cobra.Command{
Use: cmdType,
Short: "Compare local golangci-lint version against workflow version",
Run: func(cmd *cobra.Command, args []string) {
path := cmd.Flag("path").Value.String()
fmt.Println(compareVersions(path))
},
}
cmd.PersistentFlags().String("path", "../.github/workflows/dapr.yml", "Path to workflow file")
return cmd
}

func init() {
// checkLintCmd represents the checkLint command
checkLintCmd := getCmdCheckLint("check-linter")
rootCmd.AddCommand(checkLintCmd)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cmd

import (
"testing"
Expand All @@ -8,19 +8,19 @@ import (

func TestParseWorkflow(t *testing.T) {
t.Run("parse invalid workflow file", func(t *testing.T) {
parsedVersion, err := parseWorkflowVersionFromFile("../../.github/workflows/invalid.yaml")
parsedVersion, err := parseWorkflowVersionFromFile("../testdata/check-lint-version/invalid.yml")
assert.Equal(t, "", parsedVersion)
assert.Error(t, err)
})

t.Run("parse workflow file with a missing key", func(t *testing.T) {
parsedVersion, err := parseWorkflowVersionFromFile("./testing/invalid-test.yml")
parsedVersion, err := parseWorkflowVersionFromFile("../testdata/check-lint-version/invalid-test.yml")
assert.Equal(t, "", parsedVersion)
assert.NoError(t, err)
})

t.Run("parse an invalid workflow file", func(t *testing.T) {
parsedVersion, err := parseWorkflowVersionFromFile("./testing/invalid-yaml.yml")
parsedVersion, err := parseWorkflowVersionFromFile("../testdata/check-lint-version/invalid-yaml.yml")
assert.Equal(t, "", parsedVersion)
assert.Error(t, err)
})
Expand Down Expand Up @@ -75,14 +75,14 @@ func TestCompareVersions(t *testing.T) {
})

t.Run("Invalid comparison", func(t *testing.T) {
res := compareVersions("./testing/invalid-test.yml")
res := compareVersions("../testdata/check-lint-version/invalid-test.yml")
assert.Contains(t, res, "Invalid version")
})

// TODO: test function for failure to get the current version using getCurrentVersion()

t.Run("Invalid path for comparison", func(t *testing.T) {
res := compareVersions("./testing/invalid-test-incorrect-path.yml")
res := compareVersions("../testdata/check-lint-version/invalid-test-incorrect-path.yml")
assert.Contains(t, res, "Error parsing workflow")
})
}
6 changes: 6 additions & 0 deletions .build-tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ require (
github.com/google/go-containerregistry v0.11.1-0.20220802162123-c1f9836a4fa9
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.7.0
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/containerd/stargz-snapshotter/estargz v0.12.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v20.10.17+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.17+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.15.8 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20220729202839-6ad7100eb087 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vbatts/tar-split v0.11.2 // indirect
Expand Down
11 changes: 11 additions & 0 deletions .build-tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ github.com/containerd/stargz-snapshotter/estargz v0.12.0 h1:idtwRTLjk2erqiYhPWy2
github.com/containerd/stargz-snapshotter/estargz v0.12.0/go.mod h1:AIQ59TewBFJ4GOPEQXujcrJ/EKxh5xXZegW1rkR1P/M=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/danieljoos/wincred v1.1.0/go.mod h1:XYlo+eRTsVA9aHGp7NGjFkPla4m+DCL7hqDjlFjiygg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -23,16 +24,23 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf
github.com/klauspost/compress v1.15.7/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/compress v1.15.8 h1:JahtItbkWjf2jzm/T+qgMxkP9EMHsqEUA6vCMGmXvhA=
github.com/klauspost/compress v1.15.8/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.3-0.20220729202839-6ad7100eb087 h1:vm7/Jb0eH7oibgUngG/ljkvHBxF+mHlekCvVFyLGOc8=
github.com/opencontainers/image-spec v1.0.3-0.20220729202839-6ad7100eb087/go.mod h1:K/JAU0m27RFhDRX4PcFdIKntROP6y5Ed6O91aZYDQfs=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand All @@ -59,6 +67,8 @@ github.com/vbatts/tar-split v0.11.2/go.mod h1:vV3ZuO2yWSVsz+pfFzDG/upWH1JhjOiEaW
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
Expand All @@ -68,6 +78,7 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ on:
jobs:
build:
env:
NOGOLANGCILINT_VER: "123.123.123"
NOGOLANGCILINT_VER: "123.123.123"
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ dapr.yaml: check-docker-env
--include-crds=true --set global.ha.enabled=$(HA_MODE) --set dapr_config.dapr_config_chart_included=false --set-string global.tag=$(DAPR_TAG) --set-string global.registry=$(DAPR_REGISTRY) $(HELM_CHART_DIR) > $(HELM_MANIFEST_FILE)

################################################################################
# Target: upload-helmchart
# Target: upload-helmchart #
################################################################################

# Upload helm charts to Helm Registry
Expand Down Expand Up @@ -362,7 +362,7 @@ test-race:
go test -tags="allcomponents unit" -race

################################################################################
# Target: test-integration #
# Target: test-integration #
################################################################################
.PHONY: test-integration
test-integration: test-deps
Expand All @@ -388,9 +388,9 @@ lint: check-linter
.SILENT: check-linter # Silence output other than the application run
.PHONY: check-linter
check-linter:
cd ./tools/check-lint-version && \
cd ./.build-tools && \
go mod tidy && \
go run main.go
go run . check-linter

################################################################################
# Target: modtidy-all #
Expand Down Expand Up @@ -420,22 +420,22 @@ modtidy-all: $(TIDY_MODFILES)
modtidy:
go mod tidy

################################################################################
# Target: format #
################################################################################f
# Target: format #
################################################################################
.PHONY: format
format: modtidy-all
gofumpt -l -w . && goimports -local github.com/dapr/ -w $(shell find ./pkg -type f -name '*.go' -not -path "./pkg/proto/*")

################################################################################
# Target: check #
# Target: check #
################################################################################
.PHONY: check
check: format test lint
git status && [[ -z `git status -s` ]]

################################################################################
# Target: init-proto #
# Target: init-proto #
################################################################################
.PHONY: init-proto
init-proto:
Expand Down Expand Up @@ -480,7 +480,7 @@ check-diff:
git diff --exit-code ./go.sum # check no changes

################################################################################
# Target: check-proto-version #
# Target: check-proto-version #
################################################################################
.PHONY: check-proto-version
check-proto-version: ## Checking the version of proto related tools
Expand All @@ -494,7 +494,7 @@ check-proto-version: ## Checking the version of proto related tools
|| { echo "please use protoc-gen-go $(PROTOC_GEN_GO_VERSION) to generate proto, see https://github.com/dapr/dapr/blob/master/dapr/README.md#proto-client-generation"; exit 1; }

################################################################################
# Target: check-proto-diff #
# Target: check-proto-diff #
################################################################################
.PHONY: check-proto-diff
check-proto-diff:
Expand All @@ -510,7 +510,7 @@ check-proto-diff:


################################################################################
# Target: compile-build-tools #
# Target: compile-build-tools #
################################################################################
compile-build-tools:
ifeq (,$(wildcard $(BUILD_TOOLS)))
Expand Down
22 changes: 0 additions & 22 deletions tools/check-lint-version/Makefile

This file was deleted.

12 changes: 0 additions & 12 deletions tools/check-lint-version/Readme.md

This file was deleted.

16 changes: 0 additions & 16 deletions tools/check-lint-version/go.mod

This file was deleted.

24 changes: 0 additions & 24 deletions tools/check-lint-version/go.sum

This file was deleted.

0 comments on commit 43a2cdd

Please sign in to comment.