From 44707177b505beec03bb07d94daec0ffba5b80b5 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 3 Feb 2022 10:14:31 +0000 Subject: [PATCH 01/12] Add golangci lint configuration and github workflow --- .github/workflows/golangci-lint.yml | 18 ++++++++++++++++++ .golangci.yml | 24 ++++++++++++++++++++++++ Makefile | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000..fc895ced --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,18 @@ +name: golangci-lint +on: + push: + pull_request: +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.44.0 \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..48697795 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,24 @@ +run: + timeout: 5m + skip-dirs-use-default: true + modules-download-mode: readonly + allow-parallel-runners: true + +output: + sort-results: true + +linters: + disable-all: true + enable: + - deadcode + - gci + - godot + - unparam + - unused + +linters-settings: + gci: + local-prefixes: github.com/suborbital + godot: + scope: all + capital: true \ No newline at end of file diff --git a/Makefile b/Makefile index 1845484e..6cddc077 100644 --- a/Makefile +++ b/Makefile @@ -20,5 +20,7 @@ mod/replace/atmo: tidy: go mod tidy && go mod download && go mod vendor +lint: + golangci-lint run ./... .PHONY: subo subo/docker \ No newline at end of file From 7b3c75fcf0d34e1278c49f2a3f91cf693e8fa835 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 3 Feb 2022 10:16:31 +0000 Subject: [PATCH 02/12] Restore recommended golangci-lint workflow config --- .github/workflows/golangci-lint.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index fc895ced..9dbd3bab 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,11 +1,15 @@ name: golangci-lint on: push: + tags: + - v* + branches: + - master + - main pull_request: permissions: contents: read - # Optional: allow read access to pull request. Use with `only-new-issues` option. - # pull-requests: read + pull-requests: read jobs: golangci: name: lint From caf851e784807b15f8edca7f6c4138efed952123 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 3 Feb 2022 10:39:02 +0000 Subject: [PATCH 03/12] Do not check for comments start with capital letter --- .golangci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 48697795..da75d95e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,5 +20,4 @@ linters-settings: gci: local-prefixes: github.com/suborbital godot: - scope: all - capital: true \ No newline at end of file + scope: all \ No newline at end of file From 14e0530f43f921db9a1bcb49450305a68f1d29ce Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 3 Feb 2022 10:41:05 +0000 Subject: [PATCH 04/12] gci fixes --- builder/context/buildcontext.go | 3 ++- builder/context/directive.go | 3 ++- builder/context/static.go | 1 + builder/template/config.go | 1 + builder/template/templates.go | 1 + root.go | 1 + scn/api.go | 1 + scn/emailverifier.go | 1 + scn/environmenttoken.go | 1 + scn/telemetry.go | 1 + subo/command/build.go | 1 + subo/command/clean.go | 1 + subo/command/compute_create_token.go | 3 ++- subo/command/compute_deploy_core.go | 1 + subo/command/create_handler.go | 1 + subo/command/create_project.go | 1 + subo/command/create_release.go | 3 ++- subo/command/create_runnable.go | 3 ++- subo/command/dev.go | 1 + subo/release/check.go | 1 + subo/repl/repl.go | 1 + 21 files changed, 26 insertions(+), 5 deletions(-) diff --git a/builder/context/buildcontext.go b/builder/context/buildcontext.go index 09630e03..c399c072 100644 --- a/builder/context/buildcontext.go +++ b/builder/context/buildcontext.go @@ -8,10 +8,11 @@ import ( "strings" "github.com/pkg/errors" + "gopkg.in/yaml.v2" + "github.com/suborbital/atmo/directive" "github.com/suborbital/subo/subo/release" "github.com/suborbital/subo/subo/util" - "gopkg.in/yaml.v2" ) var dockerImageForLang = map[string]string{ diff --git a/builder/context/directive.go b/builder/context/directive.go index ded48da2..53248732 100644 --- a/builder/context/directive.go +++ b/builder/context/directive.go @@ -7,9 +7,10 @@ import ( "path/filepath" "github.com/pkg/errors" + "gopkg.in/yaml.v2" + "github.com/suborbital/atmo/directive" "github.com/suborbital/subo/subo/util" - "gopkg.in/yaml.v2" ) // WriteDirectiveFile writes a Directive to disk diff --git a/builder/context/static.go b/builder/context/static.go index 1b85b24f..fb0fcf13 100644 --- a/builder/context/static.go +++ b/builder/context/static.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/pkg/errors" + "github.com/suborbital/atmo/bundle" ) diff --git a/builder/template/config.go b/builder/template/config.go index bf051764..1271d5ce 100644 --- a/builder/template/config.go +++ b/builder/template/config.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/pkg/errors" + "github.com/suborbital/subo/subo/util" ) diff --git a/builder/template/templates.go b/builder/template/templates.go index 2bf1e1e8..d8fada0c 100644 --- a/builder/template/templates.go +++ b/builder/template/templates.go @@ -11,6 +11,7 @@ import ( "text/template" "github.com/pkg/errors" + "github.com/suborbital/atmo/directive" "github.com/suborbital/subo/subo/util" ) diff --git a/root.go b/root.go index aab907a4..6a6c5062 100644 --- a/root.go +++ b/root.go @@ -2,6 +2,7 @@ package main import ( "github.com/spf13/cobra" + "github.com/suborbital/subo/subo/command" "github.com/suborbital/subo/subo/features" "github.com/suborbital/subo/subo/release" diff --git a/scn/api.go b/scn/api.go index 6aa6b2c6..abd5d501 100644 --- a/scn/api.go +++ b/scn/api.go @@ -10,6 +10,7 @@ import ( "net/url" "github.com/pkg/errors" + "github.com/suborbital/subo/scn/types" ) diff --git a/scn/emailverifier.go b/scn/emailverifier.go index d782ec02..ce86138a 100644 --- a/scn/emailverifier.go +++ b/scn/emailverifier.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/pkg/errors" + "github.com/suborbital/subo/scn/types" ) diff --git a/scn/environmenttoken.go b/scn/environmenttoken.go index 7222d1ef..9fba68b3 100644 --- a/scn/environmenttoken.go +++ b/scn/environmenttoken.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/pkg/errors" + "github.com/suborbital/subo/scn/types" ) diff --git a/scn/telemetry.go b/scn/telemetry.go index 0a25f076..11d65ad0 100644 --- a/scn/telemetry.go +++ b/scn/telemetry.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/pkg/errors" + "github.com/suborbital/subo/scn/types" ) diff --git a/subo/command/build.go b/subo/command/build.go index 74734491..a47d334f 100644 --- a/subo/command/build.go +++ b/subo/command/build.go @@ -6,6 +6,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/suborbital/subo/builder" "github.com/suborbital/subo/subo/util" ) diff --git a/subo/command/clean.go b/subo/command/clean.go index 540bd829..8beacb4a 100644 --- a/subo/command/clean.go +++ b/subo/command/clean.go @@ -9,6 +9,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/suborbital/subo/builder/context" "github.com/suborbital/subo/subo/util" ) diff --git a/subo/command/compute_create_token.go b/subo/command/compute_create_token.go index 53573ef6..82cb8101 100644 --- a/subo/command/compute_create_token.go +++ b/subo/command/compute_create_token.go @@ -2,11 +2,12 @@ package command import ( "fmt" - "github.com/suborbital/subo/subo/util" "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/suborbital/subo/subo/input" + "github.com/suborbital/subo/subo/util" ) const ( diff --git a/subo/command/compute_deploy_core.go b/subo/command/compute_deploy_core.go index 4f547f38..6fd49098 100644 --- a/subo/command/compute_deploy_core.go +++ b/subo/command/compute_deploy_core.go @@ -11,6 +11,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/suborbital/subo/builder/context" "github.com/suborbital/subo/builder/template" "github.com/suborbital/subo/subo/input" diff --git a/subo/command/create_handler.go b/subo/command/create_handler.go index 235d46a9..58548901 100644 --- a/subo/command/create_handler.go +++ b/subo/command/create_handler.go @@ -6,6 +6,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/suborbital/atmo/directive" "github.com/suborbital/subo/builder/context" "github.com/suborbital/subo/subo/util" diff --git a/subo/command/create_project.go b/subo/command/create_project.go index 8924bd55..73f25683 100644 --- a/subo/command/create_project.go +++ b/subo/command/create_project.go @@ -6,6 +6,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/suborbital/subo/builder/context" "github.com/suborbital/subo/builder/template" "github.com/suborbital/subo/subo/release" diff --git a/subo/command/create_release.go b/subo/command/create_release.go index c2d3cc1e..728a6b83 100644 --- a/subo/command/create_release.go +++ b/subo/command/create_release.go @@ -9,9 +9,10 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - "github.com/suborbital/subo/subo/util" "golang.org/x/mod/semver" "gopkg.in/yaml.v2" + + "github.com/suborbital/subo/subo/util" ) // DotSuboFile describes a .subo file for controlling releases diff --git a/subo/command/create_runnable.go b/subo/command/create_runnable.go index f1e95837..2028a7d4 100644 --- a/subo/command/create_runnable.go +++ b/subo/command/create_runnable.go @@ -8,12 +8,13 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "gopkg.in/yaml.v2" + "github.com/suborbital/atmo/directive" "github.com/suborbital/subo/builder/context" "github.com/suborbital/subo/builder/template" "github.com/suborbital/subo/subo/release" "github.com/suborbital/subo/subo/util" - "gopkg.in/yaml.v2" ) // validLangs are the available languages diff --git a/subo/command/dev.go b/subo/command/dev.go index 89b7d160..358aba78 100644 --- a/subo/command/dev.go +++ b/subo/command/dev.go @@ -6,6 +6,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/suborbital/subo/builder/context" "github.com/suborbital/subo/subo/util" ) diff --git a/subo/release/check.go b/subo/release/check.go index bc942b38..54c732b4 100644 --- a/subo/release/check.go +++ b/subo/release/check.go @@ -13,6 +13,7 @@ import ( "github.com/google/go-github/v41/github" "github.com/hashicorp/go-version" "github.com/pkg/errors" + "github.com/suborbital/subo/subo/util" ) diff --git a/subo/repl/repl.go b/subo/repl/repl.go index ae897a74..eef44bed 100644 --- a/subo/repl/repl.go +++ b/subo/repl/repl.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/pkg/errors" + "github.com/suborbital/atmo/fqfn" "github.com/suborbital/subo/subo/input" ) From 0c7d56f4cac2177fb99e51f17f6c5ddebfa03a60 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 3 Feb 2022 10:41:56 +0000 Subject: [PATCH 05/12] godot fixes --- builder/builder.go | 22 ++++++++++---------- builder/context/buildcontext.go | 20 +++++++++---------- builder/context/directive.go | 10 +++++----- builder/context/native.go | 2 +- builder/context/prereq.go | 2 +- builder/context/static.go | 2 +- builder/template/config.go | 2 +- builder/template/templates.go | 30 ++++++++++++++-------------- root.go | 7 +++---- scn/api.go | 14 ++++++------- scn/emailverifier.go | 2 +- scn/environmenttoken.go | 2 +- scn/telemetry.go | 2 +- scn/types/emailverifier.go | 8 ++++---- scn/types/environmenttoken.go | 4 ++-- scn/types/heartbeat.go | 4 ++-- subo/command/build.go | 9 ++++----- subo/command/clean.go | 2 +- subo/command/compute_create_token.go | 4 ++-- subo/command/compute_deploy_core.go | 26 ++++++++++++------------ subo/command/create_handler.go | 6 +++--- subo/command/create_project.go | 4 ++-- subo/command/create_release.go | 22 ++++++++++---------- subo/command/create_runnable.go | 12 +++++------ subo/command/dev.go | 2 +- subo/features/public.go | 2 +- subo/input/input.go | 2 +- subo/localproxy/proxy.go | 6 +++--- subo/release/check.go | 4 ++-- subo/release/version.go | 8 ++++---- subo/repl/repl.go | 4 ++-- subo/util/cache.go | 2 +- subo/util/exec.go | 6 +++--- subo/util/log.go | 16 +++++++-------- subo/util/mkdir.go | 2 +- subo/util/permissions.go | 1 + subo/util/version_check.go | 6 +++--- 37 files changed, 139 insertions(+), 140 deletions(-) diff --git a/builder/builder.go b/builder/builder.go index 1b3e0472..37d2427e 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -20,7 +20,7 @@ import ( "github.com/suborbital/subo/subo/util" ) -// Builder is capable of building Wasm modules from source +// Builder is capable of building Wasm modules from source. type Builder struct { Context *context.BuildContext @@ -29,7 +29,7 @@ type Builder struct { log util.FriendlyLogger } -// BuildResult is the results of a build including the built module and logs +// BuildResult is the results of a build including the built module and logs. type BuildResult struct { Succeeded bool OutputLog string @@ -42,7 +42,7 @@ const ( ToolchainDocker = Toolchain("docker") ) -// ForDirectory creates a Builder bound to a particular directory +// ForDirectory creates a Builder bound to a particular directory. func ForDirectory(logger util.FriendlyLogger, dir string) (*Builder, error) { ctx, err := context.ForDirectory(dir) if err != nil { @@ -63,8 +63,8 @@ func (b *Builder) BuildWithToolchain(tcn Toolchain) error { b.results = []BuildResult{} - // when building in Docker mode, just collect the langs we need to build, and then - // launch the associated builder images which will do the building + // When building in Docker mode, just collect the langs we need to build, and then + // launch the associated builder images which will do the building. dockerLangs := map[string]bool{} for _, r := range b.Context.Runnables { @@ -89,8 +89,8 @@ func (b *Builder) BuildWithToolchain(tcn Toolchain) error { err = b.doNativeBuildForRunnable(r, result) - // even if there was a failure, load the result into the builder - // since the logs of the failed build are useful + // Even if there was a failure, load the result into the builder + // since the logs of the failed build are useful. b.results = append(b.results, *result) if err != nil { @@ -144,7 +144,7 @@ func (b *Builder) Bundle() error { } else if b.Context.Directive.Headless { b.log.LogInfo("updating Directive") - // bump the appVersion since we're in headless mode + // Bump the appVersion since we're in headless mode. majorStr := strings.TrimPrefix(semver.Major(b.Context.Directive.AppVersion), "v") major, _ := strconv.Atoi(majorStr) new := fmt.Sprintf("v%d.0.0", major+1) @@ -212,7 +212,7 @@ func (b *Builder) dockerBuildForLang(lang string) (*BuildResult, error) { return result, nil } -// results and resulting file are loaded into the BuildResult pointer +// results and resulting file are loaded into the BuildResult pointer. func (b *Builder) doNativeBuildForRunnable(r context.RunnableDir, result *BuildResult) error { cmds, err := context.NativeBuildCommands(r.Runnable.Lang) if err != nil { @@ -232,7 +232,7 @@ func (b *Builder) doNativeBuildForRunnable(r context.RunnableDir, result *BuildR cmdString := strings.TrimSpace(fullCmd.String()) - // Even if the command fails, still load the output into the result object + // Even if the command fails, still load the output into the result object. outputLog, err := util.RunInDir(cmdString, r.Fullpath) result.OutputLog += outputLog + "\n" @@ -288,7 +288,7 @@ func (b *Builder) checkAndRunPreReqs(runnable context.RunnableDir, result *Build } // analyzeForCompilerFlags looks at the Runnable and determines if any additional compiler flags are needed -// this is initially added to support AS-JSON in AssemblyScript with its need for the --transform flag +// this is initially added to support AS-JSON in AssemblyScript with its need for the --transform flag. func (b *Builder) analyzeForCompilerFlags(runnable context.RunnableDir) (string, error) { if runnable.Runnable.Lang == "assemblyscript" { packageJSONBytes, err := ioutil.ReadFile(filepath.Join(runnable.Fullpath, "package.json")) diff --git a/builder/context/buildcontext.go b/builder/context/buildcontext.go index c399c072..580524c0 100644 --- a/builder/context/buildcontext.go +++ b/builder/context/buildcontext.go @@ -24,7 +24,7 @@ var dockerImageForLang = map[string]string{ "js": "suborbital/builder-js", } -// BuildContext describes the context under which the tool is being run +// BuildContext describes the context under which the tool is being run. type BuildContext struct { Cwd string CwdIsRunnable bool @@ -38,7 +38,7 @@ type BuildContext struct { BuilderTag string } -// RunnableDir represents a directory containing a Runnable +// RunnableDir represents a directory containing a Runnable. type RunnableDir struct { Name string UnderscoreName string @@ -47,13 +47,13 @@ type RunnableDir struct { CompilerFlags string } -// BundleRef contains information about a bundle in the current context +// BundleRef contains information about a bundle in the current context. type BundleRef struct { Exists bool Fullpath string } -// ForDirectory returns the build context for the provided working directory +// ForDirectory returns the build context for the provided working directory. func ForDirectory(dir string) (*BuildContext, error) { fullDir, err := filepath.Abs(dir) if err != nil { @@ -101,7 +101,7 @@ func ForDirectory(dir string) (*BuildContext, error) { return bctx, nil } -// RunnableExists returns true if the context contains a runnable with name +// RunnableExists returns true if the context contains a runnable with name . func (b *BuildContext) RunnableExists(name string) bool { for _, r := range b.Runnables { if r.Name == name { @@ -112,7 +112,7 @@ func (b *BuildContext) RunnableExists(name string) bool { return false } -// ShouldBuildLang returns true if the provided language is safe-listed for building +// ShouldBuildLang returns true if the provided language is safe-listed for building. func (b *BuildContext) ShouldBuildLang(lang string) bool { if len(b.Langs) == 0 { return true @@ -147,13 +147,13 @@ func (b *BuildContext) Modules() ([]os.File, error) { func getRunnableDirs(cwd string) ([]RunnableDir, bool, error) { runnables := []RunnableDir{} - // go through all of the dirs in the current dir + // Go through all of the dirs in the current dir. topLvlFiles, err := ioutil.ReadDir(cwd) if err != nil { return nil, false, errors.Wrap(err, "failed to list directory") } - // check to see if we're running from within a Runnable directory + // Check to see if we're running from within a Runnable directory // and return true if so. runnableDir, err := getRunnableFromFiles(cwd, topLvlFiles) if err != nil { @@ -170,7 +170,7 @@ func getRunnableDirs(cwd string) ([]RunnableDir, bool, error) { dirPath := filepath.Join(cwd, tf.Name()) - // determine if a .runnable file exists in that dir + // Determine if a .runnable file exists in that dir. innerFiles, err := ioutil.ReadDir(dirPath) if err != nil { util.LogWarn(fmt.Sprintf("couldn't read files in %v", dirPath)) @@ -190,7 +190,7 @@ func getRunnableDirs(cwd string) ([]RunnableDir, bool, error) { return runnables, false, nil } -// containsRunnableYaml finds any .runnable file in a list of files +// ContainsRunnableYaml finds any .runnable file in a list of files. func ContainsRunnableYaml(files []os.FileInfo) (string, bool) { for _, f := range files { if strings.HasPrefix(f.Name(), ".runnable.") { diff --git a/builder/context/directive.go b/builder/context/directive.go index 53248732..49172cdd 100644 --- a/builder/context/directive.go +++ b/builder/context/directive.go @@ -13,7 +13,7 @@ import ( "github.com/suborbital/subo/subo/util" ) -// WriteDirectiveFile writes a Directive to disk +// WriteDirectiveFile writes a Directive to disk. func WriteDirectiveFile(cwd string, directive *directive.Directive) error { filePath := filepath.Join(cwd, "Directive.yaml") @@ -29,7 +29,7 @@ func WriteDirectiveFile(cwd string, directive *directive.Directive) error { return nil } -// readDirectiveFile finds a Directive from disk but does not validate it +// readDirectiveFile finds a Directive from disk but does not validate it. func readDirectiveFile(cwd string) (*directive.Directive, error) { filePath := filepath.Join(cwd, "Directive.yaml") @@ -55,7 +55,7 @@ func readDirectiveFile(cwd string) (*directive.Directive, error) { return directive, nil } -// readQueriesFile finds a queries.yaml from disk +// readQueriesFile finds a queries.yaml from disk. func readQueriesFile(cwd string) ([]directive.DBQuery, error) { filePath := filepath.Join(cwd, "Queries.yaml") @@ -77,7 +77,7 @@ func readQueriesFile(cwd string) ([]directive.DBQuery, error) { } // AugmentAndValidateDirectiveFns ensures that all functions referenced in a handler exist -// in the project and then adds the function list to the provided directive +// in the project and then adds the function list to the provided directive. func AugmentAndValidateDirectiveFns(dxe *directive.Directive, fns []RunnableDir) error { fnMap := map[string]bool{} for _, fn := range fns { @@ -102,7 +102,7 @@ func AugmentAndValidateDirectiveFns(dxe *directive.Directive, fns []RunnableDir) return nil } -// getHandlerFnList gets a full list of all functions used in the directive's handlers +// getHandlerFnList gets a full list of all functions used in the directive's handlers. func getHandlerFnList(dxe *directive.Directive) []string { fnMap := map[string]bool{} diff --git a/builder/context/native.go b/builder/context/native.go index 8e8ba471..dac050f1 100644 --- a/builder/context/native.go +++ b/builder/context/native.go @@ -5,7 +5,7 @@ import ( "runtime" ) -// NativeBuildCommands returns the native build commands needed to build a Runnable of a particular language +// NativeBuildCommands returns the native build commands needed to build a Runnable of a particular language. func NativeBuildCommands(lang string) ([]string, error) { os := runtime.GOOS diff --git a/builder/context/prereq.go b/builder/context/prereq.go index 45dbd42f..6ad011b2 100644 --- a/builder/context/prereq.go +++ b/builder/context/prereq.go @@ -13,7 +13,7 @@ type Prereq struct { Command string } -// PreRequisiteCommands is a map of OS : language : preReq +// PreRequisiteCommands is a map of OS : language : preReq. var PreRequisiteCommands = map[string]map[string][]Prereq{ "darwin": { "rust": {}, diff --git a/builder/context/static.go b/builder/context/static.go index fb0fcf13..3104e788 100644 --- a/builder/context/static.go +++ b/builder/context/static.go @@ -11,7 +11,7 @@ import ( ) // CollectStaticFiles collects all of the files in the `static/` directory relative to cwd -// and generates a map of their relative paths +// and generates a map of their relative paths. func CollectStaticFiles(cwd string) (map[string]os.File, error) { staticDir := filepath.Join(cwd, "static") diff --git a/builder/template/config.go b/builder/template/config.go index 1271d5ce..631a29c7 100644 --- a/builder/template/config.go +++ b/builder/template/config.go @@ -27,7 +27,7 @@ func TemplateFullPath(repo, branch string) (string, error) { return filepath.Join(root, fmt.Sprintf("%s-%s", repoName, strings.ReplaceAll(branch, "/", "-")), "templates"), nil } -// TemplateRootDir gets the template directory for subo and ensures it exists +// TemplateRootDir gets the template directory for subo and ensures it exists. func TemplateRootDir() (string, error) { config, err := os.UserConfigDir() if err != nil { diff --git a/builder/template/templates.go b/builder/template/templates.go index d8fada0c..99f770e1 100644 --- a/builder/template/templates.go +++ b/builder/template/templates.go @@ -16,7 +16,7 @@ import ( "github.com/suborbital/subo/subo/util" ) -// ErrTemplateMissing and others are template related errors +// ErrTemplateMissing and others are template related errors. var ErrTemplateMissing = errors.New("template missing") type tmplData struct { @@ -47,7 +47,7 @@ func UpdateTemplates(repo, branch string) (string, error) { return "", errors.Wrap(err, "🚫 failed to downloadZip for templates") } - // tmplPath may be different than the default if a custom URL was provided + // The tmplPath may be different than the default if a custom URL was provided. tmplPath, err := extractZip(filepath, templateRootPath, branchDirName) if err != nil { return "", errors.Wrap(err, "🚫 failed to extractZip for templates") @@ -58,7 +58,7 @@ func UpdateTemplates(repo, branch string) (string, error) { return tmplPath, nil } -// TemplatesExist returns the templates directory for the provided repo and branch +// TemplatesExist returns the templates directory for the provided repo and branch. func TemplatesExist(repo, branch string) (string, error) { repoParts := strings.Split(repo, "/") if len(repoParts) != 2 { @@ -86,7 +86,7 @@ func TemplatesExist(repo, branch string) (string, error) { return tmplPath, nil } -// ExecRunnableTmplStr executes a template string with the runnable's data +// ExecRunnableTmplStr executes a template string with the runnable's data. func ExecRunnableTmplStr(templateStr string, runnable *directive.Runnable) (string, error) { templateData := makeTemplateData(runnable) @@ -103,14 +103,14 @@ func ExecRunnableTmplStr(templateStr string, runnable *directive.Runnable) (stri return builder.String(), nil } -// ExecRunnableTmpl copies a template +// ExecRunnableTmpl copies a template. func ExecRunnableTmpl(cwd, name, templatesPath string, runnable *directive.Runnable) error { templateData := makeTemplateData(runnable) return ExecTmplDir(cwd, name, templatesPath, runnable.Lang, templateData) } -// ExecTmplDir copies a generic templated directory +// ExecTmplDir copies a generic templated directory. func ExecTmplDir(cwd, name, templatesPath, tmplName string, templateData interface{}) error { templatePath := filepath.Join(templatesPath, tmplName) targetPath := filepath.Join(cwd, name) @@ -123,8 +123,8 @@ func ExecTmplDir(cwd, name, templatesPath, tmplName string, templateData interfa return errors.Wrap(err, "failed to Stat template directory") } - var err error = filepath.Walk(templatePath, func(path string, info os.FileInfo, _ error) error { - var relPath string = strings.Replace(path, templatePath, "", 1) + var err = filepath.Walk(templatePath, func(path string, info os.FileInfo, _ error) error { + var relPath = strings.Replace(path, templatePath, "", 1) if relPath == "" { return nil } @@ -144,15 +144,15 @@ func ExecTmplDir(cwd, name, templatesPath, tmplName string, templateData interfa targetRelPath = builder.String() } - // check if the target path is an existing file, and skip it if so + // Check if the target path is an existing file, and skip it if so. if _, err := os.Stat(filepath.Join(targetPath, targetRelPath)); err != nil { if os.IsNotExist(err) { - // that's fine, continue + // That's fine, continue. } else { return errors.Wrap(err, "failed to Stat") } } else { - // if the target file already exists, we're going to skip the rest since we don't want to overwrite + // If the target file already exists, we're going to skip the rest since we don't want to overwrite. return nil } @@ -193,7 +193,7 @@ func ExecTmplDir(cwd, name, templatesPath, tmplName string, templateData interfa return err } -// downloadZip downloads a ZIP from a particular branch of the Subo repo +// downloadZip downloads a ZIP from a particular branch of the Subo repo. func downloadZip(repo, branch, targetPath string) (string, error) { url := fmt.Sprintf("https://github.com/%s/archive/%s.zip", repo, branch) @@ -213,7 +213,7 @@ func downloadZip(repo, branch, targetPath string) (string, error) { filePath := filepath.Join(targetPath, "subo.zip") - // check if the zip already exists, and delete it if it does + // Check if the zip already exists, and delete it if it does. if _, err := os.Stat(filePath); err == nil { if err := os.Remove(filePath); err != nil { return "", errors.Wrap(err, "failed to delete exising templates zip") @@ -237,7 +237,7 @@ func downloadZip(repo, branch, targetPath string) (string, error) { return filePath, nil } -// extractZip extracts a ZIP file +// extractZip extracts a ZIP file. func extractZip(filePath, destPath, branchDirName string) (string, error) { escapedFilepath := strings.ReplaceAll(filePath, " ", "\\ ") escapedDestPath := strings.ReplaceAll(destPath, " ", "\\ ") + string(filepath.Separator) @@ -257,7 +257,7 @@ func extractZip(filePath, destPath, branchDirName string) (string, error) { return filepath.Join(existingPath, "templates"), nil } -// makeTemplateData makes data to be used in templates +// makeTemplateData makes data to be used in templates. func makeTemplateData(runnable *directive.Runnable) tmplData { nameCamel := "" nameParts := strings.Split(runnable.Name, "-") diff --git a/root.go b/root.go index 6a6c5062..47a4cb32 100644 --- a/root.go +++ b/root.go @@ -23,7 +23,7 @@ including building WebAssembly Runnables and Atmo projects.`, cmd.SetVersionTemplate("Subo CLI v{{.Version}}\n") - // create commands + // create commands. create := &cobra.Command{ Use: "create", Short: "create a runnable, project, or handler", @@ -38,13 +38,12 @@ including building WebAssembly Runnables and Atmo projects.`, create.AddCommand(command.CreateRunnableCmd()) create.AddCommand(command.CreateHandlerCmd()) - // compute network related commands + // compute network related commands. cmd.AddCommand(computeCommand()) - // docs related commands + // docs related commands. cmd.AddCommand(docsCommand()) - // add top-level commands to root cmd.AddCommand(create) cmd.AddCommand(command.BuildCmd()) cmd.AddCommand(command.DevCmd()) diff --git a/scn/api.go b/scn/api.go index abd5d501..62aa139a 100644 --- a/scn/api.go +++ b/scn/api.go @@ -19,18 +19,18 @@ const ( tokenRequestHeaderKey = "X-Suborbital-Env-Token" ) -// API is an API client +// API is an API client. type API struct { endpoint string } -// VerifiedAPI is an API that has an email-verified access level +// VerifiedAPI is an API that has an email-verified access level. type VerifiedAPI struct { api *API verifier *types.RequestVerifier } -// EnvironmentAPI is an API authenticated to a particular SCN environment +// EnvironmentAPI is an API authenticated to a particular SCN environment. type EnvironmentAPI struct { api *API token string @@ -44,7 +44,7 @@ func New(endpoint string) *API { return s } -// ForVerifiedEmail verifies an email address is correct and then creates a VerifiedAPI object +// ForVerifiedEmail verifies an email address is correct and then creates a VerifiedAPI object. func (a *API) ForVerifiedEmail(email string, codeFn func() (string, error)) (*VerifiedAPI, error) { verifier, err := a.createEmailVerifier(email) if err != nil { @@ -69,7 +69,7 @@ func (a *API) ForVerifiedEmail(email string, codeFn func() (string, error)) (*Ve return verified, nil } -// ForEnvironment returns an EnvironmentAPI scoped to the given token +// ForEnvironment returns an EnvironmentAPI scoped to the given token. func (a *API) ForEnvironment(token string) (*EnvironmentAPI, error) { env := &EnvironmentAPI{ api: a, @@ -79,12 +79,12 @@ func (a *API) ForEnvironment(token string) (*EnvironmentAPI, error) { return env, nil } -// do performs a request +// do performs a request. func (a *API) do(method string, URI string, body, result interface{}) error { return a.doWithHeaders(method, URI, nil, body, result) } -// doWithHeaders performs a request with the provided headers +// doWithHeaders performs a request with the provided headers. func (a *API) doWithHeaders(method string, URI string, headers map[string]string, body, result interface{}) error { var buffer io.Reader diff --git a/scn/emailverifier.go b/scn/emailverifier.go index ce86138a..d41b5b5c 100644 --- a/scn/emailverifier.go +++ b/scn/emailverifier.go @@ -8,7 +8,7 @@ import ( "github.com/suborbital/subo/scn/types" ) -// createEmailVerifier creates an emailverifier (used internally by API.Verify) +// createEmailVerifier creates an emailverifier (used internally by API.Verify). func (a *API) createEmailVerifier(email string) (*types.EmailVerifier, error) { uri := "/auth/v1/verifier" diff --git a/scn/environmenttoken.go b/scn/environmenttoken.go index 9fba68b3..5f850740 100644 --- a/scn/environmenttoken.go +++ b/scn/environmenttoken.go @@ -8,7 +8,7 @@ import ( "github.com/suborbital/subo/scn/types" ) -// CreateEnvironmentToken creates an environment token +// CreateEnvironmentToken creates an environment token. func (a *VerifiedAPI) CreateEnvironmentToken() (*types.CreateEnvironmentTokenResponse, error) { uri := "/auth/v1/token" diff --git a/scn/telemetry.go b/scn/telemetry.go index 11d65ad0..23eb62a5 100644 --- a/scn/telemetry.go +++ b/scn/telemetry.go @@ -8,7 +8,7 @@ import ( "github.com/suborbital/subo/scn/types" ) -// SendHeartbeat sends a telemetry heartbeat request +// SendHeartbeat sends a telemetry heartbeat request. func (e *EnvironmentAPI) SendHeartbeat(heartbeat *types.HeartbeatRequest) error { uri := "/telemetry/v1/heartbeat" diff --git a/scn/types/emailverifier.go b/scn/types/emailverifier.go index 278e75a3..eda3f756 100644 --- a/scn/types/emailverifier.go +++ b/scn/types/emailverifier.go @@ -2,7 +2,7 @@ package types import "time" -// EmailVerifier is an email verification record +// EmailVerifier is an email verification record. type EmailVerifier struct { ID int64 `json:"-" db:"id"` UUID string `json:"uuid" db:"uuid"` @@ -12,18 +12,18 @@ type EmailVerifier struct { State string `json:"state" db:"state"` } -// RequestVerifier is a verifier used in an HTTP request +// RequestVerifier is a verifier used in an HTTP request. type RequestVerifier struct { UUID string `json:"uuid"` Code string `json:"code"` } -// CreateEmailVerifierRequest is a request for an email verifier +// CreateEmailVerifierRequest is a request for an email verifier. type CreateEmailVerifierRequest struct { Email string `json:"email"` } -// CreateEmailVerifierResponse is a response to a CreateEmailVerifierRequest +// CreateEmailVerifierResponse is a response to a CreateEmailVerifierRequest. type CreateEmailVerifierResponse struct { Verifier EmailVerifier `json:"verifier"` } diff --git a/scn/types/environmenttoken.go b/scn/types/environmenttoken.go index 64eed42e..9f784af5 100644 --- a/scn/types/environmenttoken.go +++ b/scn/types/environmenttoken.go @@ -1,12 +1,12 @@ package types -// CreateEnvironmentTokenRequest is a request to create an environment token +// CreateEnvironmentTokenRequest is a request to create an environment token. type CreateEnvironmentTokenRequest struct { Verifier *RequestVerifier Env string `json:"env"` } -// CreateEnvironmentTokenResponse is a response to a create token request +// CreateEnvironmentTokenResponse is a response to a create token request. type CreateEnvironmentTokenResponse struct { Token string `json:"token"` } diff --git a/scn/types/heartbeat.go b/scn/types/heartbeat.go index 01b0ae53..3b8216b4 100644 --- a/scn/types/heartbeat.go +++ b/scn/types/heartbeat.go @@ -1,12 +1,12 @@ package types -// HeartbeatRequest is a request to send heartbeat data +// HeartbeatRequest is a request to send heartbeat data. type HeartbeatRequest struct { Version string `json:"version"` Runnables *RunnableStats `json:"runnables"` } -// RunnableStats are stats about runnables +// RunnableStats are stats about runnables. type RunnableStats struct { TotalCount int `json:"totalCount"` IdentCount int `json:"identCount"` diff --git a/subo/command/build.go b/subo/command/build.go index a47d334f..3e6a357c 100644 --- a/subo/command/build.go +++ b/subo/command/build.go @@ -11,7 +11,7 @@ import ( "github.com/suborbital/subo/subo/util" ) -// BuildCmd returns the build command +// BuildCmd returns the build command. func BuildCmd() *cobra.Command { cmd := &cobra.Command{ Use: "build [dir]", @@ -50,13 +50,13 @@ func BuildCmd() *cobra.Command { useNative, _ := cmd.Flags().GetBool("native") makeTarget, _ := cmd.Flags().GetString("make") - // determine if a custom Docker mountpath and relpath were set + // Determine if a custom Docker mountpath and relpath were set. mountPath, _ := cmd.Flags().GetString("mountpath") relPath, _ := cmd.Flags().GetString("relpath") if mountPath != "" { if relPath == "" { - // fallback to the dir arg as that's usually a sane default + // Fallback to the dir arg as that's usually a sane default. relPath = dir } @@ -85,8 +85,7 @@ func BuildCmd() *cobra.Command { toolchain = builder.ToolchainDocker } - // the builder does the majority of the work: - + // The builder does the majority of the work. if err := bdr.BuildWithToolchain(toolchain); err != nil { return errors.Wrap(err, "failed to BuildWithToolchain") } diff --git a/subo/command/clean.go b/subo/command/clean.go index 8beacb4a..ca77bed9 100644 --- a/subo/command/clean.go +++ b/subo/command/clean.go @@ -38,7 +38,7 @@ func CleanCmd() *cobra.Command { util.LogStart(fmt.Sprintf("cleaning in %s", bctx.Cwd)) for _, r := range bctx.Runnables { - //delete target or .build folder + // Delete target or .build folder. files, _ := ioutil.ReadDir(r.Fullpath) for _, file := range files { diff --git a/subo/command/compute_create_token.go b/subo/command/compute_create_token.go index 82cb8101..31c92ed9 100644 --- a/subo/command/compute_create_token.go +++ b/subo/command/compute_create_token.go @@ -14,7 +14,7 @@ const ( scnEndpointEnvKey = "SUBO_SCN_ENDPOINT" ) -// ComputeCreateTokenCommand returns the dev command +// ComputeCreateTokenCommand returns the dev command. func ComputeCreateTokenCommand() *cobra.Command { cmd := &cobra.Command{ Use: "token [email]", @@ -46,7 +46,7 @@ func ComputeCreateTokenCommand() *cobra.Command { return cmd } -// getVerifierCode gets the 6-character code from stdin +// getVerifierCode gets the 6-character code from stdin. func getVerifierCode() (string, error) { fmt.Print("A verification code was sent to your email address. Enter the code to continue: ") code, err := input.ReadStdinString() diff --git a/subo/command/compute_deploy_core.go b/subo/command/compute_deploy_core.go index 6fd49098..fcb1ccc1 100644 --- a/subo/command/compute_deploy_core.go +++ b/subo/command/compute_deploy_core.go @@ -30,7 +30,7 @@ type deployData struct { const proxyDefaultPort int = 80 -// ComputeDeployCoreCommand returns the compute deploy command +// ComputeDeployCoreCommand returns the compute deploy command. func ComputeDeployCoreCommand() *cobra.Command { cmd := &cobra.Command{ Use: "core", @@ -39,7 +39,7 @@ func ComputeDeployCoreCommand() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { localInstall := cmd.Flags().Changed(localFlag) shouldReset := cmd.Flags().Changed(resetFlag) - // shouldUpdate := cmd.Flags().Changed(updateFlag) will re-add this later once we have proper update semantics + // shouldUpdate := cmd.Flags().Changed(updateFlag) will re-add this later once we have proper update semantics. branch, _ := cmd.Flags().GetString(branchFlag) tag, _ := cmd.Flags().GetString(versionFlag) @@ -65,11 +65,11 @@ func ComputeDeployCoreCommand() *cobra.Command { } // if the --reset flag was passed or there's no existing manifests - // then we need to 'build the world' from scratch + // then we need to 'build the world' from scratch. if shouldReset || !manifestsExist(bctx) { util.LogStart("preparing deployment") - // if there are any existing deployment manifests sitting around, let's replace them + // if there are any existing deployment manifests sitting around, let's replace them. if err := removeExistingManifests(bctx); err != nil { return errors.Wrap(err, "failed to removeExistingManifests") } @@ -146,7 +146,7 @@ func ComputeDeployCoreCommand() *cobra.Command { }() // this is to give the proxy server some room to bind to the port and start up - // it's not ideal, but the least gross way to ensure a good experience + // it's not ideal, but the least gross way to ensure a good experience. time.Sleep(time.Second * 1) repl := repl.New(proxyPortStr) @@ -157,7 +157,7 @@ func ComputeDeployCoreCommand() *cobra.Command { return errors.Wrap(err, "🚫 failed to install KEDA") } - // we don't care if this fails, so don't check error + // we don't care if this fails, so don't check error. util.Run("kubectl create ns suborbital") if err := createConfigMap(cwd); err != nil { @@ -183,7 +183,7 @@ func ComputeDeployCoreCommand() *cobra.Command { cmd.Flags().Bool(localFlag, false, "deploy locally using docker-compose") cmd.Flags().Bool(dryRunFlag, false, "prepare the deployment in the .suborbital directory, but do not apply it") cmd.Flags().Bool(resetFlag, false, "reset the deployment to default (replaces docker-compose.yaml and/or Kubernetes manifests)") - // cmd.Flags().Bool(updateFlag, false, "update to the newest available version (replaces docker-compose.yaml and/or Kubernetes manifests") + // cmd.Flags().Bool(updateFlag, false, "update to the newest available version (replaces docker-compose.yaml and/or Kubernetes manifests"). return cmd } @@ -220,7 +220,7 @@ Are you ready to continue? (y/N): `) return nil } -// getEnvToken gets the environment token from stdin +// getEnvToken gets the environment token from stdin. func getEnvToken() (string, error) { buf, err := util.ReadEnvironmentToken() if err == nil { @@ -240,7 +240,7 @@ func getEnvToken() (string, error) { return token, nil } -// getBuilderDomain gets the environment token from stdin +// getBuilderDomain gets the environment token from stdin. func getBuilderDomain() (string, error) { fmt.Print("Enter the domain name that will be used for the builder service: ") domain, err := input.ReadStdinString() @@ -255,11 +255,11 @@ func getBuilderDomain() (string, error) { return domain, nil } -// getStorageClass gets the storage class to use +// getStorageClass gets the storage class to use. func getStorageClass() (string, error) { defaultClass, err := detectStorageClass() if err != nil { - // that's fine, continue + // that's fine, continue. fmt.Println("failed to automatically detect Kubernetes storage class:", err.Error()) } else if defaultClass != "" { fmt.Println("using default storage class: ", defaultClass) @@ -286,7 +286,7 @@ func detectStorageClass() (string, error) { } // output will look like: storageclass.storage.k8s.io/do-block-storage - // so split on the / and return the last part + // so split on the / and return the last part. outputParts := strings.Split(output, "/") if len(outputParts) != 2 { @@ -324,7 +324,7 @@ func manifestsExist(bctx *context.BuildContext) bool { } func removeExistingManifests(bctx *context.BuildContext) error { - // start with a clean slate + // start with a clean slate. if _, err := os.Stat(filepath.Join(bctx.Cwd, ".suborbital")); err == nil { if err := os.RemoveAll(filepath.Join(bctx.Cwd, ".suborbital")); err != nil { return errors.Wrap(err, "failed to RemoveAll .suborbital") diff --git a/subo/command/create_handler.go b/subo/command/create_handler.go index 58548901..0f66ee6d 100644 --- a/subo/command/create_handler.go +++ b/subo/command/create_handler.go @@ -46,7 +46,7 @@ func CreateHandlerCmd() *cobra.Command { return errors.New("cannot create handler, Directive.yaml not found") } - //Create a new handler object + // Create a new handler object. handler := directive.Handler{ Input: directive.Input{ Type: handlerType, @@ -55,10 +55,10 @@ func CreateHandlerCmd() *cobra.Command { }, } - //Add the handler object to the directive file + // Add the handler object to the directive file. bctx.Directive.Handlers = append(bctx.Directive.Handlers, handler) - //Write Directive File which overwrites the entire file + // Write Directive File which overwrites the entire file. if err := context.WriteDirectiveFile(bctx.Cwd, bctx.Directive); err != nil { return errors.Wrap(err, "failed to WriteDirectiveFile") } diff --git a/subo/command/create_project.go b/subo/command/create_project.go index 73f25683..1b0f956c 100644 --- a/subo/command/create_project.go +++ b/subo/command/create_project.go @@ -25,7 +25,7 @@ type projectData struct { AtmoVersion string } -// CreateProjectCmd returns the build command +// CreateProjectCmd returns the build command. func CreateProjectCmd() *cobra.Command { cmd := &cobra.Command{ Use: "project ", @@ -77,7 +77,7 @@ func CreateProjectCmd() *cobra.Command { } if err := template.ExecTmplDir(bctx.Cwd, name, templatesPath, "project", data); err != nil { - // if the templates are missing, try updating them and exec again + // if the templates are missing, try updating them and exec again. if err == template.ErrTemplateMissing { templatesPath, err = template.UpdateTemplates(defaultRepo, branch) if err != nil { diff --git a/subo/command/create_release.go b/subo/command/create_release.go index 728a6b83..51d74e37 100644 --- a/subo/command/create_release.go +++ b/subo/command/create_release.go @@ -15,7 +15,7 @@ import ( "github.com/suborbital/subo/subo/util" ) -// DotSuboFile describes a .subo file for controlling releases +// DotSuboFile describes a .subo file for controlling releases. type DotSuboFile struct { DotVersionFiles []string `yaml:"dotVersionFiles"` PreMakeTargets []string `yaml:"preMakeTargets"` @@ -23,7 +23,7 @@ type DotSuboFile struct { } // CreateReleaseCmd returns the create release command -// this is only available for development builds +// this is only available for development builds. func CreateReleaseCmd() *cobra.Command { cmd := &cobra.Command{ Use: "release ", @@ -37,23 +37,23 @@ func CreateReleaseCmd() *cobra.Command { newVersion := args[0] releaseName := args[1] - // ensure the version entered is sane + // ensure the version entered is sane. if err := validateVersion(newVersion); err != nil { return errors.Wrap(err, "failed to validateVersion") } - // ensure the git repo is clean, no untracked or uncommitted changes + // ensure the git repo is clean, no untracked or uncommitted changes. if err := checkGitCleanliness(); err != nil { return errors.Wrap(err, "failed to checkGitCleanliness") } - // ensure the current git branch is an rc branch + // ensure the current git branch is an rc branch. branch, err := ensureCorrectGitBranch(newVersion) if err != nil { return errors.Wrap(err, "failed to ensureCorrectGitBranch") } - // ensure a .subo.yml file is present and valid + // ensure a .subo.yml file is present and valid. dotSubo, err := findDotSubo(cwd) if err != nil { return errors.Wrap(err, "failed to findDotSubo") @@ -61,14 +61,14 @@ func CreateReleaseCmd() *cobra.Command { return errors.New(".subo.yml file is missing") } - // ensure a changelog exists for the relase + // ensure a changelog exists for the release. changelogFilePath := filepath.Join(cwd, "changelogs", fmt.Sprintf("%s.md", newVersion)) if err := checkChangelogFileExists(changelogFilePath); err != nil { return errors.Wrap(err, "failed to checkChangelogFileExists") } - // ensure each of the vesionFiles contains the string of the new version + // ensure each of the versionFiles contains the string of the new version. for _, f := range dotSubo.DotVersionFiles { filePath := filepath.Join(cwd, f) @@ -84,7 +84,7 @@ func CreateReleaseCmd() *cobra.Command { util.LogDone("release is ready to go") util.LogStart("running pre-make targets") - // run all of the pre-release make targets + // run all of the pre-release make targets. for _, target := range dotSubo.PreMakeTargets { targetWithVersion := strings.Replace(target, "{{ .Version }}", newVersion, -1) @@ -102,7 +102,7 @@ func CreateReleaseCmd() *cobra.Command { util.LogStart("creating release") - // ensure the local changes are pushed, create the release, and then pull down the new tag + // ensure the local changes are pushed, create the release, and then pull down the new tag. if _, err := util.Run("git push"); err != nil { return errors.Wrap(err, "failed to Run git push") } @@ -123,7 +123,7 @@ func CreateReleaseCmd() *cobra.Command { util.LogDone("release created!") util.LogStart("running post-make targets") - // run all of the post-release make targets + // run all of the post-release make targets. for _, target := range dotSubo.PostMakeTargets { targetWithVersion := strings.Replace(target, "{{ .Version }}", newVersion, -1) diff --git a/subo/command/create_runnable.go b/subo/command/create_runnable.go index 2028a7d4..76c649d2 100644 --- a/subo/command/create_runnable.go +++ b/subo/command/create_runnable.go @@ -17,7 +17,7 @@ import ( "github.com/suborbital/subo/subo/util" ) -// validLangs are the available languages +// validLangs are the available languages. var validLangs = map[string]bool{ "rust": true, "swift": true, @@ -27,7 +27,7 @@ var validLangs = map[string]bool{ "js": true, } -// langAliases are aliases for languages +// langAliases are aliases for languages. var langAliases = map[string]string{ "typescript": "assemblyscript", "rs": "rust", @@ -36,13 +36,13 @@ var langAliases = map[string]string{ "ts": "js", } -// CreateRunnableError wraps errors for CreateRunnableCmd() failures +// CreateRunnableError wraps errors for CreateRunnableCmd() failures. type CreateRunnableError struct { Path string // The ouput directory for build command CreateRunnableCmd(). error // The original error. } -// NewCreateRunnableError cleans up and returns CreateRunnableError for CreateRunnableCmd() failures +// NewCreateRunnableError cleans up and returns CreateRunnableError for CreateRunnableCmd() failures. func NewCreateRunnableError(path string, err error) CreateRunnableError { if cleanupErr := os.RemoveAll(path); cleanupErr != nil { err = errors.Wrap(err, "failed to clean up runnable outputs") @@ -50,7 +50,7 @@ func NewCreateRunnableError(path string, err error) CreateRunnableError { return CreateRunnableError{Path: path, error: err} } -// CreateRunnableCmd returns the build command +// CreateRunnableCmd returns the build command. func CreateRunnableCmd() *cobra.Command { cmd := &cobra.Command{ Use: "runnable <name>", @@ -100,7 +100,7 @@ func CreateRunnableCmd() *cobra.Command { } if err := template.ExecRunnableTmpl(bctx.Cwd, name, templatesPath, runnable); err != nil { - // if the templates are missing, try updating them and exec again + // if the templates are missing, try updating them and exec again. if err == template.ErrTemplateMissing { templatesPath, err = template.UpdateTemplates(repo, branch) if err != nil { diff --git a/subo/command/dev.go b/subo/command/dev.go index 358aba78..d8fb430b 100644 --- a/subo/command/dev.go +++ b/subo/command/dev.go @@ -11,7 +11,7 @@ import ( "github.com/suborbital/subo/subo/util" ) -// DevCmd returns the dev command +// DevCmd returns the dev command. func DevCmd() *cobra.Command { cmd := &cobra.Command{ Use: "dev", diff --git a/subo/features/public.go b/subo/features/public.go index 3133fc35..6030a6a2 100644 --- a/subo/features/public.go +++ b/subo/features/public.go @@ -3,7 +3,7 @@ package features -// EnableReleaseCommands and others are feature flags +// EnableReleaseCommands and others are feature flags. const ( EnableReleaseCommands = false EnableRegistryCommands = false diff --git a/subo/input/input.go b/subo/input/input.go index 392c78bd..924d587c 100644 --- a/subo/input/input.go +++ b/subo/input/input.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" ) -// ReadStdinString reads a string from stdin +// ReadStdinString reads a string from stdin. func ReadStdinString() (string, error) { scanner := bufio.NewScanner(os.Stdin) scanner.Scan() diff --git a/subo/localproxy/proxy.go b/subo/localproxy/proxy.go index e3c36bf0..21554795 100644 --- a/subo/localproxy/proxy.go +++ b/subo/localproxy/proxy.go @@ -6,14 +6,14 @@ import ( "net/http" ) -// Proxy is a proxy from the local machine to the cloud-hosted editor +// Proxy is a proxy from the local machine to the cloud-hosted editor. type Proxy struct { endpoint string server http.Server client *http.Client } -// New creates a new local proxy +// New creates a new local proxy. func New(endpoint string, listenPort string) *Proxy { p := &Proxy{ endpoint: endpoint, @@ -30,7 +30,7 @@ func New(endpoint string, listenPort string) *Proxy { return p } -// Start starts the local proxy server +// Start starts the local proxy server. func (p *Proxy) Start() error { fmt.Println("\nPROXY: local tunnel to function editor starting") diff --git a/subo/release/check.go b/subo/release/check.go index 54c732b4..9a4dde77 100644 --- a/subo/release/check.go +++ b/subo/release/check.go @@ -68,7 +68,7 @@ func getLatestReleaseCache() (*github.RepositoryRelease, error) { if cachedTimestamp, err := getTimestampCache(); err != nil { return nil, errors.Wrap(err, "failed to getTimestampCache") } else if currentTimestamp := time.Now().UTC(); cachedTimestamp.IsZero() || currentTimestamp.After(cachedTimestamp.Add(time.Hour)) { - // check if 1 hour has passed since the last version check, and update the cached timestamp and latest release if so + // check if 1 hour has passed since the last version check, and update the cached timestamp and latest release if so. if err := cacheTimestamp(currentTimestamp); err != nil { return nil, errors.Wrap(err, "failed to cacheTimestamp") } @@ -147,7 +147,7 @@ func getLatestVersion() (*version.Version, error) { return latestVersion, nil } -// CheckForLatestVersion returns an error if SuboDotVersion does not match the latest GitHub release or if the check fails +// CheckForLatestVersion returns an error if SuboDotVersion does not match the latest GitHub release or if the check fails. func CheckForLatestVersion() (string, error) { if latestCmdVersion, err := getLatestVersion(); err != nil { return "", errors.Wrap(err, "failed to getLatestVersion") diff --git a/subo/release/version.go b/subo/release/version.go index 92739c7d..b874ff0a 100644 --- a/subo/release/version.go +++ b/subo/release/version.go @@ -1,14 +1,14 @@ package release // SuboDotVersion represents the dot version for subo -// it is also the image tag used for builders +// it is also the image tag used for builders. var SuboDotVersion = "0.3.1" -// FFIVersion is the FFI version used by this version of subo +// FFIVersion is the FFI version used by this version of subo. var FFIVersion = "0.13.1" -// AtmoVersion is the default version of Atmo that will be used for new projects +// AtmoVersion is the default version of Atmo that will be used for new projects. var AtmoVersion = "0.4.2" -// SCCTag is the docker tag used for creating new compute core deployments +// SCCTag is the docker tag used for creating new compute core deployments. var SCCTag = "v0.1.1" diff --git a/subo/repl/repl.go b/subo/repl/repl.go index eef44bed..2844f94b 100644 --- a/subo/repl/repl.go +++ b/subo/repl/repl.go @@ -12,7 +12,7 @@ import ( "github.com/suborbital/subo/subo/input" ) -// Repl is a 'local proxy repl' that allows the user to perform simple actions against their local install of Compute +// Repl is a 'local proxy repl' that allows the user to perform simple actions against their local install of Compute. type Repl struct { proxyPort string } @@ -21,7 +21,7 @@ type tokenResp struct { Token string `json:"token"` } -// New creates a new "local proxy repl" +// New creates a new "local proxy repl". func New(proxyPort string) *Repl { return &Repl{proxyPort: proxyPort} } diff --git a/subo/util/cache.go b/subo/util/cache.go index 263bf2e2..5c0242cb 100644 --- a/subo/util/cache.go +++ b/subo/util/cache.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" ) -// CacheDir returns the cache directory and creates it if it doesn't exist +// CacheDir returns the cache directory and creates it if it doesn't exist. func CacheDir() (string, error) { targetPath := filepath.Join(os.TempDir(), "suborbital", "subo") diff --git a/subo/util/exec.go b/subo/util/exec.go index 63a274ee..a2c9d6b5 100644 --- a/subo/util/exec.go +++ b/subo/util/exec.go @@ -9,15 +9,15 @@ import ( "github.com/pkg/errors" ) -// Run runs a command, outputting to terminal and returning the full output and/or error +// Run runs a command, outputting to terminal and returning the full output and/or error. func Run(cmd string) (string, error) { return RunInDir(cmd, "") } -// RunInDir runs a command in the specified directory and returns the full output or error +// RunInDir runs a command in the specified directory and returns the full output or error. func RunInDir(cmd, dir string) (string, error) { // you can uncomment this below if you want to see exactly the commands being run - // fmt.Println("▶️", cmd) + // fmt.Println("▶️", cmd). command := exec.Command("sh", "-c", cmd) diff --git a/subo/util/log.go b/subo/util/log.go index ed1f649b..274249da 100644 --- a/subo/util/log.go +++ b/subo/util/log.go @@ -4,7 +4,7 @@ import ( "fmt" ) -// FriendlyLogger describes a logger designed to provide friendly output for interactive CLI purposes +// FriendlyLogger describes a logger designed to provide friendly output for interactive CLI purposes. type FriendlyLogger interface { LogInfo(string) LogStart(string) @@ -13,7 +13,7 @@ type FriendlyLogger interface { LogWarn(string) } -// PrintLogger is a struct wrapper around the logging functions used by Subo +// PrintLogger is a struct wrapper around the logging functions used by Subo. type PrintLogger struct{} func (p *PrintLogger) LogInfo(msg string) { LogInfo(msg) } @@ -22,32 +22,32 @@ func (p *PrintLogger) LogDone(msg string) { LogDone(msg) } func (p *PrintLogger) LogFail(msg string) { LogFail(msg) } func (p *PrintLogger) LogWarn(msg string) { LogWarn(msg) } -// Keeping it DRY +// Keeping it DRY. func log(msg string) { fmt.Println(msg) } -// LogInfo logs information +// LogInfo logs information. func LogInfo(msg string) { log(fmt.Sprintf("ℹ️ %s", msg)) } -// LogStart logs the start of something +// LogStart logs the start of something. func LogStart(msg string) { log(fmt.Sprintf("⏩ START: %s", msg)) } -// LogDone logs the success of something +// LogDone logs the success of something. func LogDone(msg string) { log(fmt.Sprintf("✅ DONE: %s", msg)) } -// LogFail logs the failure of something +// LogFail logs the failure of something. func LogFail(msg string) { log(fmt.Sprintf("🚫 FAILED: %s", msg)) } -// LogWarn logs a warning from something +// LogWarn logs a warning from something. func LogWarn(msg string) { log(fmt.Sprintf("⚠️ WARNING: %s", msg)) } diff --git a/subo/util/mkdir.go b/subo/util/mkdir.go index b137601c..fc3e7e7a 100644 --- a/subo/util/mkdir.go +++ b/subo/util/mkdir.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" ) -// Mkdir creates a new directory to contain a runnable +// Mkdir creates a new directory to contain a runnable. func Mkdir(cwd, name string) (string, error) { path := filepath.Join(cwd, name) diff --git a/subo/util/permissions.go b/subo/util/permissions.go index 1f9d8e28..dfee3986 100644 --- a/subo/util/permissions.go +++ b/subo/util/permissions.go @@ -5,6 +5,7 @@ import ( ) // These constants are meant to be used as reasonable default values for files and directories created by Subo. +// nolint:godot const ( PermDirectory fs.FileMode = 0755 // rwxr-xr-x PermDirectoryPrivate fs.FileMode = 0700 // rwx------ diff --git a/subo/util/version_check.go b/subo/util/version_check.go index e66aad7b..4107a9b1 100644 --- a/subo/util/version_check.go +++ b/subo/util/version_check.go @@ -7,10 +7,10 @@ import ( "github.com/pkg/errors" ) -// ErrVersionNotPresent are errors related to checking for version numbers +// ErrVersionNotPresent are errors related to checking for version numbers. var ErrVersionNotPresent = errors.New("expected version number is not present") -// CheckFileForVersionString returns an error if the requested file does not contain the provided versionString +// CheckFileForVersionString returns an error if the requested file does not contain the provided versionString. func CheckFileForVersionString(filePath string, versionString string) error { file, err := ioutil.ReadFile(filePath) if err != nil { @@ -18,7 +18,7 @@ func CheckFileForVersionString(filePath string, versionString string) error { } if !strings.Contains(string(file), versionString) { - // also check if it exists without the 'v' prefix + // also check if it exists without the 'v' prefix. noV := strings.TrimPrefix(versionString, "v") if !strings.Contains(string(file), noV) { From e82aceedc30d22b6900c12506d6d219345d6cd95 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky <gabor@suborbital.dev> Date: Mon, 7 Feb 2022 09:16:35 +0000 Subject: [PATCH 06/12] godot / gci fixes in docs --- docs/test/greeting_test.go | 8 ++--- subo/command/docs.go | 63 +++++++++++++++++++------------------- subo/command/push.go | 15 ++++----- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/docs/test/greeting_test.go b/docs/test/greeting_test.go index f1f9d497..9dada91a 100644 --- a/docs/test/greeting_test.go +++ b/docs/test/greeting_test.go @@ -1,28 +1,28 @@ package greetings // This comment is associated with the ExampleHello_doNotDoThis function example. -// This is showing you how not to use Hello +// This is showing you how not to use Hello. func ExampleHello_doNotDoThis() { Hello("Boo!") // Output: Ahhh! } // This comment is associated with the ExampleHello_doThis function example. -// This is showing you how to use Hello +// This is showing you how to use Hello. func ExampleHello_doThis() { Hello("world") // Output: Hello, world! } // This comment is associated with the package example. -// This is showing you how to use Hello +// This is showing you how to use Hello. func Example() { Hello("Foo Bar") // Output: Hello, Foo Bar! } // This comment is associated with the package example Example_doNotDoThis. -// This is showing you how to use Hello +// This is showing you how to use Hello. func Example_doNotDoThis() { Hello("boo!") // Output: Hello, Bar Foo! diff --git a/subo/command/docs.go b/subo/command/docs.go index 30e37a7a..c3775bab 100644 --- a/subo/command/docs.go +++ b/subo/command/docs.go @@ -17,6 +17,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" + "github.com/suborbital/subo/subo/util" ) @@ -58,7 +59,7 @@ type exampleData struct { Output string } -// DocsBuildCmd returns the docs build command +// DocsBuildCmd returns the docs build command. func DocsBuildCmd() *cobra.Command { cmd := &cobra.Command{ Use: "build [dir] [--output]", @@ -89,7 +90,7 @@ func DocsBuildCmd() *cobra.Command { return cmd } -// DocsTestCmd returns the docs test command +// DocsTestCmd returns the docs test command. func DocsTestCmd() *cobra.Command { cmd := &cobra.Command{ Use: "test [dir]", @@ -114,20 +115,20 @@ func DocsTestCmd() *cobra.Command { return cmd } -// generateDocs generates new docs with inserted example code snippets +// generateDocs generates new docs with inserted example code snippets. func generateDocs(dir string, outputDir string) error { files, err := getMarkdownCodeData(dir) if err != nil { return errors.Wrap(err, "failed to getMarkdownCodeData") } - // Generate docs with inserted code snippets + // Generate docs with inserted code snippets. for fileName, fileContent := range files["md"] { - // Clean template actions + // Clean template actions. r := regexp.MustCompile(cleanActionRegex) fileContent = r.ReplaceAllStringFunc(fileContent, func(src string) string { - // remove extra whitespaces from template actions + // remove extra whitespaces from template actions. r := regexp.MustCompile(actionSuffixRegex) if r.MatchString(src) { src = r.ReplaceAllLiteralString(src, actionSuffix) @@ -142,9 +143,9 @@ func generateDocs(dir string, outputDir string) error { }, ) r = regexp.MustCompile(oldDocsRegex) - // Remove old documentation examples + // Remove old documentation examples. fileContent = r.ReplaceAllLiteralString(fileContent, "") - // Generate new documentation examples + // Generate new documentation examples. filePath := filepath.Join(outputDir, fileName) fileDir := filepath.Dir(filePath) if info, err := os.Stat(fileDir); os.IsNotExist(err) { @@ -169,10 +170,10 @@ func generateDocs(dir string, outputDir string) error { // `{{ Snippet "greetings:doNotDoThis" }}` => only package example `doNotDoThis` is inserted from package `greeting` // {{ Snippet "greetings/Hello" }} => all function `Hello` examples are inserted from package `greetings` // {{ Snippet "greetings/Hello:doThis" }} => only function `Hello` example `doThis` is inserted from package `greetings` - // Nonexistent examples for packages or functions will cause `doc` cmd to fail + // Nonexistent examples for packages or functions will cause `doc` cmd to fail. tmpl, err := template.New(fileName).Funcs(template.FuncMap{ "Snippet": func(exampleKey string) (string, error) { - // Generate user template action for reinsertion + // Generate user template action for reinsertion. tmpl, err := template.New("NestedTemplateAction").Delims(`[[`, `]]`).Parse(actionTemplate) if err != nil { return "", err @@ -183,7 +184,7 @@ func generateDocs(dir string, outputDir string) error { return "", err } - // Check example key structure + // Check example key structure. var pkgName, funcName string keys := strings.Split(exampleKey, "/") if len(keys) == 1 { @@ -194,13 +195,13 @@ func generateDocs(dir string, outputDir string) error { return "", errors.New("`Snippet` expects a non-empty string key `packageName/funcName:Example` or 'packageName:Example', where 'funcName' and 'Example' are both optional") } - // Check if supportExt files, `go` files, where found + // Check if supportExt files, `go` files, where found. examples, ok := files[supportExt] if !ok { return "", errors.New(fmt.Sprintf("Failed to `Snippet`, no files found with ext `%s`", supportExt)) } - // Check if example exists + // Check if example exists. example, ok := examples[exampleKey] if !ok { if pkgName == "" { @@ -219,7 +220,7 @@ func generateDocs(dir string, outputDir string) error { if err != nil { return errors.Wrap(err, "failed to Parse") } else if err = tmpl.Execute(&buffer, ""); err != nil { - // Reset doc to its previous state + // Reset doc to its previous state. if errWrite := ioutil.WriteFile(filePath, []byte(fileContent), os.ModePerm); errWrite != nil { return errors.Wrap(errWrite, "failed to Write") } @@ -228,7 +229,7 @@ func generateDocs(dir string, outputDir string) error { } // weird behavior of text.templates, it adds new lines regardless of action delimiters - // This ReplaceAll compensates for it + // This ReplaceAll compensates for it. r = regexp.MustCompile(cleanExtraNewLines) fileContent = r.ReplaceAllLiteralString(buffer.String(), fmt.Sprintf("\n%s\n", docRegexEnd)) _, err = file.WriteString(fileContent) @@ -240,7 +241,7 @@ func generateDocs(dir string, outputDir string) error { return nil } -// getMarkdownCodeData returns a mapping of markdown texts and go example code snippets +// getMarkdownCodeData returns a mapping of markdown texts and go example code snippets. func getMarkdownCodeData(dir string) (map[string]map[string]string, error) { if _, err := os.Stat(dir); os.IsNotExist(err) { return nil, errors.Wrap(err, fmt.Sprintf("dir %s does not exist", dir)) @@ -261,7 +262,7 @@ func getMarkdownCodeData(dir string) (map[string]map[string]string, error) { return map[string]map[string]string{"md": mdTextss, "go": goSnippets}, nil } -// getMarkdownTexts returns discovered markdown texts +// getMarkdownTexts returns discovered markdown texts. func getMarkdownTexts(dir string) (map[string]string, error) { mdTexts := make(map[string]string) err := filepath.Walk(dir, @@ -298,7 +299,7 @@ func getMarkdownTexts(dir string) (map[string]string, error) { return mdTexts, nil } -// getGoSnippets returns discovered go example code snippets +// getGoSnippets returns discovered go example code snippets. func getGoSnippets(dir string) (map[string]string, error) { goSnippets := make(map[string]string) err := filepath.Walk(dir, @@ -320,20 +321,20 @@ func getGoSnippets(dir string) (map[string]string, error) { return errors.Wrap(err, "failed to ParseDir") } - // Get and structure package and function examples from ast to text + // Get and structure package and function examples from ast to text. for pkgName, pkg := range pkgs { files := []*ast.File{} for _, file := range pkg.Files { files = append(files, file) } - // Get special package and function asts that contain example metadata + // Get special package and function asts that contain example metadata. pkgDoc, err := doc.NewFromFiles(fset, files, filepath.Join(path, pkgName), doc.AllDecls) if err != nil { return errors.Wrap(err, "failed to NewFromFiles") } - // Process examples associated with the package + // Process examples associated with the package. pkgData := codeData{ Ext: "go", RegexStart: docRegexStart, @@ -350,7 +351,7 @@ func getGoSnippets(dir string) (map[string]string, error) { goSnippets[exampleKey] = text } - // Add all examples option for package + // Add all examples option for package. exampleKey := getExampleKey(pkgName, "", "") text, err := pkgData.getCodeText(exampleKey, docTemplate, actionTemplate, pkgDoc.Examples, fset) if err != nil { @@ -358,7 +359,7 @@ func getGoSnippets(dir string) (map[string]string, error) { } goSnippets[exampleKey] = text - // Process examples associated with this function or method + // Process examples associated with this function or method. for _, funcNode := range pkgDoc.Funcs { if len(funcNode.Examples) == 0 { continue @@ -381,7 +382,7 @@ func getGoSnippets(dir string) (map[string]string, error) { goSnippets[exampleKey] = text } - // Add all examples option for function + // Add all examples option for function. exampleKey := getExampleKey(pkgName, funcNode.Name, "") text, err := funcData.getCodeText(exampleKey, docTemplate, actionTemplate, funcNode.Examples, fset) if err != nil { @@ -402,7 +403,7 @@ func getGoSnippets(dir string) (map[string]string, error) { return goSnippets, nil } -// getExampleKey returns keys associated to examples +// getExampleKey returns keys associated to examples. func getExampleKey(pkgName, funcName, exampleSuffix string) string { key := pkgName if funcName != "" { @@ -417,14 +418,14 @@ func getExampleKey(pkgName, funcName, exampleSuffix string) string { return key } -// getCodeText returns code snippets generated from example asts +// getCodeText returns code snippets generated from example asts. func (c *codeData) getCodeText(exampleKey, docTemplate, actionTemplate string, examples []*doc.Example, fset *token.FileSet) (string, error) { err := c.getExampleData(examples, fset) if err != nil { return "", errors.Wrap(err, "failed to getExampleData") } - // Generate user template action for reinsertion + // Generate user template action for reinsertion. tmpl, err := template.New("NestedTemplateAction").Delims(`[[`, `]]`).Parse(actionTemplate) if err != nil { return "", errors.Wrap(err, "failed to Parse") @@ -436,7 +437,7 @@ func (c *codeData) getCodeText(exampleKey, docTemplate, actionTemplate string, e } c.Action = buffer.String() - // Generate code snippets based on `docTemplate` templates + // Generate code snippets based on `docTemplate` templates. tmpl, err = template.New("CodeText").Parse(docTemplate) if err != nil { return "", errors.Wrap(err, "failed to Parse") @@ -450,11 +451,11 @@ func (c *codeData) getCodeText(exampleKey, docTemplate, actionTemplate string, e return buffer.String(), nil } -// getExampleData loads example asts to codeData +// getExampleData loads example asts to codeData. func (c *codeData) getExampleData(examples []*doc.Example, fset *token.FileSet) error { c.Examples = nil for i, example := range examples { - // Get example code snippets ast + // Get example code snippets ast. var buffer bytes.Buffer switch n := example.Code.(type) { case *ast.BlockStmt: @@ -467,7 +468,7 @@ func (c *codeData) getExampleData(examples []*doc.Example, fset *token.FileSet) } } - // Get example code snippets metadata + // Get example code snippets metadata. c.Examples = append(c.Examples, &exampleData{ Suffix: example.Suffix, diff --git a/subo/command/push.go b/subo/command/push.go index 89bd6c11..0849fab8 100644 --- a/subo/command/push.go +++ b/subo/command/push.go @@ -15,9 +15,10 @@ import ( "github.com/pelletier/go-toml" "github.com/pkg/errors" "github.com/spf13/cobra" + "gopkg.in/yaml.v2" + "github.com/suborbital/subo/builder/context" "github.com/suborbital/subo/subo/util" - "gopkg.in/yaml.v2" ) const suboAuthor = "Subo <subo@suborbital.dev>" @@ -27,7 +28,7 @@ type parcelWrapper struct { data []byte } -//PushCmd packages the current project into a Bindle and pushes it to a Bindle server +//PushCmd packages the current project into a Bindle and pushes it to a Bindle server. func PushCmd() *cobra.Command { cmd := &cobra.Command{ Use: "push", @@ -64,7 +65,7 @@ func PushCmd() *cobra.Command { parcelsBySHA := map[string]parcelWrapper{} - // add the Directive as a parcel + // add the Directive as a parcel. directiveBytes, err := yaml.Marshal(bctx.Directive) if err != nil { return errors.Wrap(err, "failed to Marshal Directive") @@ -79,9 +80,9 @@ func PushCmd() *cobra.Command { data: directiveBytes, } - // add each Runnable as a parcel + // add each Runnable as a parcel. for _, r := range bctx.Runnables { - //delete target or .build folder + //delete target or .build folder. files, err := ioutil.ReadDir(r.Fullpath) if err != nil { return errors.Wrapf(err, "failed to ReadDir for %s", r.Name) @@ -199,7 +200,7 @@ func createOrReadKeypair(author string) (*types.SignatureKey, []byte, error) { return sigKey, privKey, nil } - // find the SignatureKey in the local Keyring + // find the SignatureKey in the local Keyring. for i, k := range kr.Key { if k.Label == author { sigKey = &kr.Key[i] @@ -207,7 +208,7 @@ func createOrReadKeypair(author string) (*types.SignatureKey, []byte, error) { } } - // read the privkey from the '.ssh' location + // read the privkey from the '.ssh' location. privKey, err = keyring.ReadPrivKey(privKeyFilepath()) if err != nil { return nil, nil, errors.Wrap(err, "failed to ReadPrivKey") From 69f56a6ba7800659d535f2b38042983335b2586c Mon Sep 17 00:00:00 2001 From: Gabor Javorszky <gabor@suborbital.dev> Date: Mon, 7 Feb 2022 09:17:22 +0000 Subject: [PATCH 07/12] Remove unused updateflag to be added back later --- subo/command/compute_deploy_core.go | 2 -- subo/command/flags.go | 1 - 2 files changed, 3 deletions(-) diff --git a/subo/command/compute_deploy_core.go b/subo/command/compute_deploy_core.go index fcb1ccc1..6ca4fa31 100644 --- a/subo/command/compute_deploy_core.go +++ b/subo/command/compute_deploy_core.go @@ -39,7 +39,6 @@ func ComputeDeployCoreCommand() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { localInstall := cmd.Flags().Changed(localFlag) shouldReset := cmd.Flags().Changed(resetFlag) - // shouldUpdate := cmd.Flags().Changed(updateFlag) will re-add this later once we have proper update semantics. branch, _ := cmd.Flags().GetString(branchFlag) tag, _ := cmd.Flags().GetString(versionFlag) @@ -183,7 +182,6 @@ func ComputeDeployCoreCommand() *cobra.Command { cmd.Flags().Bool(localFlag, false, "deploy locally using docker-compose") cmd.Flags().Bool(dryRunFlag, false, "prepare the deployment in the .suborbital directory, but do not apply it") cmd.Flags().Bool(resetFlag, false, "reset the deployment to default (replaces docker-compose.yaml and/or Kubernetes manifests)") - // cmd.Flags().Bool(updateFlag, false, "update to the newest available version (replaces docker-compose.yaml and/or Kubernetes manifests"). return cmd } diff --git a/subo/command/flags.go b/subo/command/flags.go index d1afe9c5..eed2508b 100644 --- a/subo/command/flags.go +++ b/subo/command/flags.go @@ -16,7 +16,6 @@ const ( preReleaseFlag = "prerelease" dryRunFlag = "dryrun" resetFlag = "reset" - updateFlag = "update" localFlag = "local" proxyPortFlag = "proxy-port" ) From 4bccfae1295471455e68b90f9c839a3152be7155 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky <gabor@suborbital.dev> Date: Mon, 7 Feb 2022 09:17:41 +0000 Subject: [PATCH 08/12] Remove unused resourceflag --- subo/command/flags.go | 1 - 1 file changed, 1 deletion(-) diff --git a/subo/command/flags.go b/subo/command/flags.go index eed2508b..e39d4511 100644 --- a/subo/command/flags.go +++ b/subo/command/flags.go @@ -9,7 +9,6 @@ const ( versionFlag = "version" repoFlag = "repo" typeFlag = "type" - resourceFlag = "resource" environmentFlag = "environment" updateTemplatesFlag = "update-templates" headlessFlag = "headless" From e48ef0a99749a13b7d4f823b77486d714e62394b Mon Sep 17 00:00:00 2001 From: Gabor Javorszky <gabor@suborbital.dev> Date: Mon, 7 Feb 2022 09:18:02 +0000 Subject: [PATCH 09/12] Remove unused handlerData --- subo/command/create_handler.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/subo/command/create_handler.go b/subo/command/create_handler.go index 0f66ee6d..c5bea501 100644 --- a/subo/command/create_handler.go +++ b/subo/command/create_handler.go @@ -12,12 +12,6 @@ import ( "github.com/suborbital/subo/subo/util" ) -type handlerData struct { - HandlerType string - Request string - Method string -} - func CreateHandlerCmd() *cobra.Command { cmd := &cobra.Command{ Use: "handler <resource>", From d6645742a4da35539e61c453bc8941d7ef20699f Mon Sep 17 00:00:00 2001 From: Gabor Javorszky <gabor@suborbital.dev> Date: Mon, 7 Feb 2022 09:40:14 +0000 Subject: [PATCH 10/12] unparam: docTemplate and actionTemplate --- subo/command/docs.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subo/command/docs.go b/subo/command/docs.go index c3775bab..5f54f7d0 100644 --- a/subo/command/docs.go +++ b/subo/command/docs.go @@ -343,7 +343,7 @@ func getGoSnippets(dir string) (map[string]string, error) { } for _, example := range pkgDoc.Examples { exampleKey := getExampleKey(pkgName, "", example.Suffix) - text, err := pkgData.getCodeText(exampleKey, docTemplate, actionTemplate, []*doc.Example{example}, fset) + text, err := pkgData.getCodeText(exampleKey, []*doc.Example{example}, fset) if err != nil { return errors.Wrap(err, "failed to getCodeText") } @@ -353,7 +353,7 @@ func getGoSnippets(dir string) (map[string]string, error) { // Add all examples option for package. exampleKey := getExampleKey(pkgName, "", "") - text, err := pkgData.getCodeText(exampleKey, docTemplate, actionTemplate, pkgDoc.Examples, fset) + text, err := pkgData.getCodeText(exampleKey, pkgDoc.Examples, fset) if err != nil { return errors.Wrap(err, "failed to getCodeText") } @@ -374,7 +374,7 @@ func getGoSnippets(dir string) (map[string]string, error) { } for _, example := range funcNode.Examples { exampleKey := getExampleKey(pkgName, example.Name, example.Suffix) - text, err := funcData.getCodeText(exampleKey, docTemplate, actionTemplate, []*doc.Example{example}, fset) + text, err := funcData.getCodeText(exampleKey, []*doc.Example{example}, fset) if err != nil { return errors.Wrap(err, "failed to getCodeText") } @@ -384,7 +384,7 @@ func getGoSnippets(dir string) (map[string]string, error) { // Add all examples option for function. exampleKey := getExampleKey(pkgName, funcNode.Name, "") - text, err := funcData.getCodeText(exampleKey, docTemplate, actionTemplate, funcNode.Examples, fset) + text, err := funcData.getCodeText(exampleKey, funcNode.Examples, fset) if err != nil { return errors.Wrap(err, "failed to getCodeText") } @@ -419,7 +419,7 @@ func getExampleKey(pkgName, funcName, exampleSuffix string) string { } // getCodeText returns code snippets generated from example asts. -func (c *codeData) getCodeText(exampleKey, docTemplate, actionTemplate string, examples []*doc.Example, fset *token.FileSet) (string, error) { +func (c *codeData) getCodeText(exampleKey string, examples []*doc.Example, fset *token.FileSet) (string, error) { err := c.getExampleData(examples, fset) if err != nil { return "", errors.Wrap(err, "failed to getExampleData") From 72e7d42b68f25969a4cc64c0f0650033bbf411fa Mon Sep 17 00:00:00 2001 From: Gabor Javorszky <gabor@suborbital.dev> Date: Mon, 7 Feb 2022 16:53:37 +0000 Subject: [PATCH 11/12] Make lint a prerequisite to other make targets, complete phonies --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 6cddc077..b04e9a8e 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,16 @@ include ./subo/release/release.mk GO_INSTALL=go install -ldflags $(RELEASE_FLAGS) -subo: +subo: lint $(GO_INSTALL) -subo/dev: +subo/dev: lint $(GO_INSTALL) -tags=development -subo/docker: +subo/docker: lint docker build . -t suborbital/subo:dev -subo/docker/publish: +subo/docker/publish: lint docker buildx build . --platform linux/amd64,linux/arm64 -t suborbital/subo:dev --push mod/replace/atmo: @@ -23,4 +23,4 @@ tidy: lint: golangci-lint run ./... -.PHONY: subo subo/docker \ No newline at end of file +.PHONY: subo subo/dev subo/docker subo/docker/publish mod/replace/atmo tidy lint \ No newline at end of file From 44005b8322704930649a8fcd9f69dcc2929b0c28 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky <gabor@suborbital.dev> Date: Mon, 7 Feb 2022 16:56:41 +0000 Subject: [PATCH 12/12] Add golangci-lint to the sanity workflow too --- .github/workflows/sanity.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sanity.yml b/.github/workflows/sanity.yml index d2f91b83..c78bb360 100644 --- a/.github/workflows/sanity.yml +++ b/.github/workflows/sanity.yml @@ -21,7 +21,12 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 - + + - name: Install golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.44.0 + - name: Build Subo run: | make subo