From b0ec3fa4fc2c3e03365a48b5dd15387953646acc Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 24 Feb 2026 08:17:17 +0100 Subject: [PATCH] fmt --- internal/eval/v2/functions.go | 24 +++++++------------ internal/model/strategy_utils_test.go | 12 ++++++---- pkg/artifacts/artifacts_v4.go | 2 -- pkg/artifacts/server.go | 5 +--- pkg/artifacts/server_test.go | 20 ++++++++-------- pkg/common/draw.go | 2 ++ pkg/common/git/git.go | 7 ++---- pkg/common/git/git_test.go | 2 +- pkg/container/docker_build.go | 3 ++- pkg/container/docker_cli.go | 6 ++--- pkg/container/docker_cli_test.go | 4 ---- pkg/container/host_environment_test.go | 18 +++++++------- .../linux_container_environment_extensions.go | 3 +-- pkg/filecollector/file_collector.go | 3 +-- pkg/lookpath/env.go | 3 +-- pkg/lookpath/lp_plan9.go | 2 +- pkg/lookpath/lp_unix.go | 2 +- pkg/model/github_context.go | 6 +++-- pkg/model/workflow.go | 2 +- pkg/model/workflow_test.go | 2 +- pkg/runner/action.go | 1 - pkg/runner/command.go | 11 +++++++-- pkg/runner/expression_test.go | 3 ++- pkg/runner/job_executor.go | 3 +-- pkg/runner/logger.go | 8 ++++--- pkg/runner/run_context.go | 2 +- pkg/runner/run_context_test.go | 3 ++- pkg/runner/runner.go | 4 +++- pkg/runner/runner_test.go | 4 ++-- pkg/runner/step.go | 2 +- pkg/runner/step_docker.go | 4 +--- pkg/schema/schema.go | 11 ++++----- pkg/tart/environment_darwin.go | 9 +++++-- pkg/tart/vm_darwin.go | 2 +- 34 files changed, 94 insertions(+), 101 deletions(-) diff --git a/internal/eval/v2/functions.go b/internal/eval/v2/functions.go index ab2bab67..4cc5235b 100644 --- a/internal/eval/v2/functions.go +++ b/internal/eval/v2/functions.go @@ -9,8 +9,7 @@ import ( exprparser "gitea.com/gitea/act_runner/internal/expr" ) -type FromJSON struct { -} +type FromJSON struct{} func (FromJSON) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResult, error) { r, err := eval.Evaluate(args[0]) @@ -25,8 +24,7 @@ func (FromJSON) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationRe return CreateIntermediateResult(eval.Context(), res), nil } -type ToJSON struct { -} +type ToJSON struct{} func (ToJSON) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResult, error) { r, err := eval.Evaluate(args[0]) @@ -44,8 +42,7 @@ func (ToJSON) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResu return CreateIntermediateResult(eval.Context(), string(data)), nil } -type Contains struct { -} +type Contains struct{} func (Contains) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResult, error) { collection, err := eval.Evaluate(args[0]) @@ -72,8 +69,7 @@ func (Contains) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationRe return CreateIntermediateResult(eval.Context(), strings.Contains(strings.ToLower(collection.ConvertToString()), strings.ToLower(el.ConvertToString()))), nil } -type StartsWith struct { -} +type StartsWith struct{} func (StartsWith) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResult, error) { collection, err := eval.Evaluate(args[0]) @@ -88,8 +84,7 @@ func (StartsWith) Evaluate(eval *Evaluator, args []exprparser.Node) (*Evaluation return CreateIntermediateResult(eval.Context(), strings.HasPrefix(strings.ToLower(collection.ConvertToString()), strings.ToLower(el.ConvertToString()))), nil } -type EndsWith struct { -} +type EndsWith struct{} func (EndsWith) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResult, error) { collection, err := eval.Evaluate(args[0]) @@ -104,8 +99,7 @@ func (EndsWith) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationRe return CreateIntermediateResult(eval.Context(), strings.HasSuffix(strings.ToLower(collection.ConvertToString()), strings.ToLower(el.ConvertToString()))), nil } -type Format struct { -} +type Format struct{} func (Format) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResult, error) { collection, err := eval.Evaluate(args[0]) @@ -126,8 +120,7 @@ func (Format) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResu return CreateIntermediateResult(eval.Context(), ret), err } -type Join struct { -} +type Join struct{} func (Join) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResult, error) { collection, err := eval.Evaluate(args[0]) @@ -164,8 +157,7 @@ func (Join) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResult return CreateIntermediateResult(eval.Context(), ""), nil } -type Case struct { -} +type Case struct{} func (Case) Evaluate(eval *Evaluator, args []exprparser.Node) (*EvaluationResult, error) { if len(args)%2 == 0 { diff --git a/internal/model/strategy_utils_test.go b/internal/model/strategy_utils_test.go index 5947b53d..34fca1ea 100644 --- a/internal/model/strategy_utils_test.go +++ b/internal/model/strategy_utils_test.go @@ -7,8 +7,7 @@ import ( "gopkg.in/yaml.v3" ) -type EmptyTraceWriter struct { -} +type EmptyTraceWriter struct{} func (e *EmptyTraceWriter) Info(_ string, _ ...any) { } @@ -28,7 +27,8 @@ matrix: - a - b `, 4, 0}, - {` + { + ` matrix: label: - a @@ -37,7 +37,8 @@ matrix: - label: a x: self`, 2, 0, }, - {` + { + ` matrix: label: - a @@ -46,7 +47,8 @@ matrix: - label: c x: self`, 2, 1, }, - {` + { + ` matrix: label: - a diff --git a/pkg/artifacts/artifacts_v4.go b/pkg/artifacts/artifacts_v4.go index 94153099..28113e2a 100644 --- a/pkg/artifacts/artifacts_v4.go +++ b/pkg/artifacts/artifacts_v4.go @@ -282,7 +282,6 @@ func (r *artifactV4Routes) createArtifact(ctx *ArtifactContext) { safePath := safeResolve(safeRunPath, artifactName) safePath = safeResolve(safePath, artifactName+".zip") file, err := r.fs.OpenWritable(safePath) - if err != nil { panic(err) } @@ -310,7 +309,6 @@ func (r *artifactV4Routes) uploadArtifact(ctx *ArtifactContext) { safePath = safeResolve(safePath, artifactName+".zip") file, err := r.fs.OpenAppendable(safePath) - if err != nil { panic(err) } diff --git a/pkg/artifacts/server.go b/pkg/artifacts/server.go index b6d65379..60a60826 100644 --- a/pkg/artifacts/server.go +++ b/pkg/artifacts/server.go @@ -55,8 +55,7 @@ type WriteFS interface { OpenAppendable(name string) (WritableFile, error) } -type readWriteFSImpl struct { -} +type readWriteFSImpl struct{} func (fwfs readWriteFSImpl) Open(name string) (fs.File, error) { return os.Open(name) @@ -74,7 +73,6 @@ func (fwfs readWriteFSImpl) OpenAppendable(name string) (WritableFile, error) { return nil, err } file, err := os.OpenFile(name, os.O_CREATE|os.O_RDWR, 0o644) - if err != nil { return nil, err } @@ -127,7 +125,6 @@ func uploads(router *httprouter.Router, baseDir string, fsys WriteFS) { } return fsys.OpenWritable(safePath) }() - if err != nil { panic(err) } diff --git a/pkg/artifacts/server_test.go b/pkg/artifacts/server_test.go index fd323938..c1063966 100644 --- a/pkg/artifacts/server_test.go +++ b/pkg/artifacts/server_test.go @@ -40,7 +40,7 @@ type writeMapFS struct { } func (fsys writeMapFS) OpenWritable(name string) (WritableFile, error) { - var file = &writableMapFile{ + file := &writableMapFile{ MapFile: fstest.MapFile{ Data: []byte("content2"), }, @@ -51,7 +51,7 @@ func (fsys writeMapFS) OpenWritable(name string) (WritableFile, error) { } func (fsys writeMapFS) OpenAppendable(name string) (WritableFile, error) { - var file = &writableMapFile{ + file := &writableMapFile{ MapFile: fstest.MapFile{ Data: []byte("content2"), }, @@ -64,7 +64,7 @@ func (fsys writeMapFS) OpenAppendable(name string) (WritableFile, error) { func TestNewArtifactUploadPrepare(t *testing.T) { assert := assert.New(t) - var memfs = fstest.MapFS(map[string]*fstest.MapFile{}) + memfs := fstest.MapFS(map[string]*fstest.MapFile{}) router := httprouter.New() uploads(router, "artifact/server/path", writeMapFS{memfs}) @@ -90,7 +90,7 @@ func TestNewArtifactUploadPrepare(t *testing.T) { func TestArtifactUploadBlob(t *testing.T) { assert := assert.New(t) - var memfs = fstest.MapFS(map[string]*fstest.MapFile{}) + memfs := fstest.MapFS(map[string]*fstest.MapFile{}) router := httprouter.New() uploads(router, "artifact/server/path", writeMapFS{memfs}) @@ -117,7 +117,7 @@ func TestArtifactUploadBlob(t *testing.T) { func TestFinalizeArtifactUpload(t *testing.T) { assert := assert.New(t) - var memfs = fstest.MapFS(map[string]*fstest.MapFile{}) + memfs := fstest.MapFS(map[string]*fstest.MapFile{}) router := httprouter.New() uploads(router, "artifact/server/path", writeMapFS{memfs}) @@ -143,7 +143,7 @@ func TestFinalizeArtifactUpload(t *testing.T) { func TestListArtifacts(t *testing.T) { assert := assert.New(t) - var memfs = fstest.MapFS(map[string]*fstest.MapFile{ + memfs := fstest.MapFS(map[string]*fstest.MapFile{ "artifact/server/path/1/file.txt": { Data: []byte(""), }, @@ -175,7 +175,7 @@ func TestListArtifacts(t *testing.T) { func TestListArtifactContainer(t *testing.T) { assert := assert.New(t) - var memfs = fstest.MapFS(map[string]*fstest.MapFile{ + memfs := fstest.MapFS(map[string]*fstest.MapFile{ "artifact/server/path/1/some/file": { Data: []byte(""), }, @@ -208,7 +208,7 @@ func TestListArtifactContainer(t *testing.T) { func TestDownloadArtifactFile(t *testing.T) { assert := assert.New(t) - var memfs = fstest.MapFS(map[string]*fstest.MapFile{ + memfs := fstest.MapFS(map[string]*fstest.MapFile{ "artifact/server/path/1/some/file": { Data: []byte("content"), }, @@ -348,7 +348,7 @@ func TestMkdirFsImplSafeResolve(t *testing.T) { func TestDownloadArtifactFileUnsafePath(t *testing.T) { assert := assert.New(t) - var memfs = fstest.MapFS(map[string]*fstest.MapFile{ + memfs := fstest.MapFS(map[string]*fstest.MapFile{ "artifact/server/path/some/file": { Data: []byte("content"), }, @@ -374,7 +374,7 @@ func TestDownloadArtifactFileUnsafePath(t *testing.T) { func TestArtifactUploadBlobUnsafePath(t *testing.T) { assert := assert.New(t) - var memfs = fstest.MapFS(map[string]*fstest.MapFile{}) + memfs := fstest.MapFS(map[string]*fstest.MapFile{}) router := httprouter.New() uploads(router, "artifact/server/path", writeMapFS{memfs}) diff --git a/pkg/common/draw.go b/pkg/common/draw.go index d11fa9fb..998a539d 100644 --- a/pkg/common/draw.go +++ b/pkg/common/draw.go @@ -72,6 +72,7 @@ func (p *Pen) drawTopBars(buf io.Writer, labels ...string) { } fmt.Fprintf(buf, "\n") } + func (p *Pen) drawBottomBars(buf io.Writer, labels ...string) { style := styleDefs[p.style] for _, label := range labels { @@ -83,6 +84,7 @@ func (p *Pen) drawBottomBars(buf io.Writer, labels ...string) { } fmt.Fprintf(buf, "\n") } + func (p *Pen) drawLabels(buf io.Writer, labels ...string) { style := styleDefs[p.style] for _, label := range labels { diff --git a/pkg/common/git/git.go b/pkg/common/git/git.go index 7ff21756..bfd4ae7f 100644 --- a/pkg/common/git/git.go +++ b/pkg/common/git/git.go @@ -62,7 +62,6 @@ func FindGitRevision(ctx context.Context, file string) (shortSha string, sha str EnableDotGitCommonDir: true, }, ) - if err != nil { logger.WithError(err).Error("path", file, "not located inside a git repository") return "", "", err @@ -96,8 +95,8 @@ func FindGitRef(ctx context.Context, file string) (string, error) { logger.Debugf("HEAD points to '%s'", ref) // Prefer the git library to iterate over the references and find a matching tag or branch. - var refTag = "" - var refBranch = "" + refTag := "" + refBranch := "" repo, err := git.PlainOpenWithOptions( file, &git.PlainOpenOptions{ @@ -105,7 +104,6 @@ func FindGitRef(ctx context.Context, file string) (string, error) { EnableDotGitCommonDir: true, }, ) - if err != nil { return "", err } @@ -144,7 +142,6 @@ func FindGitRef(ctx context.Context, file string) (string, error) { return nil }) - if err != nil { return "", err } diff --git a/pkg/common/git/git_test.go b/pkg/common/git/git_test.go index 0c952de9..be6b614e 100644 --- a/pkg/common/git/git_test.go +++ b/pkg/common/git/git_test.go @@ -19,7 +19,7 @@ import ( func TestFindGitSlug(t *testing.T) { assert := assert.New(t) - var slugTests = []struct { + slugTests := []struct { url string // input provider string // expected result slug string // expected result diff --git a/pkg/container/docker_build.go b/pkg/container/docker_build.go index fe11f695..7344bace 100644 --- a/pkg/container/docker_build.go +++ b/pkg/container/docker_build.go @@ -66,6 +66,7 @@ func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor { return err } } + func createBuildContext(ctx context.Context, contextDir string, relDockerfile string) (io.ReadCloser, error) { common.Logger(ctx).Debugf("Creating archive for build context dir '%s' with relative dockerfile '%s'", contextDir, relDockerfile) @@ -93,7 +94,7 @@ func createBuildContext(ctx context.Context, contextDir string, relDockerfile st // removed. The daemon will remove them for us, if needed, after it // parses the Dockerfile. Ignore errors here, as they will have been // caught by validateContextDirectory above. - var includes = []string{"."} + includes := []string{"."} keepThem1, _ := patternmatcher.Matches(".dockerignore", excludes) keepThem2, _ := patternmatcher.Matches(relDockerfile, excludes) if keepThem1 || keepThem2 { diff --git a/pkg/container/docker_cli.go b/pkg/container/docker_cli.go index 10c2861c..41fe510d 100644 --- a/pkg/container/docker_cli.go +++ b/pkg/container/docker_cli.go @@ -38,9 +38,7 @@ import ( "github.com/spf13/pflag" ) -var ( - deviceCgroupRuleRegexp = regexp.MustCompile(`^[acb] ([0-9]+|\*):([0-9]+|\*) [rwm]{1,3}$`) -) +var deviceCgroupRuleRegexp = regexp.MustCompile(`^[acb] ([0-9]+|\*):([0-9]+|\*) [rwm]{1,3}$`) // containerOptions is a data object with all the options for creating a container type containerOptions struct { @@ -988,7 +986,7 @@ func validateDeviceCgroupRule(val string) (string, error) { // validDeviceMode checks if the mode for device is valid or not. // Valid mode is a composition of r (read), w (write), and m (mknod). func validDeviceMode(mode string) bool { - var legalDeviceMode = map[rune]bool{ + legalDeviceMode := map[rune]bool{ 'r': true, 'w': true, 'm': true, diff --git a/pkg/container/docker_cli_test.go b/pkg/container/docker_cli_test.go index 942c229e..e02276b2 100644 --- a/pkg/container/docker_cli_test.go +++ b/pkg/container/docker_cli_test.go @@ -193,7 +193,6 @@ func TestParseRunWithInvalidArgs(t *testing.T) { //nolint:gocyclo func TestParseWithVolumes(t *testing.T) { - // A single volume arr, tryit := setupPlatformVolume([]string{`/tmp`}, []string{`c:\tmp`}) if config, hostConfig, _ := mustParse(t, tryit); hostConfig.Binds != nil { @@ -261,7 +260,6 @@ func TestParseWithVolumes(t *testing.T) { t.Fatalf("Error parsing %s. Should have a single bind mount and no volumes", arr[0]) } } - } // setupPlatformVolume takes two arrays of volume specs - a Unix style @@ -462,7 +460,6 @@ func TestParseDevice(t *testing.T) { t.Fatalf("Expected %v, got %v", deviceMapping, hostconfig.Devices) } } - } func TestParseNetworkConfig(t *testing.T) { @@ -967,7 +964,6 @@ func TestConvertToStandardNotation(t *testing.T) { for key, ports := range valid { convertedPorts, err := convertToStandardNotation(ports) - if err != nil { assert.NilError(t, err) } diff --git a/pkg/container/host_environment_test.go b/pkg/container/host_environment_test.go index 035f206a..4ca2b928 100644 --- a/pkg/container/host_environment_test.go +++ b/pkg/container/host_environment_test.go @@ -27,10 +27,10 @@ func TestCopyDir(t *testing.T) { StdOut: os.Stdout, Workdir: path.Join("testdata", "scratch"), } - _ = os.MkdirAll(e.Path, 0700) - _ = os.MkdirAll(e.TmpDir, 0700) - _ = os.MkdirAll(e.ToolCache, 0700) - _ = os.MkdirAll(e.ActPath, 0700) + _ = os.MkdirAll(e.Path, 0o700) + _ = os.MkdirAll(e.TmpDir, 0o700) + _ = os.MkdirAll(e.ToolCache, 0o700) + _ = os.MkdirAll(e.ActPath, 0o700) err := e.CopyDir(e.Workdir, e.Path, true)(ctx) require.NoError(t, err) } @@ -47,12 +47,12 @@ func TestGetContainerArchive(t *testing.T) { StdOut: os.Stdout, Workdir: path.Join("testdata", "scratch"), } - _ = os.MkdirAll(e.Path, 0700) - _ = os.MkdirAll(e.TmpDir, 0700) - _ = os.MkdirAll(e.ToolCache, 0700) - _ = os.MkdirAll(e.ActPath, 0700) + _ = os.MkdirAll(e.Path, 0o700) + _ = os.MkdirAll(e.TmpDir, 0o700) + _ = os.MkdirAll(e.ToolCache, 0o700) + _ = os.MkdirAll(e.ActPath, 0o700) expectedContent := []byte("sdde/7sh") - err := os.WriteFile(filepath.Join(e.Path, "action.yml"), expectedContent, 0600) + err := os.WriteFile(filepath.Join(e.Path, "action.yml"), expectedContent, 0o600) require.NoError(t, err) archive, err := e.GetContainerArchive(ctx, e.Path) require.NoError(t, err) diff --git a/pkg/container/linux_container_environment_extensions.go b/pkg/container/linux_container_environment_extensions.go index 667300a1..76a41c8a 100644 --- a/pkg/container/linux_container_environment_extensions.go +++ b/pkg/container/linux_container_environment_extensions.go @@ -10,8 +10,7 @@ import ( log "github.com/sirupsen/logrus" ) -type LinuxContainerEnvironmentExtensions struct { -} +type LinuxContainerEnvironmentExtensions struct{} // Resolves the equivalent host path inside the container // This is required for windows and WSL 2 to translate things like C:\Users\Myproject to /mnt/users/Myproject diff --git a/pkg/filecollector/file_collector.go b/pkg/filecollector/file_collector.go index adb14459..c67de986 100644 --- a/pkg/filecollector/file_collector.go +++ b/pkg/filecollector/file_collector.go @@ -98,8 +98,7 @@ type Fs interface { Readlink(path string) (string, error) } -type DefaultFs struct { -} +type DefaultFs struct{} func (*DefaultFs) Walk(root string, fn filepath.WalkFunc) error { return filepath.Walk(root, fn) diff --git a/pkg/lookpath/env.go b/pkg/lookpath/env.go index 5e2bb559..eb554fcc 100644 --- a/pkg/lookpath/env.go +++ b/pkg/lookpath/env.go @@ -9,8 +9,7 @@ type Env interface { Getenv(name string) string } -type defaultEnv struct { -} +type defaultEnv struct{} func (*defaultEnv) Getenv(name string) string { return os.Getenv(name) diff --git a/pkg/lookpath/lp_plan9.go b/pkg/lookpath/lp_plan9.go index a201b715..18db2d88 100644 --- a/pkg/lookpath/lp_plan9.go +++ b/pkg/lookpath/lp_plan9.go @@ -20,7 +20,7 @@ func findExecutable(file string) error { if err != nil { return err } - if m := d.Mode(); !m.IsDir() && m&0111 != 0 { + if m := d.Mode(); !m.IsDir() && m&0o111 != 0 { return nil } return fs.ErrPermission diff --git a/pkg/lookpath/lp_unix.go b/pkg/lookpath/lp_unix.go index 233e21f9..f8bc60c5 100644 --- a/pkg/lookpath/lp_unix.go +++ b/pkg/lookpath/lp_unix.go @@ -22,7 +22,7 @@ func findExecutable(file string) error { if err != nil { return err } - if m := d.Mode(); !m.IsDir() && m&0111 != 0 { + if m := d.Mode(); !m.IsDir() && m&0o111 != 0 { return nil } return fs.ErrPermission diff --git a/pkg/model/github_context.go b/pkg/model/github_context.go index 135940c3..b1a2321a 100644 --- a/pkg/model/github_context.go +++ b/pkg/model/github_context.go @@ -91,8 +91,10 @@ func withDefaultBranch(ctx context.Context, b string, event map[string]any) map[ return event } -var findGitRef = git.FindGitRef -var findGitRevision = git.FindGitRevision +var ( + findGitRef = git.FindGitRef + findGitRevision = git.FindGitRevision +) func (ghc *GithubContext) SetRef(ctx context.Context, defaultBranch string, repoPath string) { logger := common.Logger(ctx) diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 4f709d83..14b5108a 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -612,7 +612,7 @@ func (s *Step) GetEnv() map[string]string { func (s *Step) ShellCommand() string { var shellCommand string - //Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17 + // Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17 switch s.Shell { case "": shellCommand = "bash -e {0}" diff --git a/pkg/model/workflow_test.go b/pkg/model/workflow_test.go index 18001ff5..5e4bb6f8 100644 --- a/pkg/model/workflow_test.go +++ b/pkg/model/workflow_test.go @@ -395,7 +395,7 @@ func TestReadWorkflow_Strategy(t *testing.T) { func TestMatrixOnlyIncludes(t *testing.T) { matrix := map[string][]any{ - "include": []any{ + "include": { map[string]any{"a": "1", "b": "2"}, map[string]any{"a": "3", "b": "4"}, }, diff --git a/pkg/runner/action.go b/pkg/runner/action.go index f773fecb..0d24c812 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -216,7 +216,6 @@ func execAsDocker(ctx context.Context, step actionStep, actionName, subpath stri if len(entrypoint) == 0 { if entrypointType == "pre-entrypoint" && action.Runs.PreEntrypoint != "" { entrypoint, err = shellquote.Split(action.Runs.PreEntrypoint) - if err != nil { return err } diff --git a/pkg/runner/command.go b/pkg/runner/command.go index 41a32fa5..5c178b1d 100644 --- a/pkg/runner/command.go +++ b/pkg/runner/command.go @@ -9,8 +9,10 @@ import ( "github.com/sirupsen/logrus" ) -var commandPatternGA *regexp.Regexp -var commandPatternADO *regexp.Regexp +var ( + commandPatternGA *regexp.Regexp + commandPatternADO *regexp.Regexp +) func init() { commandPatternGA = regexp.MustCompile("^::([^ ]+)( (.+))?::([^\r\n]*)[\r\n]+$") @@ -102,6 +104,7 @@ func (rc *RunContext) setEnv(ctx context.Context, kvPairs map[string]string, arg mergeIntoMap(rc.Env, newenv) mergeIntoMap(rc.GlobalEnv, newenv) } + func (rc *RunContext) setOutput(ctx context.Context, kvPairs map[string]string, arg string) { logger := common.Logger(ctx) stepID := rc.CurrentStep @@ -120,6 +123,7 @@ func (rc *RunContext) setOutput(ctx context.Context, kvPairs map[string]string, logger.WithFields(logrus.Fields{"command": "set-output", "name": outputName, "arg": arg}).Infof(" \U00002699 ::set-output:: %s=%s", outputName, arg) result.Outputs[outputName] = arg } + func (rc *RunContext) addPath(ctx context.Context, arg string) { common.Logger(ctx).WithFields(logrus.Fields{"command": "add-path", "arg": arg}).Infof(" \U00002699 ::add-path:: %s", arg) extraPath := []string{arg} @@ -142,6 +146,7 @@ func parseKeyValuePairs(kvPairs string, separator string) map[string]string { } return rtn } + func unescapeCommandData(arg string) string { escapeMap := map[string]string{ "%25": "%", @@ -153,6 +158,7 @@ func unescapeCommandData(arg string) string { } return arg } + func unescapeCommandProperty(arg string) string { escapeMap := map[string]string{ "%25": "%", @@ -166,6 +172,7 @@ func unescapeCommandProperty(arg string) string { } return arg } + func unescapeKvPairs(kvPairs map[string]string) map[string]string { for k, v := range kvPairs { kvPairs[k] = unescapeCommandProperty(v) diff --git a/pkg/runner/expression_test.go b/pkg/runner/expression_test.go index cb55242a..49875673 100644 --- a/pkg/runner/expression_test.go +++ b/pkg/runner/expression_test.go @@ -276,7 +276,8 @@ func TestInterpolate(t *testing.T) { func updateTestExpressionWorkflow(t *testing.T, tables []struct { in string out string -}, rc *RunContext) { +}, rc *RunContext, +) { var envs string keys := make([]string, 0, len(rc.Env)) for k := range rc.Env { diff --git a/pkg/runner/job_executor.go b/pkg/runner/job_executor.go index c0086151..4806fa22 100644 --- a/pkg/runner/job_executor.go +++ b/pkg/runner/job_executor.go @@ -54,7 +54,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo return nil }) - var setJobError = func(ctx context.Context, err error) error { + setJobError := func(ctx context.Context, err error) error { if err == nil { return nil } @@ -75,7 +75,6 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo } step, err := sf.newStep(stepModel, rc) - if err != nil { return common.NewErrorExecutor(err) } diff --git a/pkg/runner/logger.go b/pkg/runner/logger.go index 156a9bb9..229e7f9c 100644 --- a/pkg/runner/logger.go +++ b/pkg/runner/logger.go @@ -26,9 +26,11 @@ const ( gray = 37 ) -var colors []int -var nextColor int -var mux sync.Mutex +var ( + colors []int + nextColor int + mux sync.Mutex +) func init() { nextColor = 0 diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 127bf6cf..b6f58067 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -757,7 +757,7 @@ func (rc *RunContext) steps() []*model.Step { // Executor returns a pipeline executor for all the steps in the job func (rc *RunContext) Executor() (common.Executor, error) { var executor common.Executor - var jobType, err = rc.Run.Job().Type() + jobType, err := rc.Run.Job().Type() if exec, ok := rc.Config.CustomExecutor[jobType]; ok { executor = exec(rc) diff --git a/pkg/runner/run_context_test.go b/pkg/runner/run_context_test.go index b8d0125e..cadb53b3 100644 --- a/pkg/runner/run_context_test.go +++ b/pkg/runner/run_context_test.go @@ -172,7 +172,8 @@ func updateTestIfWorkflow(t *testing.T, tables []struct { in string out bool wantErr bool -}, rc *RunContext) { +}, rc *RunContext, +) { var envs string keys := make([]string, 0, len(rc.Env)) for k := range rc.Env { diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 9ba86df2..3e3a0d42 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -84,6 +84,7 @@ func (runnerConfig *Config) GetGitHubServerURL() string { } return "https://" + runnerConfig.GitHubInstance } + func (runnerConfig *Config) GetGitHubAPIServerURL() string { if len(runnerConfig.GitHubAPIServerURL) > 0 { return runnerConfig.GitHubAPIServerURL @@ -93,6 +94,7 @@ func (runnerConfig *Config) GetGitHubAPIServerURL() string { } return fmt.Sprintf("https://%s/api/v3", runnerConfig.GitHubInstance) } + func (runnerConfig *Config) GetGitHubGraphQlAPIServerURL() string { if len(runnerConfig.GitHubGraphQlAPIServerURL) > 0 { return runnerConfig.GitHubGraphQlAPIServerURL @@ -102,6 +104,7 @@ func (runnerConfig *Config) GetGitHubGraphQlAPIServerURL() string { } return fmt.Sprintf("https://%s/api/graphql", runnerConfig.GitHubInstance) } + func (runnerConfig *Config) GetGitHubInstance() string { if len(runnerConfig.GitHubServerURL) > 0 { regex := regexp.MustCompile("^https?://(.*)$") @@ -234,7 +237,6 @@ func (runner *runnerImpl) NewPlanExecutor(plan *model.Plan) common.Executor { stageExecutor = append(stageExecutor, func(ctx context.Context) error { jobName := fmt.Sprintf("%-*s", maxJobNameLen, rc.String()) executor, err := rc.Executor() - if err != nil { return err } diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index a3900edf..0a93e260 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -453,8 +453,7 @@ func TestPullAndPostStepFailureIsJobFailure(t *testing.T) { } } -type mockCache struct { -} +type mockCache struct{} func (c mockCache) Fetch(ctx context.Context, cacheDir string, url string, ref string, token string) (string, error) { _ = ctx @@ -464,6 +463,7 @@ func (c mockCache) Fetch(ctx context.Context, cacheDir string, url string, ref s _ = token return "", errors.New("fetch failure") } + func (c mockCache) GetTarArchive(ctx context.Context, cacheDir string, sha string, includePrefix string) (io.ReadCloser, error) { _ = ctx _ = cacheDir diff --git a/pkg/runner/step.go b/pkg/runner/step.go index 6be25e66..68ae3cba 100644 --- a/pkg/runner/step.go +++ b/pkg/runner/step.go @@ -164,7 +164,7 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo Mode: 0o666, }, &container.FileEntry{ Name: envFileCommand, - Mode: 0666, + Mode: 0o666, }, &container.FileEntry{ Name: summaryFileCommand, Mode: 0o666, diff --git a/pkg/runner/step_docker.go b/pkg/runner/step_docker.go index 70d773b1..8e2bbad1 100644 --- a/pkg/runner/step_docker.go +++ b/pkg/runner/step_docker.go @@ -85,9 +85,7 @@ func (sd *stepDocker) runUsesContainer() common.Executor { } } -var ( - ContainerNewContainer = container.NewContainer -) +var ContainerNewContainer = container.NewContainer func (sd *stepDocker) newStepContainer(ctx context.Context, image string, cmd []string, entrypoint []string) container.Container { rc := sd.RunContext diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 76a6abcf..4ed63da1 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -171,14 +171,11 @@ type StringDefinition struct { IsExpression bool `json:"is-expression,omitempty"` } -type NumberDefinition struct { -} +type NumberDefinition struct{} -type BooleanDefinition struct { -} +type BooleanDefinition struct{} -type NullDefinition struct { -} +type NullDefinition struct{} func GetWorkflowSchema() *Schema { sh := &Schema{} @@ -462,7 +459,7 @@ func (s *Node) checkString(node *yaml.Node, def Definition) error { } func (s *Node) checkOneOf(def Definition, node *yaml.Node) error { - var invalidProps = math.MaxInt + invalidProps := math.MaxInt var bestMatches ValidationErrorCollection for _, v := range *def.OneOf { // Use helper to create child node diff --git a/pkg/tart/environment_darwin.go b/pkg/tart/environment_darwin.go index c9b02f9e..cda8196b 100644 --- a/pkg/tart/environment_darwin.go +++ b/pkg/tart/environment_darwin.go @@ -100,8 +100,8 @@ func (e *Environment) start(ctx context.Context) error { return err } var customDirectoryMounts []string - _ = os.MkdirAll(e.Miscpath, 0777) - _ = os.MkdirAll(e.ToolCache, 0777) + _ = os.MkdirAll(e.Miscpath, 0o777) + _ = os.MkdirAll(e.ToolCache, 0o777) customDirectoryMounts = append(customDirectoryMounts, "act:"+e.Miscpath) customDirectoryMounts = append(customDirectoryMounts, "tool_cache:"+e.ToolCache) e.vm = vm @@ -113,6 +113,7 @@ func (e *Environment) start(ctx context.Context) error { return e.execRaw(ctx, "ln -sf '/Volumes/My Shared Files/act' /private/tmp/act && ln -sf '/Volumes/My Shared Files/tool_cache' /private/tmp/tool_cache") } + func (e *Environment) Stop(ctx context.Context) error { common.Logger(ctx).Debug("Preparing stopping VM") @@ -149,6 +150,7 @@ func (e *Environment) Remove() common.Executor { return e.Close()(ctx) } } + func (e *Environment) exec(ctx context.Context, command []string, _ string, env map[string]string, _, workdir string) error { var wd string if workdir != "" { @@ -216,12 +218,15 @@ func (e *Environment) GetActPath() string { func (e *Environment) Copy(destPath string, files ...*container.FileEntry) common.Executor { return e.HostEnvironment.Copy(e.ToHostPath(destPath), files...) } + func (e *Environment) CopyTarStream(ctx context.Context, destPath string, tarStream io.Reader) error { return e.HostEnvironment.CopyTarStream(ctx, e.ToHostPath(destPath), tarStream) } + func (e *Environment) CopyDir(destPath string, srcPath string, useGitIgnore bool) common.Executor { return e.HostEnvironment.CopyDir(e.ToHostPath(destPath), srcPath, useGitIgnore) } + func (e *Environment) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) { return e.HostEnvironment.GetContainerArchive(ctx, e.ToHostPath(srcPath)) } diff --git a/pkg/tart/vm_darwin.go b/pkg/tart/vm_darwin.go index 0a15520b..4a4e0010 100644 --- a/pkg/tart/vm_darwin.go +++ b/pkg/tart/vm_darwin.go @@ -85,7 +85,7 @@ func (vm *VM) cloneAndConfigure( func (vm *VM) Start(ctx context.Context, config Config, _ *Env, customDirectoryMounts []string) error { os.Remove(vm.tartRunOutputPath()) - var runArgs = []string{"run"} + runArgs := []string{"run"} if config.Softnet { runArgs = append(runArgs, "--net-softnet")