From 69b692b9627c5dc3bef245460e145892f66f62e6 Mon Sep 17 00:00:00 2001 From: "Ryan (hackercat)" Date: Mon, 3 May 2021 18:52:03 +0200 Subject: [PATCH] Add `super-linter` + fix lint issues (#650) * feat: bump `golangci-lint`, add `super-linter`, replace outdated linter Bump `golangci-lint` version. Add `super-linter` to lint other languages. Go linter is disabled because it's currently broken: https://github.com/github/super-linter/pull/370 Replacing `scopelint` with `exportloopref`: "[runner] The linter 'scopelint' is deprecated (since v1.39.0) due to: The repository of the linter has been deprecated by the owner. Replaced by exportloopref." Fixed formatting in `.golangci.yml` Add addtional linters: `misspell`: purely style, detects typos in comments `whitespace`: detects leading and trailing whitespace `goimports`: it's gofmt + checks unused imports * fix: lint/fix `go` files * fix: lint with `standardjs` * fix: lint/fix with `markdownlint`, make template more verbose * feat: add lint stuff to makefile * fix: `UseGitIgnore` formatting * fix: lint/fix `README.md` Co-authored-by: Casey Lee --- .github/ISSUE_TEMPLATE/issue_template.md | 42 +++++++++++++++--------- .github/linters/.golangci.yml | 1 + .github/linters/.markdown-lint.yml | 11 +++++++ .github/workflows/push.yml | 16 ++++++++- act/common/file.go | 4 --- act/common/git.go | 1 - act/common/git_test.go | 1 - act/container/docker_build.go | 1 - act/container/docker_pull.go | 2 -- act/container/docker_run.go | 1 - act/model/workflow.go | 16 ++++----- act/runner/expression_test.go | 2 -- act/runner/logger.go | 1 - act/runner/res/trampoline.js | 10 +++--- act/runner/run_context.go | 1 - act/runner/run_context_test.go | 1 - act/runner/runner.go | 2 +- act/runner/step_context.go | 1 - cmd/graph.go | 1 - 19 files changed, 66 insertions(+), 49 deletions(-) create mode 120000 .github/linters/.golangci.yml create mode 100644 .github/linters/.markdown-lint.yml diff --git a/.github/ISSUE_TEMPLATE/issue_template.md b/.github/ISSUE_TEMPLATE/issue_template.md index b616c67a..2472da07 100644 --- a/.github/ISSUE_TEMPLATE/issue_template.md +++ b/.github/ISSUE_TEMPLATE/issue_template.md @@ -1,20 +1,23 @@ --- name: Issue about: Use this template for reporting a bug/issue. -title: "Issue: " +title: "Issue: " labels: kind/bug assignees: '' --- ## Act version - + ```none @@ -22,14 +25,23 @@ assignees: '' ## Expected behaviour - + ## Actual behaviour - + ## Workflow and/or repository + - ## `act` output - +
Log ```none - +PASTE YOUR LOG HERE ```
diff --git a/.github/linters/.golangci.yml b/.github/linters/.golangci.yml new file mode 120000 index 00000000..d531ead6 --- /dev/null +++ b/.github/linters/.golangci.yml @@ -0,0 +1 @@ +../../.golangci.yml \ No newline at end of file diff --git a/.github/linters/.markdown-lint.yml b/.github/linters/.markdown-lint.yml new file mode 100644 index 00000000..bb91f2f0 --- /dev/null +++ b/.github/linters/.markdown-lint.yml @@ -0,0 +1,11 @@ +# Default state for all rules +default: true + +# MD013/line-length - Line length +MD013: false + +# MD033/no-inline-html - Inline HTML +MD033: false + +# MD041/first-line-heading/first-line-h1 - First line in a file should be a top-level heading +MD041: false diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index fc52d97d..851fb7b6 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -7,6 +7,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - uses: actions/setup-go@v1 with: go-version: 1.16 @@ -14,7 +16,19 @@ jobs: env: CGO_ENABLED: 0 with: - version: v1.32.2 + version: v1.39.0 + - uses: github/super-linter@v3 + env: + DEFAULT_BRANCH: master + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FILTER_REGEX_EXCLUDE: .*testdata/* + VALIDATE_ALL_CODEBASE: ${{ github.event_name != 'pull_request' }} # lint only new changes when pull_request + VALIDATE_BASH: false + VALIDATE_DOCKERFILE: false + VALIDATE_DOCKERFILE_HADOLINT: false + VALIDATE_GO: false # it's broken, see commit message + VALIDATE_JSCPD: false + VALIDATE_SHELL_SHFMT: false test: name: Test on Linux diff --git a/act/common/file.go b/act/common/file.go index 268b2726..0894f0c9 100644 --- a/act/common/file.go +++ b/act/common/file.go @@ -28,7 +28,6 @@ func CopyFile(source string, dest string) (err error) { if err != nil { _ = os.Chmod(dest, sourceinfo.Mode()) } - } return @@ -36,7 +35,6 @@ func CopyFile(source string, dest string) (err error) { // CopyDir recursive copy of directory func CopyDir(source string, dest string) (err error) { - // get properties of source dir sourceinfo, err := os.Stat(source) if err != nil { @@ -55,7 +53,6 @@ func CopyDir(source string, dest string) (err error) { objects, err := directory.Readdir(-1) for _, obj := range objects { - sourcefilepointer := source + "/" + obj.Name() destinationfilepointer := dest + "/" + obj.Name() @@ -73,7 +70,6 @@ func CopyDir(source string, dest string) (err error) { fmt.Println(err) } } - } return err } diff --git a/act/common/git.go b/act/common/git.go index 2cfecf87..24220916 100644 --- a/act/common/git.go +++ b/act/common/git.go @@ -301,7 +301,6 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor { // Repos on disk point to commit hashes, and need to checkout input.Ref before // we try and pull down any changes if hash.String() != input.Ref { - // Run git fetch to make sure we have the latest sha err := r.Fetch(&git.FetchOptions{}) if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { diff --git a/act/common/git_test.go b/act/common/git_test.go index 0edb4507..1567c24c 100644 --- a/act/common/git_test.go +++ b/act/common/git_test.go @@ -40,7 +40,6 @@ func TestFindGitSlug(t *testing.T) { assert.Equal(tt.provider, provider) assert.Equal(tt.slug, slug) } - } func testDir(t *testing.T) string { diff --git a/act/container/docker_build.go b/act/container/docker_build.go index f9107790..95d15e21 100644 --- a/act/container/docker_build.go +++ b/act/container/docker_build.go @@ -63,7 +63,6 @@ func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor { } return nil } - } func createBuildContext(contextDir string, relDockerfile string) (io.ReadCloser, error) { log.Debugf("Creating archive for build context dir '%s' with relative dockerfile '%s'", contextDir, relDockerfile) diff --git a/act/container/docker_pull.go b/act/container/docker_pull.go index ee8e0dbe..9ae49abf 100644 --- a/act/container/docker_pull.go +++ b/act/container/docker_pull.go @@ -62,9 +62,7 @@ func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor { return err } return nil - } - } func cleanImage(image string) string { diff --git a/act/container/docker_run.go b/act/container/docker_run.go index 1374c381..371d8b66 100644 --- a/act/container/docker_run.go +++ b/act/container/docker_run.go @@ -151,7 +151,6 @@ func (cr *containerReference) UpdateFromGithubEnv(env *map[string]string) common } func (cr *containerReference) Exec(command []string, env map[string]string) common.Executor { - return common.NewPipelineExecutor( cr.connect(), cr.find(), diff --git a/act/model/workflow.go b/act/model/workflow.go index 8fe9354d..50221b08 100644 --- a/act/model/workflow.go +++ b/act/model/workflow.go @@ -23,7 +23,6 @@ type Workflow struct { // On events for the workflow func (w *Workflow) On() []string { - switch w.RawOn.Kind { case yaml.ScalarNode: var val string @@ -109,7 +108,6 @@ func (j *Job) Container() *ContainerSpec { // Needs list for Job func (j *Job) Needs() []string { - switch j.RawNeeds.Kind { case yaml.ScalarNode: var val string @@ -131,7 +129,6 @@ func (j *Job) Needs() []string { // RunsOn list for Job func (j *Job) RunsOn() []string { - switch j.RawRunsOn.Kind { case yaml.ScalarNode: var val string @@ -183,7 +180,6 @@ func (j *Job) GetMatrixes() []map[string]interface{} { log.Debugf("Adding include '%v'", include) matrixes = append(matrixes, include) } - } else { matrixes = append(matrixes, make(map[string]interface{})) } @@ -313,12 +309,12 @@ func (s *Step) Type() StepType { } func (s *Step) Validate() error { - if s.Type() != StepTypeRun { - return fmt.Errorf("(StepID: %s): Unexpected value 'uses'", s.String()) - } else if s.Shell == "" { - return fmt.Errorf("(StepID: %s): Required property is missing: 'shell'", s.String()) - } - return nil + if s.Type() != StepTypeRun { + return fmt.Errorf("(StepID: %s): Unexpected value 'uses'", s.String()) + } else if s.Shell == "" { + return fmt.Errorf("(StepID: %s): Required property is missing: 'shell'", s.String()) + } + return nil } // ReadWorkflow returns a list of jobs for a given workflow file reader diff --git a/act/runner/expression_test.go b/act/runner/expression_test.go index d0795f4d..55ddff5e 100644 --- a/act/runner/expression_test.go +++ b/act/runner/expression_test.go @@ -199,7 +199,6 @@ func updateTestExpressionWorkflow(t *testing.T, tables []struct { in string out string }, rc *RunContext) { - var envs string keys := make([]string, 0, len(rc.Env)) for k := range rc.Env { @@ -242,7 +241,6 @@ jobs: if err != nil { t.Fatal(err) } - } func TestRewrite(t *testing.T) { diff --git a/act/runner/logger.go b/act/runner/logger.go index ff3384cc..41356627 100644 --- a/act/runner/logger.go +++ b/act/runner/logger.go @@ -109,7 +109,6 @@ func (f *stepLogFormatter) print(b *bytes.Buffer, entry *logrus.Entry) { } func (f *stepLogFormatter) isColored(entry *logrus.Entry) bool { - isColored := checkIfTerminal(entry.Logger.Out) if force, ok := os.LookupEnv("CLICOLOR_FORCE"); ok && force != "0" { diff --git a/act/runner/res/trampoline.js b/act/runner/res/trampoline.js index 8f45c662..e9a87322 100644 --- a/act/runner/res/trampoline.js +++ b/act/runner/res/trampoline.js @@ -1,14 +1,14 @@ const { spawnSync } = require('child_process') -const spawnArguments={ - cwd: process.env['INPUT_CWD'], +const spawnArguments = { + cwd: process.env.INPUT_CWD, stdio: [ process.stdin, process.stdout, - process.stderr, + process.stderr ] } -const child=spawnSync( +const child = spawnSync( '/bin/sh', - [ '-c' ].concat(process.env['INPUT_COMMAND']), + ['-c'].concat(process.env.INPUT_COMMAND), spawnArguments) process.exit(child.status) diff --git a/act/runner/run_context.go b/act/runner/run_context.go index fcd86f60..116acf79 100755 --- a/act/runner/run_context.go +++ b/act/runner/run_context.go @@ -336,7 +336,6 @@ func (rc *RunContext) EvalBool(expr string) (bool, error) { !strings.Contains(part, "!")) && // but it's not negated interpolatedPart == "false" && // and the interpolated string is false (isString || previousOrNextPartIsAnOperator(i, parts)) { // and it's of type string or has an logical operator before or after - interpolatedPart = fmt.Sprintf("'%s'", interpolatedPart) // then we have to quote the false expression } diff --git a/act/runner/run_context_test.go b/act/runner/run_context_test.go index 440619ec..78a94975 100644 --- a/act/runner/run_context_test.go +++ b/act/runner/run_context_test.go @@ -157,7 +157,6 @@ func updateTestIfWorkflow(t *testing.T, tables []struct { out bool wantErr bool }, rc *RunContext) { - var envs string keys := make([]string, 0, len(rc.Env)) for k := range rc.Env { diff --git a/act/runner/runner.go b/act/runner/runner.go index 912e2deb..388aa984 100644 --- a/act/runner/runner.go +++ b/act/runner/runner.go @@ -33,7 +33,7 @@ type Config struct { Privileged bool // use privileged mode UsernsMode string // user namespace to use ContainerArchitecture string // Desired OS/architecture platform for running containers - UseGitIgnore bool // controls if paths in .gitignore should not be copied into container, default true + UseGitIgnore bool // controls if paths in .gitignore should not be copied into container, default true } type runnerImpl struct { diff --git a/act/runner/step_context.go b/act/runner/step_context.go index 730d5eda..0ce3e821 100755 --- a/act/runner/step_context.go +++ b/act/runner/step_context.go @@ -539,7 +539,6 @@ func (sc *StepContext) runAction(actionDir string, actionPath string) common.Exe // Interpolate the outer inputs into the composite step with items exprEval := sc.NewExpressionEvaluator() for k, v := range stepContext.Step.With { - if strings.Contains(v, "inputs") { stepContext.Step.With[k] = exprEval.Interpolate(v) } diff --git a/cmd/graph.go b/cmd/graph.go index 4f8895ef..b38487be 100644 --- a/cmd/graph.go +++ b/cmd/graph.go @@ -8,7 +8,6 @@ import ( ) func drawGraph(plan *model.Plan) error { - drawings := make([]*common.Drawing, 0) jobPen := common.NewPen(common.StyleSingleLine, 96)