cspell lint go code (#3706)

This commit is contained in:
6543 2024-05-24 22:35:04 +02:00 committed by GitHub
parent 4628a97c93
commit 42f2734308
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 214 additions and 161 deletions

View file

@ -1,7 +1,17 @@
{
"version": "0.2",
"language": "en",
"dictionaries": [
// language
"en_us",
// code
"go",
"node",
// package names
"npm"
],
"words": [
"abool",
"BUILDPLATFORM",
"Codeberg",
"Curr",
@ -21,35 +31,40 @@
"Ionescu",
"Kaniko",
"Keyfunc",
"LASTEXITCODE",
"Laszlo",
"Msgf",
"Netrc",
"PROTOC",
"Pinia",
"Println",
"pwsh",
"Refspec",
"Reviewdog",
"Rydzewski",
"SSHURL",
"TARGETARCH",
"TARGETOS",
"Typeflag",
"Upsert",
"WORKDIR",
"Warnf",
"Weblate",
"Wrapf",
"anbraten",
"apimachinery",
"autoincr",
"autoscaler",
"binutils",
"bitbucketdatacenter",
"bradrydzewski",
"brightbox",
"buildx",
"ccmenu",
"charmbracelet",
"ciphertext",
"compatiblelicenses",
"corepack",
"cpuset",
"creativecommons",
"datacenter",
"desaturate",
@ -57,11 +72,14 @@
"doublestar",
"envsubst",
"estree",
"errgroup",
"evenodd",
"excalidraw",
"favicons",
"forbidigo",
"fsnotify",
"gitea",
"gocritic",
"golangci",
"gomod",
"gonic",
@ -73,7 +91,10 @@
"laszlocph",
"logfile",
"loglevel",
"mapstructure",
"markdownlint",
"memswap",
"moby",
"multiarch",
"multierr",
"netdns",
@ -86,24 +107,37 @@
"ppid",
"prismjs",
"proto",
"protobuf",
"protoc",
"protoimpl",
"protoreflect",
"rawurl",
"regcred",
"repology",
"reslimit",
"riscv",
"rundll32",
"seccomp",
"secprofile",
"securecookie",
"sess",
"shellescape",
"stepbuilder",
"stretchr",
"sublicensable",
"swaggo",
"techknowlogick",
"testdata",
"tink",
"tinycolor",
"tmpfs",
"tmpl",
"tolerations",
"ttlcache",
"typecheck",
"unplugin",
"urfave",
"varchar",
"vite",
"vitejs",
"vueuse",
"waivable",
"windi",
@ -112,6 +146,7 @@
"xlog",
"xorm",
"xormigrate",
"xyaml",
"zerolog",
"zerologger"
],
@ -119,6 +154,7 @@
"**/node_modules/**/*",
"*.excalidraw",
"*.svg",
"*_test.go",
".cspell.json",
".git/**/*",
".gitignore",
@ -130,18 +166,29 @@
"flake.nix",
"go.mod",
"go.sum",
"pipeline/rpc/proto/woodpecker.pb.go",
"pnpm-lock.yaml",
"server/store/datastore/migration/**/*",
"web/components.d.ts",
"web/src/assets/locales/**/*",
"**/fixtures/**",
"**/testdata/**",
// TODO: remove the following
".woodpecker/",
"agent/",
"cli/",
"cmd/",
"docs/",
"pipeline/",
"server/"
],
// Exclude imports, because they are also strings.
"ignoreRegExpList": [
// ignore mulltiline imports
"import\\s*\\((.|[\r\n])*?\\)",
// ignore single line imports
"import\\s*.*\".*?\"",
// ignore go generate directive
"//\\s*go:generate.*",
// ignore nolint directive
"//\\s*nolint:.*",
// ignore docker image names
"\\s*docker\\.io/.*"
],
"enableFiletypes": ["dockercompose"]
}

View file

@ -6,6 +6,8 @@ variables:
- &node_image 'docker.io/node:22-alpine'
- &xgo_image 'docker.io/techknowlogick/xgo:go-1.22.x'
# cspell:words bindata netgo TARGZ
steps:
build-web:
image: *node_image

View file

@ -9,6 +9,8 @@ variables:
- &platforms_alpine 'linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le'
- &build_args 'CI_COMMIT_SHA=${CI_COMMIT_SHA},CI_COMMIT_BRANCH=${CI_COMMIT_BRANCH},CI_COMMIT_TAG=${CI_COMMIT_TAG}'
# cspell:words woodpeckerbot netgo TARGZ
# vars used on push / tag events only
- publish_logins: &publish_logins # Default DockerHub login
- registry: https://index.docker.io/v1/
@ -96,7 +98,7 @@ steps:
- make cross-compile-server
environment:
PLATFORMS: linux|amd64
TAGS: bindata sqlite sqlite_unlock_notify netgo
TAGS: sqlite sqlite_unlock_notify netgo
when:
- event: pull_request
evaluate: 'CI_COMMIT_PULL_REQUEST_LABELS contains "build_pr_images"'
@ -118,7 +120,7 @@ steps:
- make cross-compile-server
environment:
PLATFORMS: linux|arm/v7;linux|arm64/v8;linux|amd64;linux|ppc64le;linux|riscv64
TAGS: bindata sqlite sqlite_unlock_notify netgo
TAGS: sqlite sqlite_unlock_notify netgo
when:
branch:
- ${CI_REPO_DEFAULT_BRANCH}

View file

