diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ecef812a..d77ddd2b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: - name: Run Tests run: |- task workspace - task testcov + task test - name: Upload Coverage uses: codecov/codecov-action@v3 with: diff --git a/Taskfile.yml b/Taskfile.yml index bedd20fe..23103a5c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -10,7 +10,7 @@ tasks: desc: Formatting and linting dir: "{{.SRC_DIR}}" cmds: - - gofmt -d . + - gofumpt -d . - go vet ./... - golangci-lint run @@ -18,23 +18,29 @@ tasks: desc: Fix formatting and linting dir: "{{.SRC_DIR}}" cmds: - - gofmt -w . + - gofumpt -w . - go mod tidy - golangci-lint run --fix + setup: + desc: Setup linter, formatter, etc. for local testing and CI + cmds: + - cmd: echo "Installing development tools..." + silent: true + - task: install-changie + - task: install-gofumpt + - task: install-golangci-lint + - cmd: echo "Development tools installed!" + silent: true + - task: workspace + test: desc: Run tests dir: "{{.SRC_DIR}}" cmds: - - go test -v ./... {{ .CLI_ARGS }} + - go test -race -coverprofile=coverage.txt -covermode=atomic -v ./... {{ .CLI_ARGS }} silent: true - testcov: - desc: Run tests with code coverage output - dir: "{{.SRC_DIR}}" - cmds: - - go test -race -coverprofile=coverage.txt -covermode=atomic -v ./... - update-opslevel-go: desc: Update opslevel-go version to latest release dir: "{{.SRC_DIR}}" @@ -46,7 +52,48 @@ tasks: desc: Setup workspace for cli & opslevel-go development dir: "{{.SRC_DIR}}" cmds: + - cmd: echo "Setting up opslevel-go workspace..." + silent: true - git submodule update --init - go work init || exit 0 - go work use . submodules/opslevel-go - - echo "Workspace ready!" + - cmd: echo "opslevel-go workspace ready!" + silent: true + + # internal (not directly called) tasks + + go-install-tool: + desc: go install '{{.GO_TOOL}}' and set GOBIN if not set + internal: true + silent: true + vars: + IS_TOOL_INSTALLED: + sh: which {{.GO_TOOL}} > /dev/null || echo "1" + cmds: + - test -z "{{.IS_TOOL_INSTALLED}}" || echo "Installing {{.GO_TOOL}}..." + - test -z "{{.IS_TOOL_INSTALLED}}" || go install {{.GO_TOOL_PATH}} + - test -n $(go env GOBIN) || go env -w GOBIN=$(go env GOPATH)/bin + - echo " '{{.GO_TOOL}}' is installed." + requires: + vars: [GO_TOOL, GO_TOOL_PATH] + + install-changie: + desc: go install "changie" + internal: true + cmds: + - task: go-install-tool + vars: { GO_TOOL: "changie", GO_TOOL_PATH: "github.com/miniscruff/changie@latest" } + + install-gofumpt: + desc: go install "gofumpt" + internal: true + cmds: + - task: go-install-tool + vars: { GO_TOOL: "gofumpt", GO_TOOL_PATH: "mvdan.cc/gofumpt@latest" } + + install-golangci-lint: + desc: go install "golangci-lint" + internal: true + cmds: + - task: go-install-tool + vars: { GO_TOOL: "golangci-lint", GO_TOOL_PATH: "github.com/golangci/golangci-lint/cmd/golangci-lint@latest" } diff --git a/src/cmd/account.go b/src/cmd/account.go index 2d73374e..becc8df6 100644 --- a/src/cmd/account.go +++ b/src/cmd/account.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "fmt" + "github.com/opslevel/opslevel-go/v2023" "github.com/opslevel/cli/common" diff --git a/src/cmd/alias.go b/src/cmd/alias.go index bff1b273..4dbbd1f1 100644 --- a/src/cmd/alias.go +++ b/src/cmd/alias.go @@ -2,11 +2,12 @@ package cmd import ( "fmt" + "os" + "strings" + "github.com/opslevel/opslevel-go/v2023" "github.com/rs/zerolog/log" "github.com/spf13/cobra" - "os" - "strings" ) var createAliasCommand = &cobra.Command{ diff --git a/src/cmd/import.go b/src/cmd/import.go index 6bc40560..cb70cc82 100644 --- a/src/cmd/import.go +++ b/src/cmd/import.go @@ -2,6 +2,7 @@ package cmd import ( "errors" + "github.com/opslevel/cli/common" "github.com/spf13/cobra" ) diff --git a/src/cmd/infra.go b/src/cmd/infra.go index 01a78534..0dbeee72 100644 --- a/src/cmd/infra.go +++ b/src/cmd/infra.go @@ -4,15 +4,16 @@ import ( "encoding/csv" "encoding/json" "fmt" + "io" + "os" + "strings" + "github.com/creasty/defaults" "github.com/opslevel/cli/common" "github.com/opslevel/opslevel-go/v2023" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "gopkg.in/yaml.v3" - "io" - "os" - "strings" ) var createInfraCmd = &cobra.Command{ diff --git a/src/cmd/integration.go b/src/cmd/integration.go index 6f9eb728..992440d3 100644 --- a/src/cmd/integration.go +++ b/src/cmd/integration.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "fmt" + "github.com/opslevel/opslevel-go/v2023" "github.com/opslevel/cli/common" diff --git a/src/cmd/maturity.go b/src/cmd/maturity.go index ad61bb79..29937f85 100644 --- a/src/cmd/maturity.go +++ b/src/cmd/maturity.go @@ -4,12 +4,13 @@ import ( "encoding/csv" "encoding/json" "fmt" - "github.com/opslevel/cli/common" - "github.com/opslevel/opslevel-go/v2023" - "github.com/spf13/cobra" "os" "sort" "strings" + + "github.com/opslevel/cli/common" + "github.com/opslevel/opslevel-go/v2023" + "github.com/spf13/cobra" ) var listServiceMaturityCmd = &cobra.Command{ diff --git a/src/cmd/repository.go b/src/cmd/repository.go index 65b39be1..2995f64a 100644 --- a/src/cmd/repository.go +++ b/src/cmd/repository.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "fmt" + "github.com/opslevel/opslevel-go/v2023" "github.com/opslevel/cli/common" diff --git a/src/cmd/rubric.go b/src/cmd/rubric.go index 551c3549..3e92c706 100644 --- a/src/cmd/rubric.go +++ b/src/cmd/rubric.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "fmt" + "github.com/opslevel/opslevel-go/v2023" "github.com/opslevel/cli/common" diff --git a/src/cmd/terraform.go b/src/cmd/terraform.go index 9ce3dd88..2df936c5 100644 --- a/src/cmd/terraform.go +++ b/src/cmd/terraform.go @@ -40,7 +40,7 @@ func newFile(filename string, makeExecutable bool) *os.File { panic(err) } if makeExecutable { - if err := os.Chmod(filename, 0755); err != nil { + if err := os.Chmod(filename, 0o755); err != nil { panic(err) } } diff --git a/src/common/client.go b/src/common/client.go index e58ef8f9..e624e37a 100644 --- a/src/common/client.go +++ b/src/common/client.go @@ -2,10 +2,11 @@ package common import ( "fmt" + "time" + "github.com/opslevel/opslevel-go/v2023" "github.com/spf13/cobra" "github.com/spf13/viper" - "time" ) func NewGraphClient(version string, options ...opslevel.Option) *opslevel.Client { diff --git a/src/common/prompts.go b/src/common/prompts.go index a335e01b..12c3bedb 100644 --- a/src/common/prompts.go +++ b/src/common/prompts.go @@ -2,9 +2,10 @@ package common import ( "fmt" - "github.com/opslevel/opslevel-go/v2023" "sort" + "github.com/opslevel/opslevel-go/v2023" + "github.com/manifoldco/promptui" ) diff --git a/src/go.mod b/src/go.mod index aeaeba9c..03d18888 100644 --- a/src/go.mod +++ b/src/go.mod @@ -82,12 +82,12 @@ require ( go.opentelemetry.io/otel v1.14.0 // indirect go.opentelemetry.io/otel/sdk v1.14.0 // indirect go.opentelemetry.io/otel/trace v1.14.0 // indirect - golang.org/x/crypto v0.12.0 // indirect - golang.org/x/mod v0.8.0 // indirect - golang.org/x/net v0.14.0 // indirect - golang.org/x/sys v0.11.0 // indirect - golang.org/x/text v0.12.0 // indirect - golang.org/x/tools v0.6.0 // indirect + golang.org/x/crypto v0.13.0 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.15.0 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/text v0.13.0 // indirect + golang.org/x/tools v0.13.0 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect diff --git a/src/go.sum b/src/go.sum index c1ef280a..c98f8ace 100644 --- a/src/go.sum +++ b/src/go.sum @@ -465,8 +465,8 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -501,8 +501,9 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -540,8 +541,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= -golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -563,8 +564,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/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= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -615,15 +616,15 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= -golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= +golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -635,8 +636,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -688,8 +689,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=