mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-06 00:44:22 +02:00
Compare commits
4 Commits
eeb479ea89
...
fix/563-pu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4034634340 | ||
|
|
4691a92ea8 | ||
|
|
0ee4643d4a | ||
|
|
e774003c18 |
@@ -17,14 +17,14 @@ RUN make clean && make build
|
||||
### DIND VARIANT
|
||||
#
|
||||
#
|
||||
FROM docker:29.6.0-dind AS dind
|
||||
FROM docker:29.6.1-dind AS dind
|
||||
|
||||
ARG VERSION=dev
|
||||
|
||||
LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
||||
LABEL org.opencontainers.image.version="${VERSION}"
|
||||
|
||||
RUN apk add --no-cache s6 bash git tzdata
|
||||
RUN apk add --no-cache s6 bash git tzdata nftables
|
||||
|
||||
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
||||
COPY scripts/run.sh /usr/local/bin/run.sh
|
||||
@@ -37,7 +37,7 @@ ENTRYPOINT ["s6-svscan","/etc/s6"]
|
||||
### DIND-ROOTLESS VARIANT
|
||||
#
|
||||
#
|
||||
FROM docker:29.6.0-dind-rootless AS dind-rootless
|
||||
FROM docker:29.6.1-dind-rootless AS dind-rootless
|
||||
|
||||
ARG VERSION=dev
|
||||
|
||||
@@ -45,7 +45,7 @@ LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
||||
LABEL org.opencontainers.image.version="${VERSION}"
|
||||
|
||||
USER root
|
||||
RUN apk add --no-cache s6 bash git tzdata
|
||||
RUN apk add --no-cache s6 bash git tzdata nftables
|
||||
|
||||
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
||||
COPY scripts/run.sh /usr/local/bin/run.sh
|
||||
|
||||
@@ -366,6 +366,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
||||
} else if t := task.Secrets["GITHUB_TOKEN"]; t != "" {
|
||||
preset.Token = t
|
||||
}
|
||||
applyPullRequestTargetCheckoutContext(preset)
|
||||
|
||||
if actionsIDTokenRequestURL := taskContext["actions_id_token_request_url"].GetStringValue(); actionsIDTokenRequestURL != "" {
|
||||
envs["ACTIONS_ID_TOKEN_REQUEST_URL"] = actionsIDTokenRequestURL
|
||||
@@ -574,6 +575,41 @@ func postInternalCache(url, secret string, body map[string]string) error {
|
||||
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 {
|
||||
return r.runningCount.Load()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"gitea.com/gitea/runner/act/model"
|
||||
clientmocks "gitea.com/gitea/runner/internal/pkg/client/mocks"
|
||||
"gitea.com/gitea/runner/internal/pkg/config"
|
||||
"gitea.com/gitea/runner/internal/pkg/ver"
|
||||
@@ -92,6 +93,67 @@ func TestNewRunnerInitializesLabelsAndEnvironment(t *testing.T) {
|
||||
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 {
|
||||
return &runnerv1.Task{
|
||||
Context: &structpb.Struct{
|
||||
|
||||
Reference in New Issue
Block a user