@ -6,8 +6,7 @@ when:
- renovate/*
variables:
- &trivy_image aquasec/trivy:0.46.1
- &trivy_plugin woodpeckerci/plugin-trivy:1.0.1
- &trivy_plugin docker.io/woodpeckerci/plugin-trivy:1.0.1
steps:
backend:
@ -22,7 +21,7 @@ steps:
settings:
skip-dirs: node_modules/,plugins/woodpecker-plugins/node_modules/
dir: docs/
# well we should check it, but we can not do much about old deps if docusaurus do not take that serously
# well we should check it, but we can not do much about old deps if docusaurus do not take that seriously
# but this is not an issue as we just generate a static site anyway ...
failure: ignore

View file

@ -18,7 +18,8 @@ steps:
commands:
- corepack enable
- pnpx cspell lint --no-progress --gitignore '{**,.*}/{*,.*}'
- apk add --no-cache -U tree # busybox tree dont understand "-I"
- apk add --no-cache -U tree # busybox tree don't understand "-I"
# cspell:disable-next-line
- tree --gitignore -I 012_columns_rename_procs_to_steps.go -I versioned_docs -I '*opensource.svg'| pnpx cspell lint --no-progress stdin
- name: prettier
@ -28,7 +29,7 @@ steps:
version: 3.2.5
- name: links
image: lycheeverse/lychee:0.14.3
image: docker.io/lycheeverse/lychee:0.14.3
depends_on: []
commands:
- lychee pipeline/frontend/yaml/linter/schema/schema.json

View file

@ -74,7 +74,7 @@ steps:
lint-license-header:
image: *golang_image
commands:
- go install github.com/google/addlicense@latest
- go install github.com/google/addlicense@latest # cspell:words addlicense
- 'addlicense -check -ignore "vendor/**" **/*.go'
when: *when
@ -107,7 +107,7 @@ steps:
image: *golang_image
environment:
WOODPECKER_DATABASE_DRIVER: postgres
WOODPECKER_DATABASE_DATASOURCE: 'host=postgres user=postgres dbname=postgres sslmode=disable'
WOODPECKER_DATABASE_DATASOURCE: 'host=postgres user=postgres dbname=postgres sslmode=disable' # cspell:disable-line
commands:
- make test-server-datastore
when: *when

View file

@ -35,7 +35,7 @@ steps:
- pnpm lint
when: *when
formatcheck:
format-check:
depends_on:
- install-dependencies
image: *node_image

View file

