Files
act_runner/act/runner/step_docker.go
silverwind e71a5028b0 enhance: align job execution closer to GitHub Actions (#1421)
Closes many small gaps between how workflows run on GitHub and on the runner, each checked against GitHub's runner and live runs.

- `action.yml` expressions are checked against the contexts GitHub allows per field, and input defaults are evaluated with those contexts only
- Reusable workflows take inputs from `workflow_call` only, evaluate outputs once after all called jobs finish, stop at 10 nested workflows and resolve relative `./` paths in remote workflows against that workflow's repository
- A called job failing under `continue-on-error` no longer fails the caller, and same-repository calls use their own clone cache
- Job timeouts cancel the job with GitHub's message, step timeouts fail the step with GitHub's message, and invalid `timeout-minutes` values behave like on GitHub
- `runner.timeout` expiry names the setting and server cancellation is logged
- Matrix and strategy evaluation errors fail the job
- `exec` records skipped jobs and sets `github.run_attempt`, `workflow_ref` and `workflow_sha`
- `runs-on` expressions keep their types
- Step summaries upload as each step ends
- Docker actions join the job network, and the job container no longer gets a network alias from the job name
- Container, network and volume names are unique per job invocation
- Cached images are matched against the daemon's platform and Dockerfile actions build for the requested platform
- `runner.arch` maps 32-bit ARM and x86 names like GitHub
- Pinned action SHAs are verified and git replace objects are ignored
- `hashFiles` uses GitHub's current bundle
- Registration trims labels and writes `.runner` as `0600`
- The container entrypoint quotes its arguments and reads the registration token from the environment or a file
- The systemd example uses `KillMode=mixed` so running jobs can finish on stop
- The cache server releases its database between eviction batches
- Shared rules come from actionslib v1.7.0, added in https://gitea.com/gitea/actionslib/pulls/34

_Written by Claude (Opus 5.5)._

Reviewed-on: https://gitea.com/gitea/runner/pulls/1421
Reviewed-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
2026-11-22 10:11:23 +00:00

87 lines
2.2 KiB
Go

// Copyright 2022 The Gitea Authors. All rights reserved.
// Copyright 2022 The nektos/act Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package runner
import (
"context"
"errors"
"fmt"
"strings"
"gitea.com/gitea/runner/act/common"
"gitea.com/gitea/runner/act/container"
"gitea.dev/actionslib/pkg/model"
"github.com/kballard/go-shellquote"
)
type stepDocker struct {
Step *model.Step
RunContext *RunContext
env map[string]string
}
func (sd *stepDocker) pre() common.Executor { return common.NewPipelineExecutor() }
func (sd *stepDocker) main() common.Executor {
sd.env = map[string]string{}
return runStepExecutor(sd, stepStageMain, sd.runUsesContainer)
}
func (sd *stepDocker) post() common.Executor { return common.NewPipelineExecutor() }
func (sd *stepDocker) getRunContext() *RunContext {
return sd.RunContext
}
func (sd *stepDocker) getStepModel() *model.Step {
return sd.Step
}
func (sd *stepDocker) getEnv() *map[string]string {
return &sd.env
}
func (sd *stepDocker) getIfExpression(_ context.Context, _ stepStage) string {
return sd.Step.If.Value
}
func (sd *stepDocker) runUsesContainer(ctx context.Context) error {
rc := sd.RunContext
if rc.isWindowsHost() {
return errWindowsHostContainer
}
if rc.kubernetes {
return errKubernetesDocker
}
cmd, err := shellquote.Split(stepInput(sd.Step, "args"))
if err != nil {
return err
}
var entrypoint []string
if entry := stepInput(sd.Step, "entrypoint"); entry != "" {
entrypoint = []string{entry}
}
input := stepContainerInput(ctx, sd, strings.TrimPrefix(sd.Step.Uses, "docker://"), cmd, entrypoint, "")
return rc.runStepContainer(ctx, ContainerNewContainer(input), nil, rc.Config.ForcePull)
}
func (rc *RunContext) runStepContainer(ctx context.Context, stepContainer container.Container, prepImage common.Executor, forcePull bool) error {
if stepContainer == nil {
return fmt.Errorf("running a Docker action: %w", errors.ErrUnsupported)
}
return common.NewPipelineExecutor(
prepImage,
stepContainer.Pull(forcePull),
stepContainer.Remove(),
stepContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop),
stepContainer.Start(true),
).Finally(stepContainer.Close())(ctx)
}
var ContainerNewContainer = container.NewContainer