1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-06 17:40:58 +00:00

chore: enable staticcheck (#196)

Fix places where deprecated functions/types were used.

Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/196
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-07-26 03:55:31 +00:00 committed by earl-warren
parent 6e4a3b5127
commit b1ea5424b9
8 changed files with 41 additions and 41 deletions

View file

@ -3,7 +3,6 @@ package artifacts
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"io/fs" "io/fs"
@ -136,11 +135,11 @@ func uploads(router *httprouter.Router, baseDir string, fsys WriteFS) {
writer, ok := file.(io.Writer) writer, ok := file.(io.Writer)
if !ok { if !ok {
panic(errors.New("File is not writable")) panic("File is not writable")
} }
if req.Body == nil { if req.Body == nil {
panic(errors.New("No body given")) panic("No body given")
} }
_, err = io.Copy(writer, req.Body) _, err = io.Copy(writer, req.Body)

View file

@ -8,12 +8,11 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types/build"
"github.com/docker/docker/pkg/archive"
// github.com/docker/docker/builder/dockerignore is deprecated "github.com/moby/go-archive"
"github.com/moby/buildkit/frontend/dockerfile/dockerignore"
"github.com/moby/patternmatcher" "github.com/moby/patternmatcher"
"github.com/moby/patternmatcher/ignorefile"
"github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/common"
) )
@ -40,7 +39,7 @@ func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
logger.Debugf("Building image from '%v'", input.ContextDir) logger.Debugf("Building image from '%v'", input.ContextDir)
tags := []string{input.ImageTag} tags := []string{input.ImageTag}
options := types.ImageBuildOptions{ options := build.ImageBuildOptions{
Tags: tags, Tags: tags,
Remove: true, Remove: true,
Platform: input.Platform, Platform: input.Platform,
@ -83,7 +82,7 @@ func createBuildContext(ctx context.Context, contextDir string, relDockerfile st
var excludes []string var excludes []string
if err == nil { if err == nil {
excludes, err = dockerignore.ReadAll(f) excludes, err = ignorefile.ReadAll(f)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -386,7 +386,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// Can't evaluate options passed into --tmpfs until we actually mount // Can't evaluate options passed into --tmpfs until we actually mount
tmpfs := make(map[string]string) tmpfs := make(map[string]string)
for _, t := range copts.tmpfs.GetAll() { for _, t := range copts.tmpfs.GetSlice() {
if arr := strings.SplitN(t, ":", 2); len(arr) > 1 { if arr := strings.SplitN(t, ":", 2); len(arr) > 1 {
tmpfs[arr[0]] = arr[1] tmpfs[arr[0]] = arr[1]
} else { } else {
@ -410,7 +410,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
entrypoint = []string{""} entrypoint = []string{""}
} }
publishOpts := copts.publish.GetAll() publishOpts := copts.publish.GetSlice()
var ( var (
ports map[nat.Port]struct{} ports map[nat.Port]struct{}
portBindings map[nat.Port][]nat.PortBinding portBindings map[nat.Port][]nat.PortBinding
@ -428,7 +428,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
} }
// Merge in exposed ports to the map of published ports // Merge in exposed ports to the map of published ports
for _, e := range copts.expose.GetAll() { for _, e := range copts.expose.GetSlice() {
if strings.Contains(e, ":") { if strings.Contains(e, ":") {
return nil, errors.Errorf("invalid port format for --expose: %s", e) return nil, errors.Errorf("invalid port format for --expose: %s", e)
} }
@ -457,7 +457,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
// parsing flags, we haven't yet sent a _ping to the daemon to determine // parsing flags, we haven't yet sent a _ping to the daemon to determine
// what operating system it is. // what operating system it is.
deviceMappings := []container.DeviceMapping{} deviceMappings := []container.DeviceMapping{}
for _, device := range copts.devices.GetAll() { for _, device := range copts.devices.GetSlice() {
var ( var (
validated string validated string
deviceMapping container.DeviceMapping deviceMapping container.DeviceMapping
@ -475,13 +475,13 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
} }
// collect all the environment variables for the container // collect all the environment variables for the container
envVariables, err := opts.ReadKVEnvStrings(copts.envFile.GetAll(), copts.env.GetAll()) envVariables, err := opts.ReadKVEnvStrings(copts.envFile.GetSlice(), copts.env.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
// collect all the labels for the container // collect all the labels for the container
labels, err := opts.ReadKVStrings(copts.labelsFile.GetAll(), copts.labels.GetAll()) labels, err := opts.ReadKVStrings(copts.labelsFile.GetSlice(), copts.labels.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -511,19 +511,19 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
return nil, err return nil, err
} }
loggingOpts, err := parseLoggingOpts(copts.loggingDriver, copts.loggingOpts.GetAll()) loggingOpts, err := parseLoggingOpts(copts.loggingDriver, copts.loggingOpts.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
securityOpts, err := parseSecurityOpts(copts.securityOpt.GetAll()) securityOpts, err := parseSecurityOpts(copts.securityOpt.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
securityOpts, maskedPaths, readonlyPaths := parseSystemPaths(securityOpts) securityOpts, maskedPaths, readonlyPaths := parseSystemPaths(securityOpts)
storageOpts, err := parseStorageOpts(copts.storageOpt.GetAll()) storageOpts, err := parseStorageOpts(copts.storageOpt.GetSlice())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -597,7 +597,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
IOMaximumIOps: copts.ioMaxIOps, IOMaximumIOps: copts.ioMaxIOps,
IOMaximumBandwidth: uint64(copts.ioMaxBandwidth), //nolint:gosec IOMaximumBandwidth: uint64(copts.ioMaxBandwidth), //nolint:gosec
Ulimits: copts.ulimits.GetList(), Ulimits: copts.ulimits.GetList(),
DeviceCgroupRules: copts.deviceCgroupRules.GetAll(), DeviceCgroupRules: copts.deviceCgroupRules.GetSlice(),
Devices: deviceMappings, Devices: deviceMappings,
DeviceRequests: copts.gpus.Value(), DeviceRequests: copts.gpus.Value(),
} }
@ -638,7 +638,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
AutoRemove: copts.autoRemove, AutoRemove: copts.autoRemove,
Privileged: copts.privileged, Privileged: copts.privileged,
PortBindings: portBindings, PortBindings: portBindings,
Links: copts.links.GetAll(), Links: copts.links.GetSlice(),
PublishAllPorts: copts.publishAll, PublishAllPorts: copts.publishAll,
// Make sure the dns fields are never nil. // Make sure the dns fields are never nil.
// New containers don't ever have those fields nil, // New containers don't ever have those fields nil,
@ -648,17 +648,17 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
DNS: copts.dns.GetAllOrEmpty(), DNS: copts.dns.GetAllOrEmpty(),
DNSSearch: copts.dnsSearch.GetAllOrEmpty(), DNSSearch: copts.dnsSearch.GetAllOrEmpty(),
DNSOptions: copts.dnsOptions.GetAllOrEmpty(), DNSOptions: copts.dnsOptions.GetAllOrEmpty(),
ExtraHosts: copts.extraHosts.GetAll(), ExtraHosts: copts.extraHosts.GetSlice(),
VolumesFrom: copts.volumesFrom.GetAll(), VolumesFrom: copts.volumesFrom.GetSlice(),
IpcMode: container.IpcMode(copts.ipcMode), IpcMode: container.IpcMode(copts.ipcMode),
NetworkMode: container.NetworkMode(copts.netMode.NetworkMode()), NetworkMode: container.NetworkMode(copts.netMode.NetworkMode()),
PidMode: pidMode, PidMode: pidMode,
UTSMode: utsMode, UTSMode: utsMode,
UsernsMode: usernsMode, UsernsMode: usernsMode,
CgroupnsMode: cgroupnsMode, CgroupnsMode: cgroupnsMode,
CapAdd: strslice.StrSlice(copts.capAdd.GetAll()), CapAdd: strslice.StrSlice(copts.capAdd.GetSlice()),
CapDrop: strslice.StrSlice(copts.capDrop.GetAll()), CapDrop: strslice.StrSlice(copts.capDrop.GetSlice()),
GroupAdd: copts.groupAdd.GetAll(), GroupAdd: copts.groupAdd.GetSlice(),
RestartPolicy: restartPolicy, RestartPolicy: restartPolicy,
SecurityOpt: securityOpts, SecurityOpt: securityOpts,
StorageOpt: storageOpts, StorageOpt: storageOpts,
@ -777,11 +777,11 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
} }
if copts.aliases.Len() > 0 { if copts.aliases.Len() > 0 {
n.Aliases = make([]string, copts.aliases.Len()) n.Aliases = make([]string, copts.aliases.Len())
copy(n.Aliases, copts.aliases.GetAll()) copy(n.Aliases, copts.aliases.GetSlice())
} }
if copts.links.Len() > 0 { if copts.links.Len() > 0 {
n.Links = make([]string, copts.links.Len()) n.Links = make([]string, copts.links.Len())
copy(n.Links, copts.links.GetAll()) copy(n.Links, copts.links.GetSlice())
} }
if copts.ipv4Address != "" { if copts.ipv4Address != "" {
n.IPv4Address = copts.ipv4Address n.IPv4Address = copts.ipv4Address
@ -793,7 +793,7 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
// TODO should linkLocalIPs be added to the _first_ network only, or to _all_ networks? (should this be a per-network option as well?) // TODO should linkLocalIPs be added to the _first_ network only, or to _all_ networks? (should this be a per-network option as well?)
if copts.linkLocalIPs.Len() > 0 { if copts.linkLocalIPs.Len() > 0 {
n.LinkLocalIPs = make([]string, copts.linkLocalIPs.Len()) n.LinkLocalIPs = make([]string, copts.linkLocalIPs.Len())
copy(n.LinkLocalIPs, copts.linkLocalIPs.GetAll()) copy(n.LinkLocalIPs, copts.linkLocalIPs.GetSlice())
} }
return nil return nil
} }

View file

@ -300,8 +300,10 @@ func TestParseWithMacAddress(t *testing.T) {
if _, _, _, err := parseRun([]string{invalidMacAddress, "img", "cmd"}); err != nil && err.Error() != "invalidMacAddress is not a valid mac address" { if _, _, _, err := parseRun([]string{invalidMacAddress, "img", "cmd"}); err != nil && err.Error() != "invalidMacAddress is not a valid mac address" {
t.Fatalf("Expected an error with %v mac-address, got %v", invalidMacAddress, err) t.Fatalf("Expected an error with %v mac-address, got %v", invalidMacAddress, err)
} }
if config, _ := mustParse(t, validMacAddress); config.MacAddress != "92:d0:c6:0a:29:33" { config, _ := mustParse(t, validMacAddress)
t.Fatalf("Expected the config to have '92:d0:c6:0a:29:33' as MacAddress, got '%v'", config.MacAddress) if config.MacAddress != "92:d0:c6:0a:29:33" { //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
t.Fatalf("Expected the config to have '92:d0:c6:0a:29:33' as container-wide MacAddress, got '%v'",
config.MacAddress) //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
} }
} }

View file

@ -6,8 +6,8 @@ import (
"context" "context"
"fmt" "fmt"
cerrdefs "github.com/containerd/errdefs"
"github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
) )
// ImageExistsLocally returns a boolean indicating if an image with the // ImageExistsLocally returns a boolean indicating if an image with the
@ -19,8 +19,8 @@ func ImageExistsLocally(ctx context.Context, imageName string, platform string)
} }
defer cli.Close() defer cli.Close()
inspectImage, _, err := cli.ImageInspectWithRaw(ctx, imageName) inspectImage, err := cli.ImageInspect(ctx, imageName)
if client.IsErrNotFound(err) { if cerrdefs.IsNotFound(err) {
return false, nil return false, nil
} else if err != nil { } else if err != nil {
return false, err return false, err
@ -43,7 +43,7 @@ func RemoveImage(ctx context.Context, imageName string, force bool, pruneChildre
defer cli.Close() defer cli.Close()
inspectImage, err := cli.ImageInspect(ctx, imageName) inspectImage, err := cli.ImageInspect(ctx, imageName)
if client.IsErrNotFound(err) { if cerrdefs.IsNotFound(err) {
return false, nil return false, nil
} else if err != nil { } else if err != nil {
return false, err return false, err

View file

@ -23,7 +23,6 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/system" "github.com/docker/docker/api/types/system"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
@ -63,7 +62,7 @@ func (cr *containerReference) ConnectToNetwork(name string) common.Executor {
func (cr *containerReference) connectToNetwork(name string, aliases []string) common.Executor { func (cr *containerReference) connectToNetwork(name string, aliases []string) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
return cr.cli.NetworkConnect(ctx, name, cr.input.Name, &networktypes.EndpointSettings{ return cr.cli.NetworkConnect(ctx, name, cr.input.Name, &network.EndpointSettings{
Aliases: aliases, Aliases: aliases,
}) })
} }
@ -578,7 +577,7 @@ func (cr *containerReference) extractFromImageEnv(env *map[string]string) common
return func(ctx context.Context) error { return func(ctx context.Context) error {
logger := common.Logger(ctx) logger := common.Logger(ctx)
inspect, _, err := cr.cli.ImageInspectWithRaw(ctx, cr.input.Image) inspect, err := cr.cli.ImageInspect(ctx, cr.input.Image)
if err != nil { if err != nil {
err = fmt.Errorf("inspect image: %w", err) err = fmt.Errorf("inspect image: %w", err)
logger.Error(err) logger.Error(err)
@ -727,7 +726,7 @@ func (cr *containerReference) tryReadGID() common.Executor {
return cr.tryReadID("-g", func(id int) { cr.GID = id }) return cr.tryReadID("-g", func(id int) { cr.GID = id })
} }
func (cr *containerReference) waitForCommand(ctx context.Context, isTerminal bool, resp types.HijackedResponse, _ types.IDResponse, _ string, _ string) error { func (cr *containerReference) waitForCommand(ctx context.Context, isTerminal bool, resp types.HijackedResponse, _ container.ExecCreateResponse, _ string, _ string) error {
logger := common.Logger(ctx) logger := common.Logger(ctx)
cmdResponse := make(chan error) cmdResponse := make(chan error)

View file

@ -440,9 +440,10 @@ func (e *HostEnvironment) GetActPath() string {
} }
func (*HostEnvironment) GetPathVariableName() string { func (*HostEnvironment) GetPathVariableName() string {
if runtime.GOOS == "plan9" { switch runtime.GOOS {
case "plan9":
return "path" return "path"
} else if runtime.GOOS == "windows" { case "windows":
return "Path" // Actually we need a case insensitive map return "Path" // Actually we need a case insensitive map
} }
return "PATH" return "PATH"

View file

@ -57,7 +57,7 @@ func (mfs *memoryFs) Walk(root string, fn filepath.WalkFunc) error {
} }
func (mfs *memoryFs) OpenGitIndex(path string) (*index.Index, error) { func (mfs *memoryFs) OpenGitIndex(path string) (*index.Index, error) {
f, _ := mfs.Filesystem.Chroot(filepath.Join(path, ".git")) f, _ := mfs.Chroot(filepath.Join(path, ".git"))
storage := filesystem.NewStorage(f, cache.NewObjectLRUDefault()) storage := filesystem.NewStorage(f, cache.NewObjectLRUDefault())
i, err := storage.Index() i, err := storage.Index()
if err != nil { if err != nil {