diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 8ed56350..1c0d03da 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -23,4 +23,4 @@ jobs: with: go-version: '^1.14' - name: integration tests - run: ./ci/steps/integration.sh + run: ./ci/scripts/integration.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fd942730..81d4dcdd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -15,7 +15,8 @@ jobs: - name: fmt uses: ./ci/image with: - args: ./ci/steps/fmt.sh + args: make -j fmt + - run: ./ci/scripts/files_changed.sh lint: runs-on: ubuntu-latest steps: @@ -38,7 +39,7 @@ jobs: - name: test uses: ./ci/image with: - args: ./ci/steps/unit_test.sh + args: make -j test/go gendocs: runs-on: ubuntu-latest steps: @@ -52,4 +53,5 @@ jobs: - name: generate-docs uses: ./ci/image with: - args: ./ci/steps/gendocs.sh + args: make -j gendocs + - run: ./ci/scripts/files_changed.sh diff --git a/Makefile b/Makefile index 102d5c95..a926a30f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ # Makefile for Coder CLI -.PHONY: clean build build/macos build/windows build/linux +.PHONY: clean build build/macos build/windows build/linux fmt lint gendocs test/go + +PROJECT_ROOT := $(shell git rev-parse --show-toplevel) +MAKE_ROOT := $(shell pwd) clean: rm -rf ./ci/bin @@ -9,8 +12,24 @@ build: build/macos build/windows build/linux build/macos: # requires darwin - CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 ./ci/steps/build.sh + CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 ./ci/scripts/build.sh build/windows: - CGO_ENABLED=0 GOOS=windows GOARCH=386 ./ci/steps/build.sh + CGO_ENABLED=0 GOOS=windows GOARCH=386 ./ci/scripts/build.sh build/linux: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./ci/steps/build.sh + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./ci/scripts/build.sh + +fmt: + go mod tidy + gofmt -w -s . + goimports -w "-local=$$(go list -m)" . + +lint: + golangci-lint run -c .golangci.yml + +gendocs: + rm -rf ./docs + mkdir ./docs + go run ./cmd/coder gen-docs ./docs + +test/go: + go test $$(go list ./... | grep -v pkg/tcli | grep -v ci/integration | grep -v coder-sdk) diff --git a/ci/integration/envs_test.go b/ci/integration/envs_test.go index 8401e872..65101667 100644 --- a/ci/integration/envs_test.go +++ b/ci/integration/envs_test.go @@ -10,12 +10,13 @@ import ( "testing" "time" - "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/pkg/tcli" "cdr.dev/slog" "cdr.dev/slog/sloggers/slogtest" "cdr.dev/slog/sloggers/slogtest/assert" "github.com/google/go-cmp/cmp" + + "cdr.dev/coder-cli/coder-sdk" + "cdr.dev/coder-cli/pkg/tcli" ) func cleanupClient(ctx context.Context, t *testing.T) *coder.Client { diff --git a/ci/integration/integration_test.go b/ci/integration/integration_test.go index a7e3a560..940bcbf1 100644 --- a/ci/integration/integration_test.go +++ b/ci/integration/integration_test.go @@ -6,8 +6,9 @@ import ( "testing" "time" - "cdr.dev/coder-cli/pkg/tcli" "cdr.dev/slog/sloggers/slogtest/assert" + + "cdr.dev/coder-cli/pkg/tcli" ) func run(t *testing.T, container string, execute func(t *testing.T, ctx context.Context, runner *tcli.ContainerRunner)) { diff --git a/ci/integration/setup_test.go b/ci/integration/setup_test.go index 754eda14..45cb7f04 100644 --- a/ci/integration/setup_test.go +++ b/ci/integration/setup_test.go @@ -9,8 +9,9 @@ import ( "strings" "testing" - "cdr.dev/coder-cli/pkg/tcli" "golang.org/x/xerrors" + + "cdr.dev/coder-cli/pkg/tcli" ) // binpath is populated during package initialization with a path to the coder binary. diff --git a/ci/integration/tags_test.go b/ci/integration/tags_test.go index 2fb7dfe0..fdeabbb4 100644 --- a/ci/integration/tags_test.go +++ b/ci/integration/tags_test.go @@ -4,9 +4,10 @@ import ( "context" "testing" + "cdr.dev/slog/sloggers/slogtest/assert" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/pkg/tcli" - "cdr.dev/slog/sloggers/slogtest/assert" ) func TestTags(t *testing.T) { diff --git a/ci/integration/users_test.go b/ci/integration/users_test.go index 1272337f..e1c20ec9 100644 --- a/ci/integration/users_test.go +++ b/ci/integration/users_test.go @@ -4,9 +4,10 @@ import ( "context" "testing" + "cdr.dev/slog/sloggers/slogtest/assert" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/pkg/tcli" - "cdr.dev/slog/sloggers/slogtest/assert" ) func TestUsers(t *testing.T) { diff --git a/ci/steps/build.sh b/ci/scripts/build.sh similarity index 95% rename from ci/steps/build.sh rename to ci/scripts/build.sh index 29356df3..d19f1bf6 100755 --- a/ci/steps/build.sh +++ b/ci/scripts/build.sh @@ -6,7 +6,7 @@ popd() { builtin popd >/dev/null; } set -euo pipefail -cd "$(git rev-parse --show-toplevel)/ci/steps" +cd "$(git rev-parse --show-toplevel)/ci/scripts" tag=$(git describe --tags) diff --git a/ci/scripts/files_changed.sh b/ci/scripts/files_changed.sh new file mode 100755 index 00000000..759c68d3 --- /dev/null +++ b/ci/scripts/files_changed.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(git rev-parse --show-toplevel)" + +if [[ $(git ls-files --other --modified --exclude-standard) ]]; then + echo "Files have changed:" + git -c color.ui=never status + exit 1 +fi diff --git a/ci/steps/integration.sh b/ci/scripts/integration.sh similarity index 100% rename from ci/steps/integration.sh rename to ci/scripts/integration.sh diff --git a/ci/steps/fmt.sh b/ci/steps/fmt.sh deleted file mode 100755 index 6c3f7a88..00000000 --- a/ci/steps/fmt.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -cd "$(git rev-parse --show-toplevel)" - -echo "--- formatting" -go mod tidy -gofmt -w -s . -goimports -w "-local=$$(go list -m)" . - -if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then - echo "Files need generation or are formatted incorrectly:" - git -c color.ui=always status | grep --color=no '\e\[31m' - echo "Please run the following locally:" - echo " ./ci/steps/fmt.sh" - exit 1 - fi diff --git a/ci/steps/gendocs.sh b/ci/steps/gendocs.sh deleted file mode 100755 index d4cb8413..00000000 --- a/ci/steps/gendocs.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -cd "$(git rev-parse --show-toplevel)" - -echo "--- regenerating documentation" -rm -rf ./docs -mkdir ./docs -go run ./cmd/coder gen-docs ./docs - -if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then - echo "Documentation needs generation:" - git -c color.ui=always status | grep --color=no '\e\[31m' - echo "Please run the following locally:" - echo " ./ci/steps/gendocs.sh" - exit 1 -fi diff --git a/ci/steps/lint.sh b/ci/steps/lint.sh deleted file mode 100755 index 5a766fb5..00000000 --- a/ci/steps/lint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -cd "$(git rev-parse --show-toplevel)" - -echo "--- golangci-lint" -golangci-lint run -c .golangci.yml diff --git a/ci/steps/unit_test.sh b/ci/steps/unit_test.sh deleted file mode 100755 index 1692a10a..00000000 --- a/ci/steps/unit_test.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -cd "$(git rev-parse --show-toplevel)" - -echo "--- running unit tests" -go test $(go list ./... | grep -v pkg/tcli | grep -v ci/integration | grep -v coder-sdk) diff --git a/coder-sdk/config_test.go b/coder-sdk/config_test.go index 8a470958..511f339f 100644 --- a/coder-sdk/config_test.go +++ b/coder-sdk/config_test.go @@ -7,10 +7,11 @@ import ( "testing" "time" - "cdr.dev/coder-cli/coder-sdk" "cdr.dev/slog" "cdr.dev/slog/sloggers/slogtest" "cdr.dev/slog/sloggers/slogtest/assert" + + "cdr.dev/coder-cli/coder-sdk" ) func newClient(t *testing.T) *coder.Client { diff --git a/internal/cmd/ceapi.go b/internal/cmd/ceapi.go index 04edfcb6..964d1857 100644 --- a/internal/cmd/ceapi.go +++ b/internal/cmd/ceapi.go @@ -5,9 +5,10 @@ import ( "fmt" "strings" + "golang.org/x/xerrors" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/pkg/clog" - "golang.org/x/xerrors" ) // Helpers for working with the Coder Enterprise API. diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 876e6267..c268ff49 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -4,9 +4,10 @@ package cmd import ( "os" - "cdr.dev/coder-cli/internal/x/xcobra" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" + + "cdr.dev/coder-cli/internal/x/xcobra" ) // verbose is a global flag for specifying that a command should give verbose output. diff --git a/internal/cmd/configssh.go b/internal/cmd/configssh.go index 562e5225..3077ae7a 100644 --- a/internal/cmd/configssh.go +++ b/internal/cmd/configssh.go @@ -12,11 +12,12 @@ import ( "cdr.dev/coder-cli/pkg/clog" + "github.com/spf13/cobra" + "golang.org/x/xerrors" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/internal/coderutil" "cdr.dev/coder-cli/internal/config" - "github.com/spf13/cobra" - "golang.org/x/xerrors" ) const sshStartToken = "# ------------START-CODER-ENTERPRISE-----------" diff --git a/internal/cmd/images.go b/internal/cmd/images.go index 8e9679ce..b4ee6158 100644 --- a/internal/cmd/images.go +++ b/internal/cmd/images.go @@ -4,11 +4,12 @@ import ( "encoding/json" "os" + "github.com/spf13/cobra" + "golang.org/x/xerrors" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/pkg/clog" "cdr.dev/coder-cli/pkg/tablewriter" - "github.com/spf13/cobra" - "golang.org/x/xerrors" ) func imgsCmd() *cobra.Command { diff --git a/internal/cmd/login.go b/internal/cmd/login.go index c3aa7a2d..ce3a7d41 100644 --- a/internal/cmd/login.go +++ b/internal/cmd/login.go @@ -8,16 +8,17 @@ import ( "net/url" "strings" + "github.com/pkg/browser" + "github.com/spf13/cobra" + "golang.org/x/sync/errgroup" + "golang.org/x/xerrors" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/internal/config" "cdr.dev/coder-cli/internal/loginsrv" "cdr.dev/coder-cli/internal/version" "cdr.dev/coder-cli/internal/x/xcobra" "cdr.dev/coder-cli/pkg/clog" - "github.com/pkg/browser" - "github.com/spf13/cobra" - "golang.org/x/sync/errgroup" - "golang.org/x/xerrors" ) func loginCmd() *cobra.Command { diff --git a/internal/cmd/logout.go b/internal/cmd/logout.go index 8c1c27a6..fd864aa1 100644 --- a/internal/cmd/logout.go +++ b/internal/cmd/logout.go @@ -3,10 +3,11 @@ package cmd import ( "os" - "cdr.dev/coder-cli/internal/config" - "cdr.dev/coder-cli/pkg/clog" "github.com/spf13/cobra" "golang.org/x/xerrors" + + "cdr.dev/coder-cli/internal/config" + "cdr.dev/coder-cli/pkg/clog" ) func logoutCmd() *cobra.Command { diff --git a/internal/cmd/rebuild.go b/internal/cmd/rebuild.go index 50875467..abdd243c 100644 --- a/internal/cmd/rebuild.go +++ b/internal/cmd/rebuild.go @@ -7,15 +7,16 @@ import ( "strings" "time" - "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/x/xcobra" - "cdr.dev/coder-cli/pkg/clog" "github.com/briandowns/spinner" "github.com/fatih/color" "github.com/manifoldco/promptui" "github.com/spf13/cobra" "golang.org/x/crypto/ssh/terminal" "golang.org/x/xerrors" + + "cdr.dev/coder-cli/coder-sdk" + "cdr.dev/coder-cli/internal/x/xcobra" + "cdr.dev/coder-cli/pkg/clog" ) func rebuildEnvCommand() *cobra.Command { diff --git a/internal/cmd/resourcemanager.go b/internal/cmd/resourcemanager.go index df411e00..775596e1 100644 --- a/internal/cmd/resourcemanager.go +++ b/internal/cmd/resourcemanager.go @@ -7,10 +7,11 @@ import ( "sort" "text/tabwriter" - "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/pkg/clog" "github.com/spf13/cobra" "golang.org/x/xerrors" + + "cdr.dev/coder-cli/coder-sdk" + "cdr.dev/coder-cli/pkg/clog" ) func resourceCmd() *cobra.Command { diff --git a/internal/cmd/shell.go b/internal/cmd/shell.go index 17b0ee27..609bd332 100644 --- a/internal/cmd/shell.go +++ b/internal/cmd/shell.go @@ -15,12 +15,13 @@ import ( "golang.org/x/xerrors" "nhooyr.io/websocket" + "cdr.dev/wsep" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/internal/activity" "cdr.dev/coder-cli/internal/coderutil" "cdr.dev/coder-cli/internal/x/xterminal" "cdr.dev/coder-cli/pkg/clog" - "cdr.dev/wsep" ) func getEnvsForCompletion(user string) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { diff --git a/internal/cmd/sync.go b/internal/cmd/sync.go index 9f6d9a19..c1c09bca 100644 --- a/internal/cmd/sync.go +++ b/internal/cmd/sync.go @@ -8,12 +8,13 @@ import ( "path/filepath" "strings" + "github.com/spf13/cobra" + "golang.org/x/xerrors" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/internal/sync" "cdr.dev/coder-cli/internal/x/xcobra" "cdr.dev/coder-cli/pkg/clog" - "github.com/spf13/cobra" - "golang.org/x/xerrors" ) func syncCmd() *cobra.Command { diff --git a/internal/cmd/tags.go b/internal/cmd/tags.go index 112cfbfa..13163e60 100644 --- a/internal/cmd/tags.go +++ b/internal/cmd/tags.go @@ -4,12 +4,13 @@ import ( "encoding/json" "os" + "github.com/spf13/cobra" + "golang.org/x/xerrors" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/internal/x/xcobra" "cdr.dev/coder-cli/pkg/clog" "cdr.dev/coder-cli/pkg/tablewriter" - "github.com/spf13/cobra" - "golang.org/x/xerrors" ) func tagsCmd() *cobra.Command { diff --git a/internal/cmd/tokens.go b/internal/cmd/tokens.go index ef0bdb32..b5f0c5d7 100644 --- a/internal/cmd/tokens.go +++ b/internal/cmd/tokens.go @@ -3,17 +3,18 @@ package cmd import ( "fmt" + "github.com/spf13/cobra" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/internal/x/xcobra" "cdr.dev/coder-cli/pkg/tablewriter" - "github.com/spf13/cobra" ) func tokensCmd() *cobra.Command { cmd := &cobra.Command{ Use: "tokens", - Short: "manage Coder API tokens for the active user", Hidden: true, + Short: "manage Coder API tokens for the active user", Long: "Create and manage API Tokens for authenticating the CLI.\n" + "Statically authenticate using the token value with the " + "`" + "CODER_TOKEN" + "`" + " and " + "`" + "CODER_URL" + "`" + " environment variables.", } diff --git a/internal/cmd/users.go b/internal/cmd/users.go index fc5533dd..a9d6725f 100644 --- a/internal/cmd/users.go +++ b/internal/cmd/users.go @@ -4,9 +4,10 @@ import ( "encoding/json" "os" - "cdr.dev/coder-cli/pkg/tablewriter" "github.com/spf13/cobra" "golang.org/x/xerrors" + + "cdr.dev/coder-cli/pkg/tablewriter" ) func usersCmd() *cobra.Command { diff --git a/internal/coderutil/env.go b/internal/coderutil/env.go index beefc3bc..c961fa56 100644 --- a/internal/coderutil/env.go +++ b/internal/coderutil/env.go @@ -4,9 +4,10 @@ import ( "context" "net/url" - "cdr.dev/coder-cli/coder-sdk" "golang.org/x/xerrors" "nhooyr.io/websocket" + + "cdr.dev/coder-cli/coder-sdk" ) // DialEnvWsep dials the executor endpoint using the https://github.com/cdr/wsep message protocol. diff --git a/internal/loginsrv/input_test.go b/internal/loginsrv/input_test.go index 714ec86c..ee507318 100644 --- a/internal/loginsrv/input_test.go +++ b/internal/loginsrv/input_test.go @@ -8,8 +8,9 @@ import ( "testing" "time" - "cdr.dev/coder-cli/internal/loginsrv" "github.com/stretchr/testify/require" + + "cdr.dev/coder-cli/internal/loginsrv" ) // 100ms is plenty of time as we are dealing with simple in-memory pipe. diff --git a/internal/loginsrv/server_test.go b/internal/loginsrv/server_test.go index 694c68b6..7f3413fc 100644 --- a/internal/loginsrv/server_test.go +++ b/internal/loginsrv/server_test.go @@ -9,8 +9,9 @@ import ( "testing" "time" - "cdr.dev/coder-cli/internal/loginsrv" "github.com/stretchr/testify/require" + + "cdr.dev/coder-cli/internal/loginsrv" ) // 500ms should be plenty enough, even on slow machine to perform the request/response cycle. diff --git a/internal/sync/singlefile.go b/internal/sync/singlefile.go index 31745f93..5cb91f7f 100644 --- a/internal/sync/singlefile.go +++ b/internal/sync/singlefile.go @@ -9,11 +9,12 @@ import ( "path/filepath" "strings" - "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/coderutil" "cdr.dev/wsep" "golang.org/x/xerrors" "nhooyr.io/websocket" + + "cdr.dev/coder-cli/coder-sdk" + "cdr.dev/coder-cli/internal/coderutil" ) // SingleFile copies the given file into the remote dir or remote path of the given coder.Environment. diff --git a/internal/sync/sync.go b/internal/sync/sync.go index 34713ad7..076d4124 100644 --- a/internal/sync/sync.go +++ b/internal/sync/sync.go @@ -22,11 +22,12 @@ import ( "golang.org/x/sync/semaphore" "golang.org/x/xerrors" + "cdr.dev/wsep" + "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/internal/activity" "cdr.dev/coder-cli/internal/coderutil" "cdr.dev/coder-cli/pkg/clog" - "cdr.dev/wsep" ) // Sync runs a live sync daemon. diff --git a/internal/x/xcobra/cobra.go b/internal/x/xcobra/cobra.go index d991e791..7ddfd9e2 100644 --- a/internal/x/xcobra/cobra.go +++ b/internal/x/xcobra/cobra.go @@ -4,8 +4,9 @@ package xcobra import ( "fmt" - "cdr.dev/coder-cli/pkg/clog" "github.com/spf13/cobra" + + "cdr.dev/coder-cli/pkg/clog" ) // ExactArgs returns an error if there are not exactly n args. diff --git a/pkg/tcli/tcli_test.go b/pkg/tcli/tcli_test.go index 5ecce5f0..178e702c 100644 --- a/pkg/tcli/tcli_test.go +++ b/pkg/tcli/tcli_test.go @@ -8,8 +8,9 @@ import ( "testing" "time" - "cdr.dev/coder-cli/pkg/tcli" "cdr.dev/slog/sloggers/slogtest/assert" + + "cdr.dev/coder-cli/pkg/tcli" ) func TestTCli(t *testing.T) {