mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-13 22:41:54 +02:00
feat: support $/ prefix in action uses: (#1150)
Accepts GitHub's `$/` self-repository prefix in a step `uses:`. It resolves to the repository holding the file that wrote the `uses:`, at the ref being run, with no checkout. Inside a composite action that is the enclosing action, otherwise the workflow's own repo and commit. The action cache is keyed on the resolved reference for these, because the same `$/x` names a different action per enclosing repository. Related PR for job-level support: https://github.com/go-gitea/gitea/pull/38822 Reviewed-on: https://gitea.com/gitea/runner/pulls/1150 Reviewed-by: Zettat123 <[email protected]> Co-authored-by: silverwind <[email protected]>
This commit is contained in:
@@ -653,6 +653,8 @@ func TestStepActionRemotePost(t *testing.T) {
|
||||
},
|
||||
Step: tt.stepModel,
|
||||
action: tt.actionModel,
|
||||
// post only ever runs after prepareActionExecutor resolved the action
|
||||
remoteAction: newRemoteAction(tt.stepModel.Uses),
|
||||
}
|
||||
sar.RunContext.ExprEval = sar.RunContext.NewExpressionEvaluator(ctx)
|
||||
|
||||
@@ -821,6 +823,73 @@ func Test_newRemoteAction(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_newSelfRepoAction(t *testing.T) {
|
||||
workflow := &model.GithubContext{
|
||||
ServerURL: "https://gitea.example.com",
|
||||
Repository: "owner/workflow-repo",
|
||||
Sha: "abc123",
|
||||
}
|
||||
composite := &model.GithubContext{
|
||||
ServerURL: "https://gitea.example.com",
|
||||
Repository: "owner/workflow-repo",
|
||||
Sha: "abc123",
|
||||
ActionRepository: "other/action-repo",
|
||||
ActionRef: "v1",
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
action string
|
||||
github *model.GithubContext
|
||||
want *remoteAction
|
||||
}{
|
||||
{
|
||||
name: "top level resolves to the workflow repo at its commit",
|
||||
action: "$/.gitea/actions/build",
|
||||
github: workflow,
|
||||
want: &remoteAction{
|
||||
URL: "https://gitea.example.com",
|
||||
Org: "owner",
|
||||
Repo: "workflow-repo",
|
||||
Path: ".gitea/actions/build",
|
||||
Ref: "abc123",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "inside a composite resolves to the enclosing action",
|
||||
action: "$/.gitea/actions/build",
|
||||
github: composite,
|
||||
want: &remoteAction{
|
||||
URL: "https://gitea.example.com",
|
||||
Org: "other",
|
||||
Repo: "action-repo",
|
||||
Path: ".gitea/actions/build",
|
||||
Ref: "v1",
|
||||
},
|
||||
},
|
||||
{name: "empty path", action: "$/", github: workflow},
|
||||
{name: "ref suffix is not allowed", action: "$/.gitea/actions/build@v1", github: workflow},
|
||||
{name: "path traversal", action: "$/../escape", github: workflow},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, newSelfRepoAction(tt.action, tt.github))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_stepActionRemoteSelfRepoActionDir(t *testing.T) {
|
||||
dirFor := func(repo string) string {
|
||||
sar := &stepActionRemote{
|
||||
Step: &model.Step{Uses: "$/.gitea/actions/build"},
|
||||
RunContext: &RunContext{Config: &Config{ActionCacheDir: "/cache"}},
|
||||
remoteAction: &remoteAction{Org: "owner", Repo: repo, Ref: "v1"},
|
||||
}
|
||||
return sar.actionDir()
|
||||
}
|
||||
// The same `$/x` in two repos must not share a cache directory.
|
||||
assert.NotEqual(t, dirFor("one"), dirFor("two"))
|
||||
}
|
||||
|
||||
func Test_remoteActionReference(t *testing.T) {
|
||||
tests := []struct {
|
||||
uses string
|
||||
|
||||
Reference in New Issue
Block a user