mirror of
https://gitea.com/gitea/runner.git
synced 2026-08-28 23:07:46 +00:00
fix: improve behaviour across masking, commands and status (#1194)
Fixes 51 bugs discovered via comparison with `actions/runner`. Every fix has test coverage.
### Secrets
- A short secret registered no shifted-base64 form, so `base64("user:$TOKEN")` printed in the clear
- Encoded forms came only from the whole trimmed value, missing padded and per-line spellings
- Masks split only on `\n`, so `::add-mask::a%0Db` registered neither half
- Adds XML, expression-string and quote-trimming encoders
### Workflow commands
- Split at the last `::` or `]` rather than the first, so `::add-mask::a::b` registered no mask
- A command on the last line without a newline was ignored, and `::ADD-MASK::` did nothing
- `##[...]` did not decode `%3B`/`%5D`, properties lost anything after a second `=`
- `$GITHUB_ENV` and `::set-env::` now refuse `NODE_OPTIONS`
### Status
- `continue-on-error` reported failed, a cancelled job reported success, an `if:` error reported cancelled
- File commands ran after `continue-on-error`, failing the job while the step stayed green
- A bad job output aborted the whole run instead of that job
### Steps and actions
- `${{ matrix.* }}` and `${{ strategy.* }}` were empty inside composite actions
- Composite inputs leaked into nested actions as `INPUT_*`, `with:` matched case-sensitively, `pre` failures were dropped
- Docker actions dropped `runs.env` when the caller passed `with: args:`, and caller `args`/`entrypoint` beat the manifest
- An implicit shell ran with `pipefail`, a `shell:` without `{0}` passed without running
- `container.env` overrode job env and every `$GITHUB_ENV` write, heredocs lost leading blank lines, `$GITHUB_PATH` was not BOM-decoded
Written by Claude Opus 5.
Reviewed-on: https://gitea.com/gitea/runner/pulls/1194
Reviewed-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -36,7 +36,13 @@ func evaluateCompositeInputAndEnv(ctx context.Context, parent *RunContext, step
|
||||
|
||||
// lookup if key is defined in the step but the already
|
||||
// evaluated value from the environment
|
||||
_, defined := step.getStepModel().With[inputID]
|
||||
defined := false
|
||||
for key := range step.getStepModel().With {
|
||||
if strings.EqualFold(key, inputID) {
|
||||
defined = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if value, ok := stepEnv[envKey]; defined && ok {
|
||||
env[envKey] = value
|
||||
} else {
|
||||
@@ -51,6 +57,15 @@ func evaluateCompositeInputAndEnv(ctx context.Context, parent *RunContext, step
|
||||
return env
|
||||
}
|
||||
|
||||
func (rc *RunContext) setCompositeActionEnv(env map[string]string) {
|
||||
rc.setActionEnv(env)
|
||||
for key := range rc.Env {
|
||||
if strings.HasPrefix(key, "INPUT_") {
|
||||
delete(rc.Env, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func newCompositeRunContext(ctx context.Context, parent *RunContext, step actionStep, actionPath string) *RunContext {
|
||||
env := evaluateCompositeInputAndEnv(ctx, parent, step)
|
||||
|
||||
@@ -62,12 +77,13 @@ func newCompositeRunContext(ctx context.Context, parent *RunContext, step action
|
||||
compositerc := &RunContext{
|
||||
Name: parent.Name,
|
||||
JobName: parent.JobName,
|
||||
Matrix: parent.Matrix,
|
||||
Run: &model.Run{
|
||||
JobID: parent.Run.JobID,
|
||||
Workflow: &model.Workflow{
|
||||
Name: parent.Run.Workflow.Name,
|
||||
Jobs: map[string]*model.Job{
|
||||
parent.Run.JobID: {},
|
||||
parent.Run.JobID: {Strategy: parent.Run.Job().Strategy},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -81,7 +97,7 @@ func newCompositeRunContext(ctx context.Context, parent *RunContext, step action
|
||||
Parent: parent,
|
||||
EventJSON: parent.EventJSON,
|
||||
}
|
||||
compositerc.setActionEnv(env)
|
||||
compositerc.setCompositeActionEnv(env)
|
||||
compositerc.ExprEval = compositerc.NewExpressionEvaluator(ctx)
|
||||
|
||||
return compositerc
|
||||
@@ -131,7 +147,7 @@ func execAsComposite(step actionStep) common.Executor {
|
||||
// repeated composite actions grow rc.Masks exponentially.
|
||||
rc.Masks = appendUniqueMasks(rc.Masks, compositeRC.Masks)
|
||||
rc.ExtraPath = compositeRC.ExtraPath
|
||||
// compositeRC.Env is dirty, contains INPUT_ and merged step env, only rely on compositeRC.GlobalEnv
|
||||
// Propagate GlobalEnv only, so composite inputs and step-local values do not escape.
|
||||
mergeIntoMap := mergeIntoMapCaseSensitive
|
||||
if rc.JobContainer.IsEnvironmentCaseInsensitive() {
|
||||
mergeIntoMap = mergeIntoMapCaseInsensitive
|
||||
@@ -194,6 +210,7 @@ func (rc *RunContext) compositeExecutor(action *model.Action) *compositeSteps {
|
||||
}
|
||||
|
||||
steps = append(steps, common.JobError)
|
||||
preSteps = append(preSteps, common.JobError)
|
||||
return &compositeSteps{
|
||||
pre: func(ctx context.Context) error {
|
||||
return common.NewPipelineExecutor(preSteps...)(common.WithJobErrorContainer(ctx))
|
||||
|
||||
Reference in New Issue
Block a user