mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-05 14:55:44 +00:00
Contains a number of small bug fixes where jobs behaved differently from GitHub or failed silently.
1. Hooks fail on a refused `::set-env::` or `::add-path::` and no longer inherit the last step's identity
1. Docker build, exec and wait errors are returned instead of swallowed, token-only registry credentials work, logs of `--tty` services decode
1. Env files split lines like GitHub on each OS, so a carriage return is kept on Linux and CRLF ends a line on Windows, empty heredoc names or delimiters are rejected
1. Post steps run after their pre step even when main was skipped, composites see undeclared inputs, `runs.args` wins without `with.args` being parsed
1. Docker actions skip evaluating defaults of inputs given in `with` and read `entryPoint` and `args` in any case, a lowercase `dockerfile` is found, undeclared inputs get GitHub's warning
1. A user-set `CI` is kept, `GITHUB_REPOSITORY_ID` and the other missing `GITHUB_*` variables are exported
1. `timeout-minutes` can read the step's own `env`, a step-level `ACTIONS_ALLOW_UNSECURE_COMMANDS: false` beats a job-level `true` while the runner's own opt-in still wins, `pwsh` quotes the script path
1. A step `env:` given as one expression such as `${{ fromJSON(matrix.env) }}` is applied, `hashFiles` fails with GitHub's messages on script errors and after 120 seconds, a job image without node still gets an empty hash
1. A step whose command files cannot be reset fails instead of importing stale ones, a timeout between steps fails the job instead of reporting success
1. One named volume can be mounted at several paths, host-mode PTY steps keep their last output when they fail, host scratch directories are removed when job setup fails
1. Cancelling a step right after it starts kills its whole process tree
1. Cache prefix restores pick the newest entry created within the same second, also on S3, cache commits with a wrong size are rejected
1. Artifact chunks are written at their offset, download URLs are escaped, listing a run without artifacts no longer crashes
1. Poll backoff reaches `fetch_interval_max`, proxy passwords are masked in more forms, secrets are also masked in step names and in their quoted form in the runner log, a failed final report is logged
1. On Windows hosts a differently cased unsecure-commands opt-in or proxy variable counts, and an early cancel no longer leaks a job object handle
1. Interactive `register` prompts for a missing token and stops on SIGTERM, `exec --list --detect-event` no longer panics without events, `config set` works on `cache.s3` keys
Reviewed-on: https://gitea.com/gitea/runner/pulls/1338
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
86 lines
2.8 KiB
Go
86 lines
2.8 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package process
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
"sync/atomic"
|
|
"time"
|
|
)
|
|
|
|
// treeKillWaitDelay bounds how long Wait lingers for the command's I/O pipes to
|
|
// drain after the process exits before force-closing them and returning. It also
|
|
// covers a command that backgrounds a process holding a pipe open after a clean
|
|
// exit.
|
|
const treeKillWaitDelay = 10 * time.Second
|
|
|
|
// TreeKill wires an exec.Cmd so that cancelling it tears down the command's
|
|
// whole process tree (see Killer) rather than only the direct child, and bounds
|
|
// the post-exit I/O wait so a leftover pipe writer can never hang cmd.Wait.
|
|
//
|
|
// Background: a command often launches a process tree (a shell that starts a
|
|
// child which spawns further background processes). The default
|
|
// exec.CommandContext cancellation only kills the direct child, leaving the rest
|
|
// of the tree running; and because the orphans inherit cmd's stdout/stderr pipe,
|
|
// cmd.Wait() would block forever, hanging the caller.
|
|
//
|
|
// Callers still set cmd.SysProcAttr (via SysProcAttr) themselves, because the
|
|
// value differs between the plain and PTY execution paths.
|
|
type TreeKill struct {
|
|
killer atomic.Pointer[Killer]
|
|
}
|
|
|
|
// NewTreeKill sets cmd.Cancel and cmd.WaitDelay. Call it before cmd.Start, then
|
|
// call Capture once after a successful Start.
|
|
func NewTreeKill(cmd *exec.Cmd) *TreeKill {
|
|
t := &TreeKill{}
|
|
cmd.Cancel = func() error {
|
|
if k := t.killer.Load(); k != nil {
|
|
return k.Kill()
|
|
}
|
|
if cmd.Process != nil {
|
|
if killer, err := NewKiller(cmd.Process); err == nil {
|
|
defer killer.Close()
|
|
return killer.Kill()
|
|
}
|
|
return cmd.Process.Kill()
|
|
}
|
|
return nil
|
|
}
|
|
cmd.WaitDelay = treeKillWaitDelay
|
|
return t
|
|
}
|
|
|
|
// Capture assigns the started process (and the descendants it spawns) to a
|
|
// Killer so cancellation can reach the whole tree — a Job Object on Windows
|
|
// (children spawned afterwards are auto-included) and the process group on Unix.
|
|
// Call it once after cmd.Start. On failure the command falls back to the default
|
|
// single-process kill and the returned error is for logging only; WaitDelay
|
|
// still bounds the wait. The returned Killer should be closed when the command
|
|
// finishes (Close is nil-safe).
|
|
func (t *TreeKill) Capture(p *os.Process) (*Killer, error) {
|
|
k, err := NewKiller(p)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
t.killer.Store(k)
|
|
return k, nil
|
|
}
|
|
|
|
// Wait is cmd.Wait, but like GitHub's runner a leftover holding a successful command's output does not fail it, and is killed only on Windows.
|
|
func (t *TreeKill) Wait(ctx context.Context, cmd *exec.Cmd) error {
|
|
err := cmd.Wait()
|
|
if !errors.Is(err, exec.ErrWaitDelay) || ctx.Err() != nil {
|
|
return err
|
|
}
|
|
if runtime.GOOS == "windows" {
|
|
_ = t.killer.Load().Kill()
|
|
}
|
|
return nil
|
|
}
|