mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-06 00:44:22 +02:00
Compare commits
1 Commits
fix/563-pu
...
fix/762-re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3879f14d89 |
@@ -366,7 +366,6 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
|||||||
} else if t := task.Secrets["GITHUB_TOKEN"]; t != "" {
|
} else if t := task.Secrets["GITHUB_TOKEN"]; t != "" {
|
||||||
preset.Token = t
|
preset.Token = t
|
||||||
}
|
}
|
||||||
applyPullRequestTargetCheckoutContext(preset)
|
|
||||||
|
|
||||||
if actionsIDTokenRequestURL := taskContext["actions_id_token_request_url"].GetStringValue(); actionsIDTokenRequestURL != "" {
|
if actionsIDTokenRequestURL := taskContext["actions_id_token_request_url"].GetStringValue(); actionsIDTokenRequestURL != "" {
|
||||||
envs["ACTIONS_ID_TOKEN_REQUEST_URL"] = actionsIDTokenRequestURL
|
envs["ACTIONS_ID_TOKEN_REQUEST_URL"] = actionsIDTokenRequestURL
|
||||||
@@ -575,41 +574,6 @@ func postInternalCache(url, secret string, body map[string]string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyPullRequestTargetCheckoutContext(preset *model.GithubContext) {
|
|
||||||
if preset == nil || preset.EventName != "pull_request_target" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
headSHA := nestedString(preset.Event, "pull_request", "head", "sha")
|
|
||||||
if headSHA == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
preset.Sha = headSHA
|
|
||||||
preset.Ref = headSHA
|
|
||||||
if headRef := nestedString(preset.Event, "pull_request", "head", "ref"); headRef != "" {
|
|
||||||
preset.HeadRef = headRef
|
|
||||||
preset.RefName = headRef
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func nestedString(m map[string]any, keys ...string) string {
|
|
||||||
var current any = m
|
|
||||||
for _, key := range keys {
|
|
||||||
next, ok := current.(map[string]any)
|
|
||||||
if !ok {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
current, ok = next[key]
|
|
||||||
if !ok {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
value := current.(string)
|
|
||||||
if value == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Runner) RunningCount() int64 {
|
func (r *Runner) RunningCount() int64 {
|
||||||
return r.runningCount.Load()
|
return r.runningCount.Load()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/model"
|
|
||||||
clientmocks "gitea.com/gitea/runner/internal/pkg/client/mocks"
|
clientmocks "gitea.com/gitea/runner/internal/pkg/client/mocks"
|
||||||
"gitea.com/gitea/runner/internal/pkg/config"
|
"gitea.com/gitea/runner/internal/pkg/config"
|
||||||
"gitea.com/gitea/runner/internal/pkg/ver"
|
"gitea.com/gitea/runner/internal/pkg/ver"
|
||||||
@@ -93,67 +92,6 @@ func TestNewRunnerInitializesLabelsAndEnvironment(t *testing.T) {
|
|||||||
require.Nil(t, r.cacheHandler)
|
require.Nil(t, r.cacheHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestApplyPullRequestTargetCheckoutContextUsesHeadSHA(t *testing.T) {
|
|
||||||
preset := &model.GithubContext{
|
|
||||||
EventName: "pull_request_target",
|
|
||||||
Sha: "base-sha",
|
|
||||||
Ref: "refs/heads/main",
|
|
||||||
RefName: "main",
|
|
||||||
HeadRef: "feature",
|
|
||||||
Event: map[string]any{
|
|
||||||
"pull_request": map[string]any{
|
|
||||||
"head": map[string]any{
|
|
||||||
"sha": "head-sha",
|
|
||||||
"ref": "contributor-branch",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
applyPullRequestTargetCheckoutContext(preset)
|
|
||||||
|
|
||||||
require.Equal(t, "head-sha", preset.Sha)
|
|
||||||
require.Equal(t, "head-sha", preset.Ref)
|
|
||||||
require.Equal(t, "contributor-branch", preset.RefName)
|
|
||||||
require.Equal(t, "contributor-branch", preset.HeadRef)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestApplyPullRequestTargetCheckoutContextNoOpsWithoutHeadSHA(t *testing.T) {
|
|
||||||
preset := &model.GithubContext{
|
|
||||||
EventName: "pull_request_target",
|
|
||||||
Sha: "base-sha",
|
|
||||||
Ref: "refs/heads/main",
|
|
||||||
RefName: "main",
|
|
||||||
Event: map[string]any{},
|
|
||||||
}
|
|
||||||
|
|
||||||
applyPullRequestTargetCheckoutContext(preset)
|
|
||||||
|
|
||||||
require.Equal(t, "base-sha", preset.Sha)
|
|
||||||
require.Equal(t, "refs/heads/main", preset.Ref)
|
|
||||||
require.Equal(t, "main", preset.RefName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestApplyPullRequestTargetCheckoutContextNoOpsForOtherEvents(t *testing.T) {
|
|
||||||
preset := &model.GithubContext{
|
|
||||||
EventName: "pull_request",
|
|
||||||
Sha: "merge-sha",
|
|
||||||
Ref: "refs/pull/1/merge",
|
|
||||||
Event: map[string]any{
|
|
||||||
"pull_request": map[string]any{
|
|
||||||
"head": map[string]any{
|
|
||||||
"sha": "head-sha",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
applyPullRequestTargetCheckoutContext(preset)
|
|
||||||
|
|
||||||
require.Equal(t, "merge-sha", preset.Sha)
|
|
||||||
require.Equal(t, "refs/pull/1/merge", preset.Ref)
|
|
||||||
}
|
|
||||||
|
|
||||||
func taskWithDefaultActionsURL(url string) *runnerv1.Task {
|
func taskWithDefaultActionsURL(url string) *runnerv1.Task {
|
||||||
return &runnerv1.Task{
|
return &runnerv1.Task{
|
||||||
Context: &structpb.Struct{
|
Context: &structpb.Struct{
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ runner:
|
|||||||
# The maximum interval for fetching the job from the Gitea instance.
|
# The maximum interval for fetching the job from the Gitea instance.
|
||||||
# The runner uses exponential backoff when idle, increasing the interval up to this maximum.
|
# The runner uses exponential backoff when idle, increasing the interval up to this maximum.
|
||||||
# Set to 0 or same as fetch_interval to disable backoff.
|
# Set to 0 or same as fetch_interval to disable backoff.
|
||||||
fetch_interval_max: 5s
|
fetch_interval_max: 1m
|
||||||
# While idle, remove stale bind-workdir task directories and orphaned host-mode
|
# While idle, remove stale bind-workdir task directories and orphaned host-mode
|
||||||
# scratch directories (left behind when a host cleanup delete stalls) older than
|
# scratch directories (left behind when a host cleanup delete stalls) older than
|
||||||
# this duration. Setting either workdir_cleanup_age or idle_cleanup_interval to 0
|
# this duration. Setting either workdir_cleanup_age or idle_cleanup_interval to 0
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ func LoadDefault(file string) (*Config, error) {
|
|||||||
cfg.Runner.FetchInterval = 2 * time.Second
|
cfg.Runner.FetchInterval = 2 * time.Second
|
||||||
}
|
}
|
||||||
if cfg.Runner.FetchIntervalMax <= 0 {
|
if cfg.Runner.FetchIntervalMax <= 0 {
|
||||||
cfg.Runner.FetchIntervalMax = 5 * time.Second
|
cfg.Runner.FetchIntervalMax = time.Minute
|
||||||
}
|
}
|
||||||
if cfg.Runner.WorkdirCleanupAge == 0 && !definedRunnerKeys["workdir_cleanup_age"] {
|
if cfg.Runner.WorkdirCleanupAge == 0 && !definedRunnerKeys["workdir_cleanup_age"] {
|
||||||
cfg.Runner.WorkdirCleanupAge = 24 * time.Hour
|
cfg.Runner.WorkdirCleanupAge = 24 * time.Hour
|
||||||
|
|||||||
@@ -48,6 +48,12 @@ func TestLoadDefault_DefaultsWorkdirCleanupAge(t *testing.T) {
|
|||||||
assert.Equal(t, 10*time.Minute, cfg.Runner.IdleCleanupInterval)
|
assert.Equal(t, 10*time.Minute, cfg.Runner.IdleCleanupInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadDefault_DefaultsIdleFetchBackoffMax(t *testing.T) {
|
||||||
|
cfg, err := LoadDefault("")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, time.Minute, cfg.Runner.FetchIntervalMax)
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadDefault_UsesConfiguredWorkdirCleanupAge(t *testing.T) {
|
func TestLoadDefault_UsesConfiguredWorkdirCleanupAge(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
path := filepath.Join(dir, "config.yaml")
|
path := filepath.Join(dir, "config.yaml")
|
||||||
|
|||||||
Reference in New Issue
Block a user