@ -28,7 +28,7 @@ import (
func (r *Runner) createLogger(logger zerolog.Logger, uploads *sync.WaitGroup, workflow *rpc.Workflow) pipeline.Logger {
return func(step *backend.Step, rc io.Reader) error {
loglogger := logger.With().
logLogger := logger.With().
Str("image", step.Image).
Str("workflowID", workflow.ID).
Logger()
@ -40,14 +40,14 @@ func (r *Runner) createLogger(logger zerolog.Logger, uploads *sync.WaitGroup, wo
secrets = append(secrets, secret.Value)
}
loglogger.Debug().Msg("log stream opened")
logLogger.Debug().Msg("log stream opened")
logStream := rpc.NewLineWriter(r.client, step.UUID, secrets...)
if _, err := io.Copy(logStream, rc); err != nil {
log.Error().Err(err).Msg("copy limited logStream part")
}
loglogger.Debug().Msg("log stream copied, close ...")
logLogger.Debug().Msg("log stream copied, close ...")
uploads.Done()
return nil

View file

@ -54,7 +54,7 @@ func (r *Runner) Run(runnerCtx context.Context) error { //nolint:contextcheck
log.Debug().Msg("request next execution")
meta, _ := metadata.FromOutgoingContext(runnerCtx)
ctxmeta := metadata.NewOutgoingContext(context.Background(), meta)
ctxMeta := metadata.NewOutgoingContext(context.Background(), meta)
// get the next workflow from the queue
work, err := r.client.Next(runnerCtx, r.filter)
@ -89,7 +89,7 @@ func (r *Runner) Run(runnerCtx context.Context) error { //nolint:contextcheck
logger.Debug().Msg("received execution")
workflowCtx, cancel := context.WithTimeout(ctxmeta, timeout)
workflowCtx, cancel := context.WithTimeout(ctxMeta, timeout)
defer cancel()
// Add sigterm support for internal context.
@ -103,9 +103,9 @@ func (r *Runner) Run(runnerCtx context.Context) error { //nolint:contextcheck
go func() {
logger.Debug().Msg("listen for cancel signal")
if werr := r.client.Wait(workflowCtx, work.ID); werr != nil {
if err := r.client.Wait(workflowCtx, work.ID); err != nil {
canceled.SetTo(true)
logger.Warn().Err(werr).Msg("cancel signal received")
logger.Warn().Err(err).Msg("cancel signal received")
cancel()
} else {
@ -144,7 +144,7 @@ func (r *Runner) Run(runnerCtx context.Context) error { //nolint:contextcheck
pipeline.WithContext(workflowCtx),
pipeline.WithTaskUUID(fmt.Sprint(work.ID)),
pipeline.WithLogger(r.createLogger(logger, &uploads, work)),
pipeline.WithTracer(r.createTracer(ctxmeta, logger, work)),
pipeline.WithTracer(r.createTracer(ctxMeta, logger, work)),
pipeline.WithBackend(*r.backend),
pipeline.WithDescription(map[string]string{
"ID": work.ID,

View file

@ -26,9 +26,9 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/pipeline/rpc"
)
func (r *Runner) createTracer(ctxmeta context.Context, logger zerolog.Logger, workflow *rpc.Workflow) pipeline.TraceFunc {
func (r *Runner) createTracer(ctxMeta context.Context, logger zerolog.Logger, workflow *rpc.Workflow) pipeline.TraceFunc {
return func(state *pipeline.State) error {
steplogger := logger.With().
stepLogger := logger.With().
Str("image", state.Pipeline.Step.Image).
Str("workflowID", workflow.ID).
Err(state.Process.Error).
@ -48,15 +48,15 @@ func (r *Runner) createTracer(ctxmeta context.Context, logger zerolog.Logger, wo
}
defer func() {
steplogger.Debug().Msg("update step status")
stepLogger.Debug().Msg("update step status")
if uerr := r.client.Update(ctxmeta, workflow.ID, stepState); uerr != nil {
steplogger.Debug().
Err(uerr).
if err := r.client.Update(ctxMeta, workflow.ID, stepState); err != nil {
stepLogger.Debug().
Err(err).
Msg("update step status error")
}
steplogger.Debug().Msg("update step status complete")
stepLogger.Debug().Msg("update step status complete")
}()
if state.Process.Exited {
return nil

View file

@ -78,9 +78,9 @@ func deploy(c *cli.Context) error {
var number int64
if pipelineArg == "last" {
// Fetch the pipeline number from the last pipeline
pipelines, berr := client.PipelineList(repoID)
if berr != nil {
return berr
pipelines, err := client.PipelineList(repoID)
if err != nil {
return err
}
for _, pipeline := range pipelines {
if branch != "" && pipeline.Branch != branch {

View file

@ -146,14 +146,14 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
if err != nil {
return err
}
confstr, err := tmpl.Execute(func(name string) string {
confStr, err := tmpl.Execute(func(name string) string {
return environ[name]
})
if err != nil {
return err
}
conf, err := yaml.ParseString(confstr)
conf, err := yaml.ParseString(confStr)
if err != nil {
return err
}
@ -177,12 +177,12 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
}
// lint the yaml file
if lerr := linter.New(linter.WithTrusted(true)).Lint([]*linter.WorkflowConfig{{
if err := linter.New(linter.WithTrusted(true)).Lint([]*linter.WorkflowConfig{{
File: path.Base(file),
RawConfig: confstr,
RawConfig: confStr,
Workflow: conf,
}}); lerr != nil {
return lerr
}}); err != nil {
return err
}
// compiles the yaml file

View file

@ -35,7 +35,7 @@ func NewClient(c *cli.Context) (woodpecker.Client, error) {
var (
skip = c.Bool("skip-verify")
socks = c.String("socks-proxy")
socksoff = c.Bool("socks-proxy-off")
socksOff = c.Bool("socks-proxy-off")
token = c.String("token")
server = c.String("server")
)
@ -70,7 +70,7 @@ func NewClient(c *cli.Context) (woodpecker.Client, error) {
trans, _ := client.Transport.(*oauth2.Transport)
if len(socks) != 0 && !socksoff {
if len(socks) != 0 && !socksOff {
dialer, err := proxy.SOCKS5("tcp", socks, nil, proxy.Direct)
if err != nil {
return nil, err

View file

@ -22,7 +22,7 @@ import (
"path/filepath"
"strings"
"github.com/muesli/termenv"
term_env "github.com/muesli/termenv"
"github.com/urfave/cli/v2"
"go.woodpecker-ci.org/woodpecker/v2/cli/common"
@ -72,7 +72,7 @@ func lintDir(c *cli.Context, dir string) error {
}
func lintFile(_ *cli.Context, file string) error {
output := termenv.NewOutput(os.Stdout)
output := term_env.NewOutput(os.Stdout)
fi, err := os.Open(file)
if err != nil {

View file

@ -64,7 +64,7 @@ func (o *Table) AddFieldFn(field string, fn FieldFn) *Table {
return o
}
// AddAllowedFields reads all first level fieldnames of the struct and allows them to be used.
// AddAllowedFields reads all first level field names of the struct and allows them to be used.
func (o *Table) AddAllowedFields(obj any) (*Table, error) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Struct {

View file

@ -47,7 +47,7 @@ var Command = &cli.Command{
}
func pipelineOutput(c *cli.Context, resources []woodpecker.Pipeline, fd ...io.Writer) error {
outfmt, outopt := output.ParseOutputOptions(c.String("output"))
outFmt, outOpt := output.ParseOutputOptions(c.String("output"))
noHeader := c.Bool("output-no-headers")
var out io.Writer
@ -60,13 +60,13 @@ func pipelineOutput(c *cli.Context, resources []woodpecker.Pipeline, fd ...io.Wr
out = os.Stdout
}
switch outfmt {
switch outFmt {
case "go-template":
if len(outopt) < 1 {
if len(outOpt) < 1 {
return fmt.Errorf("%w: missing template", output.ErrOutputOptionRequired)
}
tmpl, err := template.New("_").Parse(outopt[0] + "\n")
tmpl, err := template.New("_").Parse(outOpt[0] + "\n")
if err != nil {
return err
}
@ -79,8 +79,8 @@ func pipelineOutput(c *cli.Context, resources []woodpecker.Pipeline, fd ...io.Wr
table := output.NewTable(out)
cols := []string{"Number", "Status", "Event", "Branch", "Commit", "Author"}
if len(outopt) > 0 {
cols = outopt
if len(outOpt) > 0 {
cols = outOpt
}
if !noHeader {
table.WriteHeader(cols)

View file

@ -73,14 +73,13 @@ func registryCreate(c *cli.Context) error {
}
if strings.HasPrefix(registry.Password, "@") {
path := strings.TrimPrefix(registry.Password, "@")
out, ferr := os.ReadFile(path)
if ferr != nil {
return ferr
out, err := os.ReadFile(path)
if err != nil {
return err
}
registry.Password = string(out)
}
_, err = client.RegistryCreate(repoID, registry)
if err != nil {
if _, err := client.RegistryCreate(repoID, registry); err != nil {
return err
}
return nil

View file

@ -73,9 +73,9 @@ func registryUpdate(c *cli.Context) error {
}
if strings.HasPrefix(registry.Password, "@") {
path := strings.TrimPrefix(registry.Password, "@")
out, ferr := os.ReadFile(path)
if ferr != nil {
return ferr
out, err := os.ReadFile(path)
if err != nil {
return err
}
registry.Password = string(out)
}

View file

@ -11,7 +11,7 @@ import (
const tarDirectoryMode fs.FileMode = 0x755
func Untar(dst string, r io.Reader) error {
func UnTar(dst string, r io.Reader) error {
gzr, err := gzip.NewReader(r)
if err != nil {
return err

View file

@ -122,7 +122,7 @@ func extractNewVersion(tarFilePath string) (string, error) {
return "", err
}
err = Untar(tmpDir, tarFile)
err = UnTar(tmpDir, tarFile)
if err != nil {
return "", err
}

View file

@ -31,14 +31,14 @@ import (
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
grpccredentials "google.golang.org/grpc/credentials"
grpc_credentials "google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"go.woodpecker-ci.org/woodpecker/v2/agent"
agentRpc "go.woodpecker-ci.org/woodpecker/v2/agent/rpc"
agent_rpc "go.woodpecker-ci.org/woodpecker/v2/agent/rpc"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/rpc"
@ -67,7 +67,7 @@ func run(c *cli.Context, backends []types.Backend) error {
var transport grpc.DialOption
if c.Bool("grpc-secure") {
transport = grpc.WithTransportCredentials(grpccredentials.NewTLS(&tls.Config{InsecureSkipVerify: c.Bool("grpc-skip-insecure")}))
transport = grpc.WithTransportCredentials(grpc_credentials.NewTLS(&tls.Config{InsecureSkipVerify: c.Bool("grpc-skip-insecure")}))
} else {
transport = grpc.WithTransportCredentials(insecure.NewCredentials())
}
@ -88,8 +88,8 @@ func run(c *cli.Context, backends []types.Backend) error {
agentConfig := readAgentConfig(agentConfigPath)
agentToken := c.String("grpc-token")
authClient := agentRpc.NewAuthGrpcClient(authConn, agentToken, agentConfig.AgentID)
authInterceptor, err := agentRpc.NewAuthInterceptor(authClient, 30*time.Minute) //nolint:mnd
authClient := agent_rpc.NewAuthGrpcClient(authConn, agentToken, agentConfig.AgentID)
authInterceptor, err := agent_rpc.NewAuthInterceptor(authClient, 30*time.Minute) //nolint:mnd
if err != nil {
return err
}
@ -109,7 +109,7 @@ func run(c *cli.Context, backends []types.Backend) error {
}
defer conn.Close()
client := agentRpc.NewGrpcClient(conn)
client := agent_rpc.NewGrpcClient(conn)
sigterm := abool.New()
ctx := metadata.NewOutgoingContext(
@ -138,12 +138,12 @@ func run(c *cli.Context, backends []types.Backend) error {
log.Error().Err(err).Msg("could not get grpc server version")
return err
}
if grpcServerVersion.GrpcVersion != agentRpc.ClientGrpcVersion {
if grpcServerVersion.GrpcVersion != agent_rpc.ClientGrpcVersion {
err := errors.New("GRPC version mismatch")
log.Error().Err(err).Msgf("server version %s does report grpc version %d but we only understand %d",
grpcServerVersion.ServerVersion,
grpcServerVersion.GrpcVersion,
agentRpc.ClientGrpcVersion)
agent_rpc.ClientGrpcVersion)
return err
}

View file

@ -64,7 +64,7 @@ var flags = []cli.Flag{
Usage: "List of labels to filter tasks on. An agent must be assigned every tag listed in a task to be selected.",
},
&cli.IntFlag{
EnvVars: []string{"WOODPECKER_MAX_WORKFLOWS", "WOODPECKER_MAX_PROCS"},
EnvVars: []string{"WOODPECKER_MAX_WORKFLOWS", "WOODPECKER_MAX_PROCS"}, // cspell:words PROCS
Name: "max-workflows",
Usage: "agent parallel workflows",
Value: 1,

View file

@ -32,8 +32,8 @@ import (
// https://github.com/mozilla-services/Dockerflow
func initHealth() {
http.HandleFunc("/varz", handleStats)
http.HandleFunc("/healthz", handleHeartbeat)
http.HandleFunc("/varz", handleStats) // cspell:words varz
http.HandleFunc("/healthz", handleHeartbeat) // cspell:words healthz
http.HandleFunc("/version", handleVersion)
}

View file

@ -24,6 +24,7 @@ func GenerateContainerConf(commands []string, goos string) (env map[string]strin
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptWindows(commands)))
env["HOME"] = "c:\\root"
env["SHELL"] = "powershell.exe"
// cspell:disable-next-line
entry = []string{"powershell", "-noprofile", "-noninteractive", "-command", "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex"}
} else {
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptPosix(commands)))

View file

@ -197,6 +197,7 @@ func encodeAuthToBase64(authConfig types.Auth) (string, error) {
//
// It handles Windows and Linux style volume paths.
func splitVolumeParts(volumeParts string) ([]string, error) {
// cspell:disable-next-line
pattern := `^((?:[\w]\:)?[^\:]*)\:((?:[\w]\:)?[^\:]*)(?:\:([rwom]*))?`
r, err := regexp.Compile(pattern)
if err != nil {

View file

@ -25,10 +25,10 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/volume"
"github.com/docker/go-connections/tlsconfig"
tls_config "github.com/docker/go-connections/tlsconfig"
"github.com/moby/moby/client"
"github.com/moby/moby/pkg/jsonmessage"
"github.com/moby/moby/pkg/stdcopy"
json_message "github.com/moby/moby/pkg/jsonmessage"
std_copy "github.com/moby/moby/pkg/stdcopy"
"github.com/moby/term"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
@ -75,13 +75,13 @@ func httpClientOfOpts(dockerCertPath string, verifyTLS bool) *http.Client {
return nil
}
options := tlsconfig.Options{
options := tls_config.Options{
CAFile: filepath.Join(dockerCertPath, "ca.pem"),
CertFile: filepath.Join(dockerCertPath, "cert.pem"),
KeyFile: filepath.Join(dockerCertPath, "key.pem"),
InsecureSkipVerify: !verifyTLS,
}
tlsConf, err := tlsconfig.Client(options)
tlsConf, err := tls_config.Client(options)
if err != nil {
log.Error().Err(err).Msg("could not create http client out of docker backend options")
return nil
@ -188,27 +188,27 @@ func (e *docker) StartStep(ctx context.Context, step *backend.Step, taskUUID str
containerName := toContainerName(step)
// create pull options with encoded authorization credentials.
pullopts := types.ImagePullOptions{}
pullOpts := types.ImagePullOptions{}
if step.AuthConfig.Username != "" && step.AuthConfig.Password != "" {
pullopts.RegistryAuth, _ = encodeAuthToBase64(step.AuthConfig)
pullOpts.RegistryAuth, _ = encodeAuthToBase64(step.AuthConfig)
}
// automatically pull the latest version of the image if requested
// by the process configuration.
if step.Pull {
responseBody, perr := e.client.ImagePull(ctx, config.Image, pullopts)
if perr == nil {
responseBody, pErr := e.client.ImagePull(ctx, config.Image, pullOpts)
if pErr == nil {
// TODO(1936): show image pull progress in web-ui
fd, isTerminal := term.GetFdInfo(os.Stdout)
if err := jsonmessage.DisplayJSONMessagesStream(responseBody, os.Stdout, fd, isTerminal, nil); err != nil {
if err := json_message.DisplayJSONMessagesStream(responseBody, os.Stdout, fd, isTerminal, nil); err != nil {
log.Error().Err(err).Msg("DisplayJSONMessagesStream")
}
responseBody.Close()
}
// Fix "Show warning when fail to auth to docker registry"
// (https://web.archive.org/web/20201023145804/https://github.com/drone/drone/issues/1917)
if perr != nil && step.AuthConfig.Password != "" {
return perr
if pErr != nil && step.AuthConfig.Password != "" {
return pErr
}
}
@ -219,13 +219,13 @@ func (e *docker) StartStep(ctx context.Context, step *backend.Step, taskUUID str
if client.IsErrNotFound(err) {
// automatically pull and try to re-create the image if the
// failure is caused because the image does not exist.
responseBody, perr := e.client.ImagePull(ctx, config.Image, pullopts)
if perr != nil {
return perr
responseBody, pErr := e.client.ImagePull(ctx, config.Image, pullOpts)
if pErr != nil {
return pErr
}
// TODO(1936): show image pull progress in web-ui
fd, isTerminal := term.GetFdInfo(os.Stdout)
if err := jsonmessage.DisplayJSONMessagesStream(responseBody, os.Stdout, fd, isTerminal, nil); err != nil {
if err := json_message.DisplayJSONMessagesStream(responseBody, os.Stdout, fd, isTerminal, nil); err != nil {
log.Error().Err(err).Msg("DisplayJSONMessagesStream")
}
responseBody.Close()
@ -263,10 +263,10 @@ func (e *docker) WaitStep(ctx context.Context, step *backend.Step, taskUUID stri
containerName := toContainerName(step)
wait, errc := e.client.ContainerWait(ctx, containerName, "")
wait, errC := e.client.ContainerWait(ctx, containerName, "")
select {
case <-wait:
case <-errc:
case <-errC:
}
info, err := e.client.ContainerInspect(ctx, containerName)
@ -292,7 +292,7 @@ func (e *docker) TailStep(ctx context.Context, step *backend.Step, taskUUID stri
// de multiplex 'logs' who contains two streams, previously multiplexed together using StdWriter
go func() {
_, _ = stdcopy.StdCopy(wc, wc, logs)
_, _ = std_copy.StdCopy(wc, wc, logs)
_ = logs.Close()
_ = wc.Close()
}()

View file

@ -68,7 +68,7 @@ var Flags = []cli.Flag{
Value: false,
},
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_BACKEND_K8S_SECCTX_NONROOT"},
EnvVars: []string{"WOODPECKER_BACKEND_K8S_SECCTX_NONROOT"}, // cspell:words secctx nonroot
Name: "backend-k8s-secctx-nonroot",
Usage: "`run as non root` Kubernetes security context option",
},

View file

@ -28,7 +28,7 @@ import (
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v3"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
@ -69,11 +69,11 @@ type SecurityContextConfig struct {
RunAsNonRoot bool
}
func newDefaultDeleteOptions() metav1.DeleteOptions {
func newDefaultDeleteOptions() meta_v1.DeleteOptions {
gracePeriodSeconds := int64(0) // immediately
propagationPolicy := metav1.DeletePropagationBackground
propagationPolicy := meta_v1.DeletePropagationBackground
return metav1.DeleteOptions{
return meta_v1.DeleteOptions{
GracePeriodSeconds: &gracePeriodSeconds,
PropagationPolicy: &propagationPolicy,
}
@ -93,7 +93,7 @@ func configFromCliContext(ctx context.Context) (*config, error) {
PodAnnotationsAllowFromStep: c.Bool("backend-k8s-pod-annotations-allow-from-step"),
ImagePullSecretNames: c.StringSlice("backend-k8s-pod-image-pull-secret-names"),
SecurityContext: SecurityContextConfig{
RunAsNonRoot: c.Bool("backend-k8s-secctx-nonroot"),
RunAsNonRoot: c.Bool("backend-k8s-secctx-nonroot"), // cspell:words secctx nonroot
},
}
// TODO: remove in next major
@ -270,7 +270,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string)
// TODO: Cancel on ctx.Done
<-finished
pod, err := e.client.CoreV1().Pods(e.config.Namespace).Get(ctx, podName, metav1.GetOptions{})
pod, err := e.client.CoreV1().Pods(e.config.Namespace).Get(ctx, podName, meta_v1.GetOptions{})
if err != nil {
return nil, err
}

View file

@ -24,7 +24,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/common"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
@ -73,9 +73,9 @@ func podName(step *types.Step) (string, error) {
return dnsName(podPrefix + step.UUID)
}
func podMeta(step *types.Step, config *config, options BackendOptions, podName string) (metav1.ObjectMeta, error) {
func podMeta(step *types.Step, config *config, options BackendOptions, podName string) (meta_v1.ObjectMeta, error) {
var err error
meta := metav1.ObjectMeta{
meta := meta_v1.ObjectMeta{
Name: podName,
Namespace: config.Namespace,
Annotations: podAnnotations(config, options, podName),
@ -509,10 +509,10 @@ func startPod(ctx context.Context, engine *kube, step *types.Step, options Backe
}
log.Trace().Msgf("creating pod: %s", pod.Name)
return engine.client.CoreV1().Pods(engineConfig.Namespace).Create(ctx, pod, metav1.CreateOptions{})
return engine.client.CoreV1().Pods(engineConfig.Namespace).Create(ctx, pod, meta_v1.CreateOptions{})
}
func stopPod(ctx context.Context, engine *kube, step *types.Step, deleteOpts metav1.DeleteOptions) error {
func stopPod(ctx context.Context, engine *kube, step *types.Step, deleteOpts meta_v1.DeleteOptions) error {
podName, err := stepToPodName(step)
if err != nil {
return err

View file

@ -22,8 +22,8 @@ import (
"github.com/rs/zerolog/log"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
int_str "k8s.io/apimachinery/pkg/util/intstr"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
)
@ -50,7 +50,7 @@ func mkService(step *types.Step, config *config) (*v1.Service, error) {
log.Trace().Str("name", name).Interface("selector", selector).Interface("ports", svcPorts).Msg("creating service")
return &v1.Service{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: meta_v1.ObjectMeta{
Name: name,
Namespace: config.Namespace,
},
@ -73,7 +73,7 @@ func servicePort(port types.Port) v1.ServicePort {
Name: fmt.Sprintf("port-%d", portNumber),
Port: portNumber,
Protocol: v1.Protocol(portProtocol),
TargetPort: intstr.IntOrString{IntVal: portNumber},
TargetPort: int_str.IntOrString{IntVal: portNumber},
}
}
@ -85,10 +85,10 @@ func startService(ctx context.Context, engine *kube, step *types.Step) (*v1.Serv
}
log.Trace().Str("name", svc.Name).Interface("selector", svc.Spec.Selector).Interface("ports", svc.Spec.Ports).Msg("creating service")
return engine.client.CoreV1().Services(engineConfig.Namespace).Create(ctx, svc, metav1.CreateOptions{})
return engine.client.CoreV1().Services(engineConfig.Namespace).Create(ctx, svc, meta_v1.CreateOptions{})
}
func stopService(ctx context.Context, engine *kube, step *types.Step, deleteOpts metav1.DeleteOptions) error {
func stopService(ctx context.Context, engine *kube, step *types.Step, deleteOpts meta_v1.DeleteOptions) error {
svcName, err := serviceName(step)
if err != nil {
return err

View file

@ -23,7 +23,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
client_cmd "k8s.io/client-go/tools/clientcmd"
)
var (
@ -65,15 +65,15 @@ func isImagePullBackOffState(pod *v1.Pod) bool {
return false
}
// getClientOutOfCluster returns a k8s clientset to the request from outside of cluster.
// getClientOutOfCluster returns a k8s client set to the request from outside of cluster.
func getClientOutOfCluster() (kubernetes.Interface, error) {
kubeConfigPath := os.Getenv("KUBECONFIG")
kubeConfigPath := os.Getenv("KUBECONFIG") // cspell:words KUBECONFIG
if kubeConfigPath == "" {
kubeConfigPath = os.Getenv("HOME") + "/.kube/config"
}
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
// use the current context in kube config
config, err := client_cmd.BuildConfigFromFlags("", kubeConfigPath)
if err != nil {
return nil, err
}
@ -81,7 +81,7 @@ func getClientOutOfCluster() (kubernetes.Interface, error) {
return kubernetes.NewForConfig(config)
}
// getClient returns a k8s clientset to the request from inside of cluster.
// getClient returns a k8s client set to the request from inside of cluster.
func getClientInsideOfCluster() (kubernetes.Interface, error) {
config, err := rest.InClusterConfig()
if err != nil {

View file

@ -22,7 +22,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func mkPersistentVolumeClaim(config *config, name string) (*v1.PersistentVolumeClaim, error) {
@ -45,7 +45,7 @@ func mkPersistentVolumeClaim(config *config, name string) (*v1.PersistentVolumeC
}
pvc := &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: meta_v1.ObjectMeta{
Name: volumeName,
Namespace: config.Namespace,
},
@ -83,10 +83,10 @@ func startVolume(ctx context.Context, engine *kube, name string) (*v1.Persistent
}
log.Trace().Msgf("creating volume: %s", pvc.Name)
return engine.client.CoreV1().PersistentVolumeClaims(engineConfig.Namespace).Create(ctx, pvc, metav1.CreateOptions{})
return engine.client.CoreV1().PersistentVolumeClaims(engineConfig.Namespace).Create(ctx, pvc, meta_v1.CreateOptions{})
}
func stopVolume(ctx context.Context, engine *kube, name string, deleteOpts metav1.DeleteOptions) error {
func stopVolume(ctx context.Context, engine *kube, name string, deleteOpts meta_v1.DeleteOptions) error {
pvcName, err := volumeName(name)
if err != nil {
return err

View file

@ -24,9 +24,9 @@ import (
"github.com/alessio/shellescape"
)
func (e *local) genCmdByShell(shell string, cmds []string) (args []string, err error) {
func (e *local) genCmdByShell(shell string, cmdList []string) (args []string, err error) {
script := ""
for _, cmd := range cmds {
for _, cmd := range cmdList {
script += fmt.Sprintf("echo %s\n%s\n", strings.TrimSpace(shellescape.Quote("+ "+cmd)), cmd)
}
script = strings.TrimSpace(script)
@ -34,7 +34,7 @@ func (e *local) genCmdByShell(shell string, cmds []string) (args []string, err e
switch strings.TrimSuffix(strings.ToLower(shell), ".exe") {
case "cmd":
script := "@SET PROMPT=$\n"
for _, cmd := range cmds {
for _, cmd := range cmdList {
script += fmt.Sprintf("@echo + %s\n", strings.TrimSpace(shellescape.Quote(cmd)))
script += fmt.Sprintf("@%s\n", cmd)
script += "@IF NOT %ERRORLEVEL% == 0 exit %ERRORLEVEL%\n"
@ -50,11 +50,12 @@ func (e *local) genCmdByShell(shell string, cmds []string) (args []string, err e
return []string{"/c", cmd.Name()}, nil
case "fish":
script := ""
for _, cmd := range cmds {
for _, cmd := range cmdList {
script += fmt.Sprintf("echo %s\n%s || exit $status\n", strings.TrimSpace(shellescape.Quote("+ "+cmd)), cmd)
}
return []string{"-c", script}, nil
case "powershell", "pwsh":
// cspell:disable-next-line
return []string{"-noprofile", "-noninteractive", "-c", "$ErrorActionPreference = \"Stop\"; " + script}, nil
default:
// normal posix shells

View file

@ -159,12 +159,12 @@ func WithNetworks(networks ...string) Option {
// WithResourceLimit configures the compiler with default resource limits that
// are applied each container in the pipeline.
func WithResourceLimit(swap, mem, shmsize, cpuQuota, cpuShares int64, cpuSet string) Option {
func WithResourceLimit(swap, mem, shmSize, cpuQuota, cpuShares int64, cpuSet string) Option {
return func(compiler *Compiler) {
compiler.reslimit = ResourceLimit{
MemSwapLimit: swap,
MemLimit: mem,
ShmSize: shmsize,
ShmSize: shmSize,
CPUQuota: cpuQuota,
CPUShares: cpuShares,
CPUSet: cpuSet,

View file

@ -197,11 +197,11 @@ func (c *Constraint) Match(m metadata.Metadata, global bool, env map[string]stri
if err != nil {
return false, err
}
bresult, ok := result.(bool)
bResult, ok := result.(bool)
if !ok {
return false, fmt.Errorf("could not parse result: %v", result)
}
match = match && bresult
match = match && bResult
}
return match, nil
@ -247,7 +247,7 @@ func (c *List) Excludes(v string) bool {
return false
}
// UnmarshalYAML unmarshals the constraint.
// UnmarshalYAML unmarshal the constraint.
func (c *List) UnmarshalYAML(value *yaml.Node) error {
out1 := struct {
Include yamlBaseTypes.StringOrSlice

View file

@ -22,7 +22,7 @@ import (
"codeberg.org/6543/go-yaml2json"
"codeberg.org/6543/xyaml"
"github.com/xeipuuv/gojsonschema"
json_schema "github.com/xeipuuv/gojsonschema"
"gopkg.in/yaml.v3"
)
@ -30,8 +30,8 @@ import (
var schemaDefinition []byte
// Lint lints an io.Reader against the Woodpecker `schema.json`.
func Lint(r io.Reader) ([]gojsonschema.ResultError, error) {
schemaLoader := gojsonschema.NewBytesLoader(schemaDefinition)
func Lint(r io.Reader) ([]json_schema.ResultError, error) {
schemaLoader := json_schema.NewBytesLoader(schemaDefinition)
// read yaml config
rBytes, err := io.ReadAll(r)
@ -51,8 +51,8 @@ func Lint(r io.Reader) ([]gojsonschema.ResultError, error) {
return nil, fmt.Errorf("failed to convert yaml %w", err)
}
documentLoader := gojsonschema.NewBytesLoader(jsonDoc)
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
documentLoader := json_schema.NewBytesLoader(jsonDoc)
result, err := json_schema.Validate(schemaLoader, documentLoader)
if err != nil {
return nil, fmt.Errorf("validation failed %w", err)
}
@ -64,6 +64,6 @@ func Lint(r io.Reader) ([]gojsonschema.ResultError, error) {
return nil, nil
}
func LintString(s string) ([]gojsonschema.ResultError, error) {
func LintString(s string) ([]json_schema.ResultError, error) {
return Lint(bytes.NewBufferString(s))
}

View file

@ -86,11 +86,11 @@ func calc(matrix Matrix) []Axis {
// for each axis calculate the unique set of values that should be used.
for p := 0; p < perm; p++ {
axis := map[string]string{}
decr := perm
decrease := perm
for i, tag := range tags {
elems := matrix[tag]
decr /= len(elems)
elem := p / decr % len(elems)
decrease /= len(elems)
elem := p / decrease % len(elems)
axis[tag] = elems[elem]
// enforce a maximum number of tags in the pipeline matrix.

View file

@ -25,7 +25,7 @@ type BoolTrue struct {
value bool
}
// UnmarshalYAML implements custom Yaml unmarshaling.
// UnmarshalYAML implements custom Yaml unmarshal.
func (b *BoolTrue) UnmarshalYAML(value *yaml.Node) error {
var s string
if err := value.Decode(&s); err != nil {

View file

@ -66,24 +66,24 @@ func (v *Volumes) UnmarshalYAML(unmarshal func(any) error) error {
if !ok {
return fmt.Errorf("cannot unmarshal '%v' to type %T into a string value", name, name)
}
elts := strings.SplitN(name, ":", 3)
elements := strings.SplitN(name, ":", 3)
var vol *Volume
//nolint:mnd
switch {
case len(elts) == 1:
case len(elements) == 1:
vol = &Volume{
Destination: elts[0],
Destination: elements[0],
}
case len(elts) == 2:
case len(elements) == 2:
vol = &Volume{
Source: elts[0],
Destination: elts[1],
Source: elements[0],
Destination: elements[1],
}
case len(elts) == 3:
case len(elements) == 3:
vol = &Volume{
Source: elts[0],
Destination: elts[1],
AccessMode: elts[2],
Source: elements[0],
Destination: elements[1],
AccessMode: elements[2],
}
default:
// FIXME

View file

@ -134,7 +134,7 @@ message RegisterAgentResponse {
int64 agent_id = 1;
}
// Woodpecker auth service is a simple service to authenticate agents and aquire a token
// Woodpecker auth service is a simple service to authenticate agents and acquire a token
service WoodpeckerAuth {
rpc Auth (AuthRequest) returns (AuthResponse) {}

View file

@ -22,7 +22,7 @@ import "strings"
// secrets with asterisks. Each secret string is split on newlines to
// handle multi-line secrets.
func NewSecretsReplacer(secrets []string) *strings.Replacer {
var oldnew []string
var oldNew []string
// Strings shorter than minStringLength are not considered secrets.
// Do not sanitize them.
@ -38,10 +38,10 @@ func NewSecretsReplacer(secrets []string) *strings.Replacer {
if len(part) == 0 {
continue
}
oldnew = append(oldnew, part)
oldnew = append(oldnew, "********")
oldNew = append(oldNew, part)
oldNew = append(oldNew, "********")
}
}
return strings.NewReplacer(oldnew...)
return strings.NewReplacer(oldNew...)
}

View file

@ -20,7 +20,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
swaggerfiles "github.com/swaggo/files"
swagger_files "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"go.woodpecker-ci.org/woodpecker/v2/cmd/server/docs"
@ -82,7 +82,7 @@ func Load(noRouteHandler http.HandlerFunc, middleware ...gin.HandlerFunc) http.H
func setupSwaggerConfigAndRoutes(e *gin.Engine) {
docs.SwaggerInfo.Host = getHost(server.Config.Server.Host)
docs.SwaggerInfo.BasePath = server.Config.Server.RootPath + "/api"
e.GET(server.Config.Server.RootPath+"/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
e.GET(server.Config.Server.RootPath+"/swagger/*any", ginSwagger.WrapHandler(swagger_files.Handler))
}
func getHost(s string) string {

View file

@ -80,10 +80,10 @@ func (h *http) Fetch(ctx context.Context, forge forge.Forge, user *model.User, r
return oldConfigData, nil
}
fileMetas := make([]*types.FileMeta, len(response.Configs))
fileMetaList := make([]*types.FileMeta, len(response.Configs))
for i, config := range response.Configs {
fileMetas[i] = &types.FileMeta{Name: config.Name, Data: []byte(config.Data)}
fileMetaList[i] = &types.FileMeta{Name: config.Name, Data: []byte(config.Data)}
}
return fileMetas, nil
return fileMetaList, nil
}

View file

@ -111,7 +111,7 @@ func (m *manager) RegistryService() registry.Service {
}
func (m *manager) ConfigServiceFromRepo(_ *model.Repo) config.Service {
// TODO: decied based on repo property which config service to use
// TODO: decide based on repo property which config service to use
return m.config
}