Files
act_runner/act/runner/step_factory.go
silverwind 1d6b45bb65 feat: add runner.action_replacements to rewrite step uses (#1417)
Adds `runner.action_replacements`, regex rules that rewrite the `uses` of steps before they run. This keeps commits with `uses: builtin:checkout` buildable after the builtin actions were removed, and also allows redirecting actions to a mirror. Each regex must match the whole `uses`, `${1}` refers to a group, and rules apply in order.

Refs: https://gitea.com/gitea/runner/pulls/1407#issuecomment-1869470

_Written by Claude (Opus 5.5)._
Reviewed-on: https://gitea.com/gitea/runner/pulls/1417
Reviewed-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <2021+silverwind@noreply.gitea.com>
2026-11-22 10:18:04 +00:00

54 lines
1.4 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 (
"fmt"
"gitea.dev/actionslib/pkg/model"
)
type stepFactory interface {
newStep(step *model.Step, rc *RunContext) (step, error)
}
type stepFactoryImpl struct{}
func (sf *stepFactoryImpl) newStep(stepModel *model.Step, rc *RunContext) (step, error) {
if stepModel.Uses != "" && stepModel.Run == "" && rc.Config.ReplaceUses != nil {
stepModel.Uses = rc.Config.ReplaceUses(stepModel.Uses)
}
switch stepModel.Type() {
case model.StepTypeInvalid:
return nil, fmt.Errorf("invalid run/uses syntax for job:%s step:%+v", rc.Name, stepModel)
case model.StepTypeRun:
return &stepRun{
Step: stepModel,
RunContext: rc,
}, nil
case model.StepTypeUsesActionLocal:
return &stepActionLocal{
Step: stepModel,
RunContext: rc,
readAction: readActionImpl,
runAction: runActionImpl,
}, nil
case model.StepTypeUsesActionRemote:
return &stepActionRemote{
Step: stepModel,
RunContext: rc,
readAction: readActionImpl,
runAction: runActionImpl,
}, nil
case model.StepTypeUsesDockerURL:
return &stepDocker{
Step: stepModel,
RunContext: rc,
}, nil
}
return nil, fmt.Errorf("unable to determine how to run job:%s step:%+v", rc.Name, stepModel)
}