mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-01 12:26:36 +00:00
A docker action can declare `runs.pre-entrypoint` and `runs.post-entrypoint` next to `runs.entrypoint` — the docker equivalent of a javascript action's `runs.pre`/`runs.post`. Neither key existed on `ActionRuns`, so the YAML decoder dropped them and docker actions silently skipped their setup and cleanup stages. Only the entrypoint is stage specific. [`ContainerActionHandler`](https://github.com/actions/runner/blob/main/src/Runner.Worker/Handlers/ContainerActionHandler.cs) selects `Data.Pre`/`Data.Post` per stage but evaluates `runs.args` and `runs.env` unconditionally, so `docker create` receives the action's args and env on every stage. The `entrypoint` input stays main only, because it is read inside the main branch. The stage is carried as the existing `stepStage` value rather than a separate parameter, and the pre and post stages reuse the action path resolution that `runPreStep`/`runPostStep` already open-coded three times, so the diff also drops those copies. Known gap: `stepActionLocal.pre()` is a no-op for every `using`, so `pre-entrypoint` does not run for `uses: ./local-action` while `post-entrypoint` does. Closing it requires reading the action model before the main stage and adding a pre case to `getIfExpression` for `pre-if`, which also changes local node, go and composite actions — better as its own change. --------- Co-authored-by: silverwind <2021+silverwind@noreply.gitea.com> Co-authored-by: silverwind <me@silverwind.io> Reviewed-on: https://gitea.com/gitea/runner/pulls/1106 Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com> Co-authored-by: bircni <bircni@icloud.com>
83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package model
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadActionDefaultsAndCaseInsensitiveUsing(t *testing.T) {
|
|
action, err := ReadAction(strings.NewReader(`
|
|
name: example
|
|
runs:
|
|
using: NoDe24
|
|
main: dist/index.js
|
|
`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if action.Runs.Using != ActionRunsUsingNode24 {
|
|
t.Fatalf("using = %q, want %q", action.Runs.Using, ActionRunsUsingNode24)
|
|
}
|
|
if action.Runs.PreIf != "always()" {
|
|
t.Fatalf("pre-if = %q, want always()", action.Runs.PreIf)
|
|
}
|
|
if action.Runs.PostIf != "always()" {
|
|
t.Fatalf("post-if = %q, want always()", action.Runs.PostIf)
|
|
}
|
|
}
|
|
|
|
func TestReadActionPreservesExplicitConditions(t *testing.T) {
|
|
action, err := ReadAction(strings.NewReader(`
|
|
runs:
|
|
using: composite
|
|
pre-if: success()
|
|
post-if: failure()
|
|
steps:
|
|
- run: echo hello
|
|
`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if action.Runs.PreIf != "success()" || action.Runs.PostIf != "failure()" {
|
|
t.Fatalf("conditions = %q/%q, want explicit values", action.Runs.PreIf, action.Runs.PostIf)
|
|
}
|
|
if !action.Runs.Using.IsComposite() || action.Runs.Using.IsDocker() || action.Runs.Using.IsNode() {
|
|
t.Fatalf("unexpected using predicates for %q", action.Runs.Using)
|
|
}
|
|
}
|
|
|
|
func TestReadActionRejectsUnknownUsing(t *testing.T) {
|
|
_, err := ReadAction(strings.NewReader(`
|
|
runs:
|
|
using: node99
|
|
`))
|
|
if err == nil {
|
|
t.Fatal("expected unknown runs.using to fail")
|
|
}
|
|
if !strings.Contains(err.Error(), "node99") {
|
|
t.Fatalf("error = %q, want invalid value", err)
|
|
}
|
|
}
|
|
|
|
func TestReadActionDockerEntrypoints(t *testing.T) {
|
|
action, err := ReadAction(strings.NewReader(`
|
|
runs:
|
|
using: docker
|
|
image: Dockerfile
|
|
pre-entrypoint: pre.sh
|
|
post-entrypoint: post.sh
|
|
`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if action.Runs.PreEntrypoint != "pre.sh" {
|
|
t.Fatalf("pre-entrypoint = %q, want pre.sh", action.Runs.PreEntrypoint)
|
|
}
|
|
if action.Runs.PostEntrypoint != "post.sh" {
|
|
t.Fatalf("post-entrypoint = %q, want post.sh", action.Runs.PostEntrypoint)
|
|
}
|
|
}
|