mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-19 06:13:43 +00:00
Compare commits
9
Commits
0093731295
...
v5.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb6d793cb9 | ||
|
|
95ef17d022 | ||
|
|
ee03687688 | ||
|
|
30e600d8f6 | ||
|
|
664978c819 | ||
|
|
aa56f46c89 | ||
|
|
7a9fccb842 | ||
|
|
7d6e1ff021 | ||
|
|
319567213d |
No files matched your search
@@ -34,6 +34,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
go-version-file: "go.mod"
|
go-version-file: "go.mod"
|
||||||
check-latest: true
|
check-latest: true
|
||||||
|
- name: Import GPG key
|
||||||
|
id: import_gpg
|
||||||
|
uses: crazy-max/ghaction-import-gpg@2dc316deee8e90f13e1a351ab510b4d5bc0c82cd # v7
|
||||||
|
with:
|
||||||
|
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||||
|
passphrase: ${{ secrets.PASSPHRASE }}
|
||||||
|
fingerprint: CC64B1DB67ABBEECAB24B6455FC346329753F4B0
|
||||||
- name: goreleaser
|
- name: goreleaser
|
||||||
uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7
|
uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7
|
||||||
with:
|
with:
|
||||||
@@ -47,6 +54,7 @@ jobs:
|
|||||||
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
||||||
GORELEASER_FORCE_TOKEN: "gitea"
|
GORELEASER_FORCE_TOKEN: "gitea"
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
|
||||||
|
|
||||||
release-image:
|
release-image:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ builds:
|
|||||||
publishers:
|
publishers:
|
||||||
- name: cloudflare-r2
|
- name: cloudflare-r2
|
||||||
checksum: true
|
checksum: true
|
||||||
|
signature: true
|
||||||
extra_files:
|
extra_files:
|
||||||
- glob: ./**.xz
|
- glob: ./**.xz
|
||||||
- glob: ./**.sha256
|
- glob: ./**.sha256
|
||||||
@@ -100,6 +101,10 @@ checksum:
|
|||||||
extra_files:
|
extra_files:
|
||||||
- glob: ./**.xz
|
- glob: ./**.xz
|
||||||
|
|
||||||
|
signs:
|
||||||
|
- artifacts: checksum
|
||||||
|
args: ["--batch", "-u", "{{ .Env.GPG_FINGERPRINT }}", "--output", "${signature}", "--detach-sign", "${artifact}"]
|
||||||
|
|
||||||
snapshot:
|
snapshot:
|
||||||
version_template: "{{ .Branch }}-devel"
|
version_template: "{{ .Branch }}-devel"
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -23,11 +23,14 @@ depending on the prefix:
|
|||||||
covers both forms: it escapes `%` first, so a literal `%3B` becomes `%253B` that the extra
|
covers both forms: it escapes `%` first, so a literal `%3B` becomes `%253B` that the extra
|
||||||
`##[…]` rules cannot match, and a raw `;` or `]` is never decoded. It is also what makes
|
`##[…]` rules cannot match, and a raw `;` or `]` is never decoded. It is also what makes
|
||||||
multi-line work, `\n` becomes `%0A` and the UI turns it back into a line break.
|
multi-line work, `\n` becomes `%0A` and the UI turns it back into a line break.
|
||||||
- **Forwarding a command from step output?** Leave the payload alone, it arrived escaped and is
|
- **Forwarding a command from step output?** Preserve its escaping unless masking changes it.
|
||||||
decoded once. Decoding here double-decodes and destroys multi-line.
|
Decoding for display happens in the UI.
|
||||||
- **No prefix?** Do not escape, and split multi-line values into one row each.
|
- **No prefix?** Do not escape, and split multi-line values into one row each.
|
||||||
- **Interpolating a secret?** Masking runs after escaping, so `AppendSecretMasker` registers the
|
- **Interpolating a secret?** Masking runs after escaping. Recognised command payloads are
|
||||||
encoded forms too.
|
normalised before masking to cover partially escaped values. Their original escaping is
|
||||||
|
preserved when no replacement occurs. `AppendSecretMasker` also registers encoded forms for
|
||||||
|
other output. Complete nonblank one-character values are masked, while one-byte fragments
|
||||||
|
of multiline values are skipped.
|
||||||
- Command *properties* also escape `%3A` and `%2C`, which the UI never decodes, so the command
|
- Command *properties* also escape `%3A` and `%2C`, which the UI never decodes, so the command
|
||||||
handler folds an annotation's location into its decoded message and escapes the result again.
|
handler folds an annotation's location into its decoded message and escapes the result again.
|
||||||
|
|
||||||
|
|||||||
+7
-5
@@ -19,14 +19,15 @@ RUN --mount=type=cache,target=/go/pkg/mod \
|
|||||||
### DIND VARIANT
|
### DIND VARIANT
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
FROM docker:29.9.2-dind AS dind
|
FROM docker:29.9.3-dind AS dind
|
||||||
|
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
||||||
LABEL org.opencontainers.image.version="${VERSION}"
|
LABEL org.opencontainers.image.version="${VERSION}"
|
||||||
|
|
||||||
RUN apk add --no-cache s6 bash git tzdata nftables
|
# upgrade first: the docker base image can lag behind Alpine security fixes
|
||||||
|
RUN apk upgrade --no-cache && apk add --no-cache s6 bash git tzdata nftables
|
||||||
|
|
||||||
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
||||||
COPY scripts/run.sh /usr/local/bin/run.sh
|
COPY scripts/run.sh /usr/local/bin/run.sh
|
||||||
@@ -41,7 +42,7 @@ ENTRYPOINT ["s6-svscan","/etc/s6"]
|
|||||||
### DIND-ROOTLESS VARIANT
|
### DIND-ROOTLESS VARIANT
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
FROM docker:29.9.2-dind-rootless AS dind-rootless
|
FROM docker:29.9.3-dind-rootless AS dind-rootless
|
||||||
|
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
|
|
||||||
@@ -49,7 +50,8 @@ LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
|||||||
LABEL org.opencontainers.image.version="${VERSION}"
|
LABEL org.opencontainers.image.version="${VERSION}"
|
||||||
|
|
||||||
USER root
|
USER root
|
||||||
RUN apk add --no-cache s6 bash git tzdata nftables
|
# upgrade first: the docker base image can lag behind Alpine security fixes
|
||||||
|
RUN apk upgrade --no-cache && apk add --no-cache s6 bash git tzdata nftables
|
||||||
|
|
||||||
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
||||||
COPY scripts/run.sh /usr/local/bin/run.sh
|
COPY scripts/run.sh /usr/local/bin/run.sh
|
||||||
@@ -75,7 +77,7 @@ ARG VERSION=dev
|
|||||||
LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
||||||
LABEL org.opencontainers.image.version="${VERSION}"
|
LABEL org.opencontainers.image.version="${VERSION}"
|
||||||
|
|
||||||
RUN apk add --no-cache tini bash git tzdata
|
RUN apk upgrade --no-cache && apk add --no-cache tini bash git tzdata
|
||||||
|
|
||||||
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
||||||
COPY scripts/run.sh /usr/local/bin/run.sh
|
COPY scripts/run.sh /usr/local/bin/run.sh
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ The recommended Docker-in-Docker image runs its own Docker daemon for jobs. Jobs
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --privileged -e GITEA_INSTANCE_URL=https://your_gitea.com -e GITEA_RUNNER_REGISTRATION_TOKEN=<your_token> \
|
docker run --privileged -e GITEA_INSTANCE_URL=https://your_gitea.com -e GITEA_RUNNER_REGISTRATION_TOKEN=<your_token> \
|
||||||
-v "$PWD/data:/data" -v runner-docker:/var/lib/docker --name my_runner gitea/runner:nightly-dind
|
-v "$PWD/data:/data" -v runner-docker:/var/lib/docker --name my_runner gitea/runner:latest-dind
|
||||||
```
|
```
|
||||||
|
|
||||||
The volumes keep the registration and the image cache across container recreation. The image reads more variables, such as `GITEA_RUNNER_LABELS` and `CONFIG_FILE`, see [scripts/run.sh](scripts/run.sh) and the [Docker example](examples/docker/README.md).
|
The volumes keep the registration and the image cache across container recreation. The image reads more variables, such as `GITEA_RUNNER_LABELS` and `CONFIG_FILE`, see [scripts/run.sh](scripts/run.sh) and the [Docker example](examples/docker/README.md).
|
||||||
@@ -243,7 +243,7 @@ volumes:
|
|||||||
- ${GITEA_DOCKER_WORKSPACE:-.}/data:/app/data
|
- ${GITEA_DOCKER_WORKSPACE:-.}/data:/app/data
|
||||||
```
|
```
|
||||||
|
|
||||||
In most Linux container jobs, the containers, networks and volumes a job creates are removed when it ends, `docker compose` services included. Set `container.sweep: false` if jobs deploy services to the runner's Docker daemon.
|
Set `container.sweep: true` to remove the containers, networks and volumes most Linux container jobs create when they end, `docker compose` services included. Leave it off if jobs deploy services to the runner's Docker daemon.
|
||||||
|
|
||||||
### Built-in actions (`uses: builtin:<name>`)
|
### Built-in actions (`uses: builtin:<name>`)
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,8 @@ type Handler struct {
|
|||||||
stopSync context.CancelFunc
|
stopSync context.CancelFunc
|
||||||
syncing sync.WaitGroup
|
syncing sync.WaitGroup
|
||||||
|
|
||||||
outboundIP string
|
outboundIP string
|
||||||
|
instanceTransport http.RoundTripper
|
||||||
|
|
||||||
// internalSecret guards /_internal/{register,revoke}. When set, a remote
|
// internalSecret guards /_internal/{register,revoke}. When set, a remote
|
||||||
// runner can use these endpoints to pre-register per-job
|
// runner can use these endpoints to pre-register per-job
|
||||||
@@ -143,19 +144,21 @@ type Options struct {
|
|||||||
// in-process RegisterJob method directly.
|
// in-process RegisterJob method directly.
|
||||||
InternalSecret string
|
InternalSecret string
|
||||||
|
|
||||||
Policy Policy
|
Policy Policy
|
||||||
Logger *logging.Logger
|
Logger *logging.Logger
|
||||||
|
InstanceTransport http.RoundTripper // reaches the instance artifact requests are forwarded to, nil for http.DefaultTransport
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartHandler starts an embedded cache or forwards cache requests to Upstream.
|
// StartHandler starts an embedded cache or forwards cache requests to Upstream.
|
||||||
func StartHandler(opts Options) (*Handler, error) {
|
func StartHandler(opts Options) (*Handler, error) {
|
||||||
dir, logger := opts.Dir, opts.Logger
|
dir, logger := opts.Dir, opts.Logger
|
||||||
h := &Handler{
|
h := &Handler{
|
||||||
creds: make(map[string]*credEntry),
|
creds: make(map[string]*credEntry),
|
||||||
internalSecret: opts.InternalSecret,
|
internalSecret: opts.InternalSecret,
|
||||||
policy: opts.Policy.withDefaults(),
|
policy: opts.Policy.withDefaults(),
|
||||||
freeDisk: disk.FreeBytes,
|
freeDisk: disk.FreeBytes,
|
||||||
dbLock: make(chan struct{}, 1),
|
dbLock: make(chan struct{}, 1),
|
||||||
|
instanceTransport: opts.InstanceTransport,
|
||||||
}
|
}
|
||||||
|
|
||||||
if logger == nil {
|
if logger == nil {
|
||||||
|
|||||||
@@ -851,6 +851,9 @@ func TestHandler_touchCacheSkipsFreshCompletedEntries(t *testing.T) {
|
|||||||
func newTestHandler(t *testing.T, policy Policy, entries ...*Cache) *Handler {
|
func newTestHandler(t *testing.T, policy Policy, entries ...*Cache) *Handler {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
handler := startTestHandler(t, Options{Policy: policy})
|
handler := startTestHandler(t, Options{Policy: policy})
|
||||||
|
if len(entries) == 0 {
|
||||||
|
return handler
|
||||||
|
}
|
||||||
|
|
||||||
db, err := handler.openDB()
|
db, err := handler.openDB()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -940,6 +943,10 @@ func TestHandler_RejectsBearer(t *testing.T) {
|
|||||||
|
|
||||||
func TestHandler_UnregisterRevokes(t *testing.T) {
|
func TestHandler_UnregisterRevokes(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
handler, err := StartHandler(Options{Dir: filepath.Join(t.TempDir(), "artifactcache")})
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer handler.Close()
|
||||||
|
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
token string
|
token string
|
||||||
@@ -950,9 +957,6 @@ func TestHandler_UnregisterRevokes(t *testing.T) {
|
|||||||
{"reference counted", "shared", "v", 2},
|
{"reference counted", "shared", "v", 2},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
handler, err := StartHandler(Options{Dir: filepath.Join(t.TempDir(), "artifactcache")})
|
|
||||||
require.NoError(t, err)
|
|
||||||
defer handler.Close()
|
|
||||||
revokers := make([]func(), tc.registrations)
|
revokers := make([]func(), tc.registrations)
|
||||||
for i := range revokers {
|
for i := range revokers {
|
||||||
revokers[i] = handler.RegisterJob(tc.token, JobCredential{Repo: testRepo})
|
revokers[i] = handler.RegisterJob(tc.token, JobCredential{Repo: testRepo})
|
||||||
@@ -1049,9 +1053,8 @@ func TestHandler_ArtifactSignature(t *testing.T) {
|
|||||||
|
|
||||||
base := handler.ExternalURL() + apiPath
|
base := handler.ExternalURL() + apiPath
|
||||||
good := signArtifactURL(handler, 1)
|
good := signArtifactURL(handler, 1)
|
||||||
other, err := StartHandler(Options{Dir: filepath.Join(t.TempDir(), "artifactcache2")})
|
secret := bytes.Clone(handler.secret)
|
||||||
require.NoError(t, err)
|
secret[0] ^= 1
|
||||||
defer other.Close()
|
|
||||||
|
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
@@ -1060,7 +1063,7 @@ func TestHandler_ArtifactSignature(t *testing.T) {
|
|||||||
{"missing signature", fmt.Sprintf("%s/artifacts/%d", base, 1)},
|
{"missing signature", fmt.Sprintf("%s/artifacts/%d", base, 1)},
|
||||||
{"tampered signature", good[:len(good)-4] + "dead"},
|
{"tampered signature", good[:len(good)-4] + "dead"},
|
||||||
{"expired signature", handler.signedArtifactURL(JobCredential{}, 1, time.Now().Add(-time.Second))},
|
{"expired signature", handler.signedArtifactURL(JobCredential{}, 1, time.Now().Add(-time.Second))},
|
||||||
{"signature from a different server", base + strings.SplitN(signArtifactURL(other, 1), apiPath, 2)[1]},
|
{"signature from a different server", base + strings.SplitN(signArtifactURL(&Handler{secret: secret}, 1), apiPath, 2)[1]},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
resp, err := testClient.Get(tc.url)
|
resp, err := testClient.Get(tc.url)
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func (h *Handler) forwardOrNotFound(w http.ResponseWriter, r *http.Request) {
|
|||||||
h.twirpError(w, r, twirpInternal, fmt.Errorf("cache server cannot reach the artifact service at %s: %w", target, err))
|
h.twirpError(w, r, twirpInternal, fmt.Errorf("cache server cannot reach the artifact service at %s: %w", target, err))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if cred.InsecureTLS {
|
if proxy.Transport = h.instanceTransport; proxy.Transport == nil && cred.InsecureTLS { // the instance transport carries runner.insecure and the client cert
|
||||||
proxy.Transport = insecureTransport
|
proxy.Transport = insecureTransport
|
||||||
}
|
}
|
||||||
proxy.ServeHTTP(w, r)
|
proxy.ServeHTTP(w, r)
|
||||||
|
|||||||
@@ -133,3 +133,20 @@ func TestFrontResultsService(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFrontResultsServiceForwardsThroughTheInstanceTransport(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
gitea := httptest.NewTLSServer(http.HandlerFunc(func(writer http.ResponseWriter, _request *http.Request) { _, _ = io.WriteString(writer, "{}") }))
|
||||||
|
defer gitea.Close()
|
||||||
|
handler, err := StartHandler(Options{Dir: t.TempDir(), OutboundIP: "127.0.0.1", InstanceTransport: gitea.Client().Transport})
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer handler.Close()
|
||||||
|
defer handler.RegisterJob("token", JobCredential{Results: gitea.URL})()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, handler.ExternalURL()+artifactServicePath+"CreateArtifact", nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
resp, err := (&http.Client{Transport: &bearerTransport{token: "token"}}).Do(req)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@ func TestFetchAction(t *testing.T) {
|
|||||||
|
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
remote := filepath.Join(root, "org", "action")
|
remote := filepath.Join(root, "org", "action")
|
||||||
require.NoError(t, gitCmd("init", "--initial-branch=main", remote))
|
require.NoError(t, os.CopyFS(remote, os.DirFS(filepath.Join(gitFixtureDir, "work"))))
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(remote, "action.yml"), []byte("name: action\n"), 0o644))
|
require.NoError(t, os.WriteFile(filepath.Join(remote, "action.yml"), []byte("name: action\n"), 0o644))
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(remote, "run.sh"), []byte("#!/bin/sh\n"), 0o755))
|
require.NoError(t, os.WriteFile(filepath.Join(remote, "run.sh"), []byte("#!/bin/sh\n"), 0o755))
|
||||||
require.NoError(t, os.Symlink("action.yml", filepath.Join(remote, "link")))
|
require.NoError(t, os.Symlink("action.yml", filepath.Join(remote, "link")))
|
||||||
@@ -53,6 +53,7 @@ func TestFetchAction(t *testing.T) {
|
|||||||
var archiveRequests []http.Header
|
var archiveRequests []http.Header
|
||||||
var mirror *httptest.Server
|
var mirror *httptest.Server
|
||||||
archiveCache := map[string][]byte{}
|
archiveCache := map[string][]byte{}
|
||||||
|
revisions := map[string]string{}
|
||||||
requests, archives, failures := 0, "", 0
|
requests, archives, failures := 0, "", 0
|
||||||
handler := http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
handler := http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
@@ -79,7 +80,14 @@ func TestFetchAction(t *testing.T) {
|
|||||||
http.Redirect(writer, request, mirror.URL+request.URL.Path, http.StatusFound)
|
http.Redirect(writer, request, mirror.URL+request.URL.Path, http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sha, _ := gitOutput(request.Context(), remote, "rev-parse", strings.TrimSuffix(ref, ".tar.gz"))
|
sha, ok := revisions[ref]
|
||||||
|
if !ok {
|
||||||
|
var err error
|
||||||
|
sha, err = gitOutput(request.Context(), remote, "rev-parse", strings.TrimSuffix(ref, ".tar.gz"))
|
||||||
|
if err == nil {
|
||||||
|
revisions[ref] = sha
|
||||||
|
}
|
||||||
|
}
|
||||||
etag := fmt.Sprintf(`W/"%s-tar.gz-%t"`, sha, archives != "unprefixed")
|
etag := fmt.Sprintf(`W/"%s-tar.gz-%t"`, sha, archives != "unprefixed")
|
||||||
if request.Header.Get("If-None-Match") == etag {
|
if request.Header.Get("If-None-Match") == etag {
|
||||||
writer.WriteHeader(http.StatusNotModified)
|
writer.WriteHeader(http.StatusNotModified)
|
||||||
@@ -208,6 +216,9 @@ func TestFetchAction(t *testing.T) {
|
|||||||
require.NoError(t, gitCmd("-C", remote, "commit", "--allow-empty", "-m", "moved"))
|
require.NoError(t, gitCmd("-C", remote, "commit", "--allow-empty", "-m", "moved"))
|
||||||
require.NoError(t, gitCmd("-C", remote, "tag", "--force", "v1"))
|
require.NoError(t, gitCmd("-C", remote, "tag", "--force", "v1"))
|
||||||
expectedSha = gitRevParse(t, remote, "v1")
|
expectedSha = gitRevParse(t, remote, "v1")
|
||||||
|
mu.Lock()
|
||||||
|
clear(revisions)
|
||||||
|
mu.Unlock()
|
||||||
moved, movedSha, err := FetchAction(t.Context(), input)
|
moved, movedSha, err := FetchAction(t.Context(), input)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, expectedSha, movedSha)
|
assert.Equal(t, expectedSha, movedSha)
|
||||||
@@ -253,7 +264,7 @@ func TestFetchAction(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("downloads again over a tree whose files changed size or that has no record, not under a job copying it", func(t *testing.T) {
|
t.Run("downloads again over a tree whose files changed size or that has no record, not under a job copying it", func(t *testing.T) {
|
||||||
sha := gitRevParse(t, remote, "main")
|
sha := expectedSha
|
||||||
for _, mode := range []string{"prefixed", "none"} {
|
for _, mode := range []string{"prefixed", "none"} {
|
||||||
serve(mode, 0)
|
serve(mode, 0)
|
||||||
input := newInput(sha)
|
input := newInput(sha)
|
||||||
|
|||||||
+11
-6
@@ -185,6 +185,7 @@ type NewGitCloneExecutorInput struct {
|
|||||||
// For Gitea
|
// For Gitea
|
||||||
InsecureSkipTLS bool
|
InsecureSkipTLS bool
|
||||||
ClientCertFile, ClientKeyFile string // PEM, absolute as git runs in other directories
|
ClientCertFile, ClientKeyFile string // PEM, absolute as git runs in other directories
|
||||||
|
CAFile string // PEM, absolute, replaces git's CA bundle
|
||||||
Transport http.RoundTripper // for FetchAction's archive downloads, nil for http.DefaultTransport
|
Transport http.RoundTripper // for FetchAction's archive downloads, nil for http.DefaultTransport
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,12 +390,16 @@ func RemoteConfig(token string, insecureSkipTLS bool) []string {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClientCertConfig(prefix, certFile, keyFile, executionOS string) []string {
|
// SSLConfig uses OpenSSL on Windows, as Schannel takes no PEM key and ignores sslCAInfo.
|
||||||
if certFile == "" {
|
func SSLConfig(prefix, certFile, keyFile, caFile, executionOS string) []string {
|
||||||
return nil
|
var config []string
|
||||||
|
if certFile != "" {
|
||||||
|
config = append(config, prefix+"sslCert="+certFile, prefix+"sslKey="+keyFile)
|
||||||
}
|
}
|
||||||
config := []string{prefix + "sslCert=" + certFile, prefix + "sslKey=" + keyFile}
|
if caFile != "" {
|
||||||
if strings.EqualFold(executionOS, "windows") {
|
config = append(config, prefix+"sslCAInfo="+caFile)
|
||||||
|
}
|
||||||
|
if config != nil && strings.EqualFold(executionOS, "windows") {
|
||||||
config = append(config, prefix+"sslBackend=openssl")
|
config = append(config, prefix+"sslBackend=openssl")
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
@@ -457,7 +462,7 @@ func runGitWithStdin(ctx context.Context, dir string, input *NewGitCloneExecutor
|
|||||||
config := []string{"core.autocrlf=false", "core.eol=lf"} // keep action files LF
|
config := []string{"core.autocrlf=false", "core.eol=lf"} // keep action files LF
|
||||||
if input != nil {
|
if input != nil {
|
||||||
config = append(config, RemoteConfig(input.Token, input.InsecureSkipTLS)...)
|
config = append(config, RemoteConfig(input.Token, input.InsecureSkipTLS)...)
|
||||||
config = append(config, ClientCertConfig("http.", input.ClientCertFile, input.ClientKeyFile, runtime.GOOS)...)
|
config = append(config, SSLConfig("http.", input.ClientCertFile, input.ClientKeyFile, input.CAFile, runtime.GOOS)...)
|
||||||
}
|
}
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
args = append([]string{"-C", dir}, args...)
|
args = append([]string{"-C", dir}, args...)
|
||||||
|
|||||||
+34
-40
@@ -54,18 +54,18 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientCertConfig(t *testing.T) {
|
func TestSSLConfig(t *testing.T) {
|
||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
prefix, certFile, executionOS string
|
prefix, certFile, caFile, executionOS string
|
||||||
expected []string
|
expected []string
|
||||||
}{
|
}{
|
||||||
{"http.", "cert.pem", "windows", []string{"http.sslCert=cert.pem", "http.sslKey=key.pem", "http.sslBackend=openssl"}},
|
{"http.https://example.com/.", "cert.pem", "ca.pem", "Windows", []string{"http.https://example.com/.sslCert=cert.pem", "http.https://example.com/.sslKey=key.pem", "http.https://example.com/.sslCAInfo=ca.pem", "http.https://example.com/.sslBackend=openssl"}},
|
||||||
{"http.https://example.com/.", "cert.pem", "Windows", []string{"http.https://example.com/.sslCert=cert.pem", "http.https://example.com/.sslKey=key.pem", "http.https://example.com/.sslBackend=openssl"}},
|
{"http.", "", "ca.pem", "windows", []string{"http.sslCAInfo=ca.pem", "http.sslBackend=openssl"}},
|
||||||
{"http.", "cert.pem", "Linux", []string{"http.sslCert=cert.pem", "http.sslKey=key.pem"}},
|
{"http.", "cert.pem", "ca.pem", "Linux", []string{"http.sslCert=cert.pem", "http.sslKey=key.pem", "http.sslCAInfo=ca.pem"}},
|
||||||
{"http.", "", "Windows", nil},
|
{"http.", "", "", "Windows", nil},
|
||||||
} {
|
} {
|
||||||
t.Run(testcase.prefix+testcase.certFile+testcase.executionOS, func(t *testing.T) {
|
t.Run(testcase.prefix+testcase.certFile+testcase.caFile+testcase.executionOS, func(t *testing.T) {
|
||||||
assert.Equal(t, testcase.expected, ClientCertConfig(testcase.prefix, testcase.certFile, "key.pem", testcase.executionOS))
|
assert.Equal(t, testcase.expected, SSLConfig(testcase.prefix, testcase.certFile, "key.pem", testcase.caFile, testcase.executionOS))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,8 +112,7 @@ func TestFindGitMetadataOfSHA256RepositoryUsesOrigin(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
basedir := t.TempDir()
|
basedir := t.TempDir()
|
||||||
const remoteURL = "https://github.com/owner/repo.git"
|
const remoteURL = "https://github.com/owner/repo.git"
|
||||||
require.NoError(t, gitCmd("init", "--object-format=sha256", "--initial-branch=main", basedir))
|
require.NoError(t, gitCmd("init", "--template=", "--object-format=sha256", "--initial-branch=main", basedir))
|
||||||
require.NoError(t, os.RemoveAll(filepath.Join(basedir, ".git", "hooks")))
|
|
||||||
require.NoError(t, gitCmd("-C", basedir, "commit", "--allow-empty", "-m", "init"))
|
require.NoError(t, gitCmd("-C", basedir, "commit", "--allow-empty", "-m", "init"))
|
||||||
require.NoError(t, gitCmd("-C", basedir, "remote", "add", "origin", remoteURL))
|
require.NoError(t, gitCmd("-C", basedir, "remote", "add", "origin", remoteURL))
|
||||||
require.NoError(t, gitCmd("-C", basedir, "config", "--add", "remote.origin.url", "https://github.com/other/repo.git"))
|
require.NoError(t, gitCmd("-C", basedir, "config", "--add", "remote.origin.url", "https://github.com/other/repo.git"))
|
||||||
@@ -205,16 +204,13 @@ func TestGitCloneExecutor(t *testing.T) {
|
|||||||
require.NoError(t, gitCmd("-C", workDir, "add", "action.sh", ".gitattributes"))
|
require.NoError(t, gitCmd("-C", workDir, "add", "action.sh", ".gitattributes"))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "commit", "-m", "initial"))
|
require.NoError(t, gitCmd("-C", workDir, "commit", "-m", "initial"))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "tag", "v2"))
|
require.NoError(t, gitCmd("-C", workDir, "tag", "v2"))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "-u", "origin", "main"))
|
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "v2"))
|
|
||||||
|
|
||||||
require.NoError(t, gitCmd("-C", workDir, "checkout", "-b", "act-fails"))
|
require.NoError(t, gitCmd("-C", workDir, "checkout", "-b", "act-fails"))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "commit", "--allow-empty", "-m", "branch-commit"))
|
require.NoError(t, gitCmd("-C", workDir, "commit", "--allow-empty", "-m", "branch-commit"))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "act-fails"))
|
|
||||||
|
|
||||||
fullSha := gitRevParse(t, workDir, "main")
|
fullSha := gitRevParse(t, workDir, "main")
|
||||||
|
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "main:refs/heads/"+fullSha[:4]))
|
require.NoError(t, gitCmd("-C", workDir, "push", "-u", "origin", "main", "v2", "act-fails", "main:refs/heads/"+fullSha[:4]))
|
||||||
|
|
||||||
hostConfig := filepath.Join(t.TempDir(), "gitconfig")
|
hostConfig := filepath.Join(t.TempDir(), "gitconfig")
|
||||||
require.NoError(t, os.WriteFile(hostConfig, []byte("[core]\n\tautocrlf = true\n\teol = crlf\n[url "+strconv.Quote(remoteDir)+"]\n\tinsteadOf = https://example.invalid/action\n"), 0o644))
|
require.NoError(t, os.WriteFile(hostConfig, []byte("[core]\n\tautocrlf = true\n\teol = crlf\n[url "+strconv.Quote(remoteDir)+"]\n\tinsteadOf = https://example.invalid/action\n"), 0o644))
|
||||||
@@ -282,10 +278,10 @@ func TestGitCloneExecutor(t *testing.T) {
|
|||||||
func TestGitCloneExecutorReclonesWhenOriginURLChanges(t *testing.T) {
|
func TestGitCloneExecutorReclonesWhenOriginURLChanges(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
createRemote := func(message string) string {
|
createRemote := func(message string) string {
|
||||||
remoteDir, workDir := newGitRemote(t, message)
|
dir := t.TempDir()
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "-u", "origin", "main"))
|
require.NoError(t, os.CopyFS(dir, os.DirFS(filepath.Join(gitFixtureDir, "work"))))
|
||||||
|
require.NoError(t, gitCmd("-C", dir, "commit", "--allow-empty", "-m", message))
|
||||||
return remoteDir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
oldRemoteDir := createRemote("old-action")
|
oldRemoteDir := createRemote("old-action")
|
||||||
@@ -405,31 +401,30 @@ func TestGitCloneExecutorShallow(t *testing.T) {
|
|||||||
remoteDir, workDir := newGitRemote(t, "c1", "c2", "c3")
|
remoteDir, workDir := newGitRemote(t, "c1", "c2", "c3")
|
||||||
require.NoError(t, gitCmd("-C", workDir, "tag", "v1"))
|
require.NoError(t, gitCmd("-C", workDir, "tag", "v1"))
|
||||||
unadvertisedSHA := gitRevParse(t, workDir, "HEAD~1")
|
unadvertisedSHA := gitRevParse(t, workDir, "HEAD~1")
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "-u", "origin", "main"))
|
require.NoError(t, gitCmd("-C", workDir, "push", "-u", "origin", "main", "v1"))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "v1"))
|
|
||||||
|
|
||||||
shallowMarker := func(dir string) string { return filepath.Join(dir, ".git", "shallow") }
|
shallowMarker := func(dir string) string { return filepath.Join(dir, ".git", "shallow") }
|
||||||
|
|
||||||
for name, ref := range map[string]string{"branch is cloned shallowly": "main", "tag is cloned shallowly": "v1"} {
|
for name, ref := range map[string]string{"branch is cloned shallowly": "main", "tag is cloned shallowly": "v1"} {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
require.NoError(t, NewGitCloneExecutor(NewGitCloneExecutorInput{
|
require.NoError(t, NewGitCloneExecutor(NewGitCloneExecutorInput{
|
||||||
URL: remoteDir, Ref: ref, Dir: dir, Depth: 1,
|
URL: remoteDir, Ref: ref, Dir: dir, Depth: 1,
|
||||||
})(t.Context()))
|
})(t.Context()))
|
||||||
assert.FileExists(t, shallowMarker(dir), "clone should be shallow")
|
assert.FileExists(t, shallowMarker(dir), "clone should be shallow")
|
||||||
assert.Equal(t, 1, gitRevCount(t, dir), "only the tip commit should be present")
|
assert.Equal(t, []string{"c3"}, gitSubjects(t, dir), "only the tip commit should be present")
|
||||||
assert.Equal(t, "c3", gitHeadSubject(t, dir))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
unadvertisedRemote := func(t *testing.T, allowUnadvertised bool) string {
|
unadvertisedRemote := func(t *testing.T, allowUnadvertised bool) string {
|
||||||
remote := filepath.Join(t.TempDir(), "remote.git")
|
remote := filepath.Join(t.TempDir(), "remote.git")
|
||||||
require.NoError(t, gitCmd("clone", "--bare", remoteDir, remote))
|
require.NoError(t, gitCmd("clone", "--bare", "--template=", "--config", "uploadpack.allowAnySHA1InWant="+strconv.FormatBool(allowUnadvertised), remoteDir, remote))
|
||||||
require.NoError(t, gitCmd("-C", remote, "config", "uploadpack.allowAnySHA1InWant", strconv.FormatBool(allowUnadvertised)))
|
|
||||||
return remote
|
return remote
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("commit hash resolves when the remote accepts a direct shallow fetch", func(t *testing.T) {
|
t.Run("commit hash resolves when the remote accepts a direct shallow fetch", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
require.NoError(t, NewGitCloneExecutor(NewGitCloneExecutorInput{
|
require.NoError(t, NewGitCloneExecutor(NewGitCloneExecutorInput{
|
||||||
URL: unadvertisedRemote(t, false), Ref: unadvertisedSHA, Dir: dir, Depth: 1,
|
URL: unadvertisedRemote(t, false), Ref: unadvertisedSHA, Dir: dir, Depth: 1,
|
||||||
@@ -438,6 +433,7 @@ func TestGitCloneExecutorShallow(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("commit hash is fetched shallowly, moved to another hash, then reused without reaching the remote", func(t *testing.T) {
|
t.Run("commit hash is fetched shallowly, moved to another hash, then reused without reaching the remote", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
remote := unadvertisedRemote(t, true)
|
remote := unadvertisedRemote(t, true)
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
cloneAt := func(ref string) error {
|
cloneAt := func(ref string) error {
|
||||||
@@ -448,7 +444,7 @@ func TestGitCloneExecutorShallow(t *testing.T) {
|
|||||||
|
|
||||||
require.NoError(t, cloneAt(unadvertisedSHA))
|
require.NoError(t, cloneAt(unadvertisedSHA))
|
||||||
assert.FileExists(t, shallowMarker(dir))
|
assert.FileExists(t, shallowMarker(dir))
|
||||||
assert.Equal(t, 1, gitRevCount(t, dir))
|
assert.Len(t, gitSubjects(t, dir), 1)
|
||||||
assert.Equal(t, unadvertisedSHA, gitRevParse(t, dir, "HEAD"))
|
assert.Equal(t, unadvertisedSHA, gitRevParse(t, dir, "HEAD"))
|
||||||
|
|
||||||
olderSHA := gitRevParse(t, workDir, "HEAD~2")
|
olderSHA := gitRevParse(t, workDir, "HEAD~2")
|
||||||
@@ -461,6 +457,8 @@ func TestGitCloneExecutorShallow(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("moving hexadecimal-named branch updates while staying shallow", func(t *testing.T) {
|
t.Run("moving hexadecimal-named branch updates while staying shallow", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
remoteDir, workDir := newGitRemote(t, "c2", "c3")
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "main:deadbeef"))
|
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "main:deadbeef"))
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
clone := NewGitCloneExecutor(NewGitCloneExecutorInput{
|
clone := NewGitCloneExecutor(NewGitCloneExecutorInput{
|
||||||
@@ -473,19 +471,17 @@ func TestGitCloneExecutorShallow(t *testing.T) {
|
|||||||
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "main:deadbeef"))
|
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "main:deadbeef"))
|
||||||
|
|
||||||
require.NoError(t, clone(t.Context()))
|
require.NoError(t, clone(t.Context()))
|
||||||
assert.Equal(t, "c4", gitHeadSubject(t, dir), "reused shallow clone should update to the new tip")
|
assert.Equal(t, []string{"c4"}, gitSubjects(t, dir), "reused shallow clone should update to the new tip")
|
||||||
assert.FileExists(t, shallowMarker(dir), "repo should remain shallow after update")
|
assert.FileExists(t, shallowMarker(dir), "repo should remain shallow after update")
|
||||||
assert.Equal(t, 1, gitRevCount(t, dir))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("sha256 full hash is cloned shallowly, reused without the remote, and its 40-character prefix is short", func(t *testing.T) {
|
t.Run("sha256 full hash is cloned shallowly, reused without the remote, and its 40-character prefix is short", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
remote := filepath.Join(t.TempDir(), "remote.git")
|
remote := filepath.Join(t.TempDir(), "remote.git")
|
||||||
require.NoError(t, gitCmd("init", "--bare", "--object-format=sha256", "--initial-branch=main", remote))
|
|
||||||
work := t.TempDir()
|
work := t.TempDir()
|
||||||
require.NoError(t, gitCmd("init", "--object-format=sha256", "--initial-branch=main", work))
|
require.NoError(t, gitCmd("init", "--template=", "--object-format=sha256", "--initial-branch=main", work))
|
||||||
require.NoError(t, gitCmd("-C", work, "remote", "add", "origin", remote))
|
|
||||||
require.NoError(t, gitCmd("-C", work, "commit", "--allow-empty", "-m", "pinned"))
|
require.NoError(t, gitCmd("-C", work, "commit", "--allow-empty", "-m", "pinned"))
|
||||||
require.NoError(t, gitCmd("-C", work, "push", "origin", "main"))
|
require.NoError(t, gitCmd("clone", "--bare", "--template=", work, remote))
|
||||||
sha := gitRevParse(t, work, "HEAD")
|
sha := gitRevParse(t, work, "HEAD")
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
clone := NewGitCloneExecutor(NewGitCloneExecutorInput{URL: remote, Ref: sha, Dir: dir, Depth: 1})
|
clone := NewGitCloneExecutor(NewGitCloneExecutorInput{URL: remote, Ref: sha, Dir: dir, Depth: 1})
|
||||||
@@ -504,11 +500,11 @@ func TestGitCloneExecutorPinnedHashIgnoresShadowingRef(t *testing.T) {
|
|||||||
pinned := gitRevParse(t, workDir, "HEAD")
|
pinned := gitRevParse(t, workDir, "HEAD")
|
||||||
require.NoError(t, gitCmd("-C", workDir, "commit", "--allow-empty", "-m", "decoy"))
|
require.NoError(t, gitCmd("-C", workDir, "commit", "--allow-empty", "-m", "decoy"))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "tag", pinned))
|
require.NoError(t, gitCmd("-C", workDir, "tag", pinned))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "-u", "origin", "main"))
|
require.NoError(t, gitCmd("-C", workDir, "push", "-u", "origin", "main", pinned))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "origin", pinned))
|
|
||||||
|
|
||||||
for name, depth := range map[string]int{"shallow": 1, "full clone": 0} {
|
for name, depth := range map[string]int{"shallow": 1, "full clone": 0} {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
require.NoError(t, NewGitCloneExecutor(NewGitCloneExecutorInput{
|
require.NoError(t, NewGitCloneExecutor(NewGitCloneExecutorInput{
|
||||||
URL: remoteDir, Ref: pinned, Dir: dir, Depth: depth,
|
URL: remoteDir, Ref: pinned, Dir: dir, Depth: depth,
|
||||||
@@ -540,13 +536,11 @@ func gitRevParse(t *testing.T, dir, rev string) string {
|
|||||||
return strings.TrimSpace(string(out))
|
return strings.TrimSpace(string(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
func gitRevCount(t *testing.T, dir string) int {
|
func gitSubjects(t *testing.T, dir string) []string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
out, err := exec.Command("git", "-C", dir, "rev-list", "--count", "HEAD").Output()
|
out, err := exec.Command("git", "-C", dir, "log", "--format=%s").Output()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
n, err := strconv.Atoi(strings.TrimSpace(string(out)))
|
return strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||||
require.NoError(t, err)
|
|
||||||
return n
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func gitHeadSubject(t *testing.T, dir string) string {
|
func gitHeadSubject(t *testing.T, dir string) string {
|
||||||
@@ -680,7 +674,7 @@ func TestNewGitCloneExecutorFetchSendsTokenAndHonoursContext(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
dir := filepath.Join(t.TempDir(), "cached-action")
|
dir := filepath.Join(t.TempDir(), "cached-action")
|
||||||
require.NoError(t, gitCmd("init", dir))
|
require.NoError(t, os.CopyFS(dir, os.DirFS(filepath.Join(gitFixtureDir, "work"))))
|
||||||
require.NoError(t, gitCmd("-C", dir, "remote", "add", "origin", server.URL))
|
require.NoError(t, gitCmd("-C", dir, "remote", "add", "origin", server.URL))
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(t.Context())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ func TestDockerBuildLabelsImageWithItsTagAndReportsDaemonError(t *testing.T) {
|
|||||||
|
|
||||||
func TestCreateBuildContextFollowsDockerignoreAndSymlinkedRootButKeepsDockerfile(t *testing.T) {
|
func TestCreateBuildContextFollowsDockerignoreAndSymlinkedRootButKeepsDockerfile(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
require.NoError(t, os.Mkdir(filepath.Join(dir, "build"), 0o755))
|
||||||
for name, content := range map[string]string{
|
for name, content := range map[string]string{
|
||||||
".dockerignore": "*.log\nbuild\n!build/keep.txt\nDockerfile", "Dockerfile": "FROM scratch", "a.txt": "a",
|
".dockerignore": "*.log\nbuild\n!build/keep.txt\nDockerfile", "Dockerfile": "FROM scratch", "a.txt": "a",
|
||||||
"a.log": "log", "build/drop.txt": "drop", "build/keep.txt": "keep",
|
"a.log": "log", "build/drop.txt": "drop", "build/keep.txt": "keep",
|
||||||
} {
|
} {
|
||||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, filepath.Dir(name)), 0o755))
|
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644))
|
require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644))
|
||||||
}
|
}
|
||||||
require.NoError(t, os.Mkdir(filepath.Join(dir, "empty"), 0o755))
|
require.NoError(t, os.Mkdir(filepath.Join(dir, "empty"), 0o755))
|
||||||
|
|||||||
@@ -540,6 +540,9 @@ func TestRejectsMissingContainer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPublicCopyPipelineHandlesStaleID(t *testing.T) {
|
func TestPublicCopyPipelineHandlesStaleID(t *testing.T) {
|
||||||
|
source := t.TempDir()
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(source, "x"), nil, 0o644))
|
||||||
|
|
||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
name, destination, extractionRoot, entry string
|
name, destination, extractionRoot, entry string
|
||||||
directory bool
|
directory bool
|
||||||
@@ -567,8 +570,6 @@ func TestPublicCopyPipelineHandlesStaleID(t *testing.T) {
|
|||||||
|
|
||||||
cr := &containerReference{id: "stale", cli: client, input: &NewContainerInput{Name: "job-1"}}
|
cr := &containerReference{id: "stale", cli: client, input: &NewContainerInput{Name: "job-1"}}
|
||||||
if testcase.directory {
|
if testcase.directory {
|
||||||
source := t.TempDir()
|
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(source, "x"), nil, 0o644))
|
|
||||||
require.NoError(t, cr.CopyDir(testcase.destination, source+string(filepath.Separator), false, true)(ctx))
|
require.NoError(t, cr.CopyDir(testcase.destination, source+string(filepath.Separator), false, true)(ctx))
|
||||||
} else {
|
} else {
|
||||||
require.NoError(t, cr.Copy(testcase.destination, &FileEntry{Name: "x", Mode: 0o644})(ctx))
|
require.NoError(t, cr.Copy(testcase.destination, &FileEntry{Name: "x", Mode: 0o644})(ctx))
|
||||||
@@ -1108,6 +1109,10 @@ func TestConnectTakesDaemonOSFromPing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerCopyModes(t *testing.T) {
|
func TestContainerCopyModes(t *testing.T) {
|
||||||
|
source := t.TempDir()
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(source, "run.sh"), []byte("#!/bin/sh\n"), 0o666))
|
||||||
|
require.NoError(t, os.Chmod(filepath.Join(source, "run.sh"), 0o666))
|
||||||
|
|
||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
hostOS, serverOS string
|
hostOS, serverOS string
|
||||||
expected int64
|
expected int64
|
||||||
@@ -1117,9 +1122,6 @@ func TestContainerCopyModes(t *testing.T) {
|
|||||||
{"linux", "linux", 0o666},
|
{"linux", "linux", 0o666},
|
||||||
} {
|
} {
|
||||||
t.Run(testcase.hostOS+"-"+testcase.serverOS, func(t *testing.T) {
|
t.Run(testcase.hostOS+"-"+testcase.serverOS, func(t *testing.T) {
|
||||||
source := t.TempDir()
|
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(source, "run.sh"), []byte("#!/bin/sh\n"), 0o666))
|
|
||||||
require.NoError(t, os.Chmod(filepath.Join(source, "run.sh"), 0o666))
|
|
||||||
file := &FileEntry{Name: "run.sh", Mode: 0o600, Body: "#!/bin/sh\n"}
|
file := &FileEntry{Name: "run.sh", Mode: 0o600, Body: "#!/bin/sh\n"}
|
||||||
original := hostOS
|
original := hostOS
|
||||||
hostOS = testcase.hostOS
|
hostOS = testcase.hostOS
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ func TestActionPlatformNames(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCopyDir(t *testing.T) {
|
func TestCopyDir(t *testing.T) {
|
||||||
|
src := filepath.Join(t.TempDir(), "action")
|
||||||
|
require.NoError(t, os.MkdirAll(filepath.Join(src, ".git", "objects"), 0o700))
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(src, ".git", "objects", "pack"), []byte("x"), 0o600))
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(src, "action.yml"), []byte("name: x\n"), 0o600))
|
||||||
|
|
||||||
for _, test := range []struct {
|
for _, test := range []struct {
|
||||||
name string
|
name string
|
||||||
useGitIgnore, skipGitDir bool
|
useGitIgnore, skipGitDir bool
|
||||||
@@ -41,11 +46,6 @@ func TestCopyDir(t *testing.T) {
|
|||||||
{name: "unfiltered outside a git repository", useGitIgnore: true},
|
{name: "unfiltered outside a git repository", useGitIgnore: true},
|
||||||
} {
|
} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
src := filepath.Join(t.TempDir(), "action")
|
|
||||||
require.NoError(t, os.MkdirAll(filepath.Join(src, ".git", "objects"), 0o700))
|
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(src, ".git", "objects", "pack"), []byte("x"), 0o600))
|
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(src, "action.yml"), []byte("name: x\n"), 0o600))
|
|
||||||
|
|
||||||
dest := filepath.Join(t.TempDir(), "dest")
|
dest := filepath.Join(t.TempDir(), "dest")
|
||||||
require.NoError(t, (&HostEnvironment{}).CopyDir(dest, src+string(filepath.Separator), test.useGitIgnore, test.skipGitDir)(t.Context()))
|
require.NoError(t, (&HostEnvironment{}).CopyDir(dest, src+string(filepath.Separator), test.useGitIgnore, test.skipGitDir)(t.Context()))
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package container
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -15,14 +16,9 @@ import (
|
|||||||
"golang.org/x/text/encoding/unicode"
|
"golang.org/x/text/encoding/unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestHostEnv(t *testing.T) (*HostEnvironment, string) {
|
|
||||||
t.Helper()
|
|
||||||
e := &HostEnvironment{Path: t.TempDir()}
|
|
||||||
return e, filepath.Join(e.Path, "envfile")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseEnvFile(t *testing.T) {
|
func TestParseEnvFile(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
hostEnv := &HostEnvironment{Path: t.TempDir()}
|
||||||
largeValue := strings.Repeat("x", 2*1024*1024)
|
largeValue := strings.Repeat("x", 2*1024*1024)
|
||||||
encodeUTF16 := func(endianness unicode.Endianness) string {
|
encodeUTF16 := func(endianness unicode.Endianness) string {
|
||||||
content, err := unicode.UTF16(endianness, unicode.UseBOM).NewEncoder().Bytes([]byte("FOO=bar\r\nMULTI<<EOF\r\nline1\r\nEOF\r\n"))
|
content, err := unicode.UTF16(endianness, unicode.UseBOM).NewEncoder().Bytes([]byte("FOO=bar\r\nMULTI<<EOF\r\nline1\r\nEOF\r\n"))
|
||||||
@@ -51,15 +47,15 @@ func TestParseEnvFile(t *testing.T) {
|
|||||||
{"UTF16 big endian", encodeUTF16(unicode.BigEndian), map[string]string{"FOO": "bar\r", "MULTI": "line1\r"}},
|
{"UTF16 big endian", encodeUTF16(unicode.BigEndian), map[string]string{"FOO": "bar\r", "MULTI": "line1\r"}},
|
||||||
} {
|
} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
e, envPath := newTestHostEnv(t)
|
envPath := filepath.Join(hostEnv.Path, test.name)
|
||||||
require.NoError(t, os.WriteFile(envPath, []byte(test.content), 0o600))
|
require.NoError(t, os.WriteFile(envPath, []byte(test.content), 0o600))
|
||||||
env := map[string]string{}
|
env := map[string]string{}
|
||||||
require.NoError(t, parseEnvFile(e, envPath, &env, false)(t.Context()))
|
require.NoError(t, parseEnvFile(hostEnv, envPath, &env, false)(t.Context()))
|
||||||
assert.Equal(t, test.want, env)
|
assert.Equal(t, test.want, env)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
t.Run("ordered entries preserve repeated names", func(t *testing.T) {
|
t.Run("ordered entries preserve repeated names", func(t *testing.T) {
|
||||||
hostEnv, envPath := newTestHostEnv(t)
|
envPath := filepath.Join(hostEnv.Path, "ordered")
|
||||||
require.NoError(t, os.WriteFile(envPath, []byte("FOO=first\r\nfoo<<EOF\r\nmiddle\r\nEOF\r\nFOO=last\r\n"), 0o600))
|
require.NoError(t, os.WriteFile(envPath, []byte("FOO=first\r\nfoo<<EOF\r\nmiddle\r\nEOF\r\nFOO=last\r\n"), 0o600))
|
||||||
var entries [][2]string
|
var entries [][2]string
|
||||||
require.NoError(t, ParseEnvFile(hostEnv, envPath, func(name, value string) {
|
require.NoError(t, ParseEnvFile(hostEnv, envPath, func(name, value string) {
|
||||||
@@ -70,7 +66,7 @@ func TestParseEnvFile(t *testing.T) {
|
|||||||
}, entries)
|
}, entries)
|
||||||
})
|
})
|
||||||
t.Run("Windows line endings", func(t *testing.T) {
|
t.Run("Windows line endings", func(t *testing.T) {
|
||||||
hostEnv, envPath := newTestHostEnv(t)
|
envPath := filepath.Join(hostEnv.Path, "windows")
|
||||||
require.NoError(t, os.WriteFile(envPath, []byte("FOO=bar\r\nMULTI<<EOF\r\nline1\r\nline2\nEOF\r\n"), 0o600))
|
require.NoError(t, os.WriteFile(envPath, []byte("FOO=bar\r\nMULTI<<EOF\r\nline1\r\nline2\nEOF\r\n"), 0o600))
|
||||||
env := map[string]string{}
|
env := map[string]string{}
|
||||||
require.NoError(t, parseEnvFile(hostEnv, envPath, &env, true)(t.Context()))
|
require.NoError(t, parseEnvFile(hostEnv, envPath, &env, true)(t.Context()))
|
||||||
@@ -80,16 +76,22 @@ func TestParseEnvFile(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseEnvFileLineExceedsBufferReportsScannerError(t *testing.T) {
|
func TestParseEnvFileLineExceedsBufferReportsScannerError(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
e, envPath := newTestHostEnv(t)
|
hostEnv := &HostEnvironment{Path: t.TempDir()}
|
||||||
require.NoError(t, os.WriteFile(envPath, []byte("FOO<<EOF\n"+strings.Repeat("x", 17*1024*1024)+"\nEOF\n"), 0o600))
|
envPath := filepath.Join(hostEnv.Path, "envfile")
|
||||||
|
const header, footer = "FOO<<EOF\n", "\nEOF\n"
|
||||||
|
content := bytes.Repeat([]byte("x"), len(header)+17*1024*1024+len(footer))
|
||||||
|
copy(content, header)
|
||||||
|
copy(content[len(content)-len(footer):], footer)
|
||||||
|
require.NoError(t, os.WriteFile(envPath, content, 0o600))
|
||||||
|
|
||||||
env := map[string]string{}
|
env := map[string]string{}
|
||||||
err := parseEnvFile(e, envPath, &env, false)(t.Context())
|
err := parseEnvFile(hostEnv, envPath, &env, false)(t.Context())
|
||||||
require.ErrorIs(t, err, bufio.ErrTooLong)
|
require.ErrorIs(t, err, bufio.ErrTooLong)
|
||||||
assert.Contains(t, err.Error(), "reading env file")
|
assert.Contains(t, err.Error(), "reading env file")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseEnvFileInvalidHeredoc(t *testing.T) {
|
func TestParseEnvFileInvalidHeredoc(t *testing.T) {
|
||||||
|
hostEnv := &HostEnvironment{Path: t.TempDir()}
|
||||||
for name, content := range map[string]string{
|
for name, content := range map[string]string{
|
||||||
"missing delimiter": "FOO<<EOF\nline1\nline2\n",
|
"missing delimiter": "FOO<<EOF\nline1\nline2\n",
|
||||||
"empty name": "<<EOF\nline1\nEOF\n",
|
"empty name": "<<EOF\nline1\nEOF\n",
|
||||||
@@ -97,11 +99,11 @@ func TestParseEnvFileInvalidHeredoc(t *testing.T) {
|
|||||||
"delimiter with carriage return": "FOO<<EOF\nline1\nEOF\r\n",
|
"delimiter with carriage return": "FOO<<EOF\nline1\nEOF\r\n",
|
||||||
} {
|
} {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
e, envPath := newTestHostEnv(t)
|
envPath := filepath.Join(hostEnv.Path, name)
|
||||||
require.NoError(t, os.WriteFile(envPath, []byte("APPLIED=before-error\n"+content), 0o600))
|
require.NoError(t, os.WriteFile(envPath, []byte("APPLIED=before-error\n"+content), 0o600))
|
||||||
|
|
||||||
env := map[string]string{}
|
env := map[string]string{}
|
||||||
err := parseEnvFile(e, envPath, &env, false)(t.Context())
|
err := parseEnvFile(hostEnv, envPath, &env, false)(t.Context())
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "delimiter")
|
assert.Contains(t, err.Error(), "delimiter")
|
||||||
assert.Equal(t, map[string]string{"APPLIED": "before-error"}, env)
|
assert.Equal(t, map[string]string{"APPLIED": "before-error"}, env)
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ func gitCmd(t *testing.T, args ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCollectFilesKeepsWhatGitTracksOrDoesNotIgnore(t *testing.T) {
|
func TestCollectFilesKeepsWhatGitTracksOrDoesNotIgnore(t *testing.T) {
|
||||||
repoDir := filepath.Join(t.TempDir(), "mygitrepo")
|
repoDir := t.TempDir()
|
||||||
for _, dir := range []string{repoDir, filepath.Join(repoDir, "sub"), filepath.Join(repoDir, "nested")} {
|
gitCmd(t, "init", "-q", "--template=", repoDir)
|
||||||
gitCmd(t, "init", "-q", dir)
|
for _, dir := range []string{"sub", "nested"} {
|
||||||
|
require.NoError(t, os.CopyFS(filepath.Join(repoDir, dir, ".git"), os.DirFS(filepath.Join(repoDir, ".git"))))
|
||||||
}
|
}
|
||||||
|
require.NoError(t, os.Mkdir(filepath.Join(repoDir, "ign"), 0o755))
|
||||||
for name, body := range map[string]string{
|
for name, body := range map[string]string{
|
||||||
".gitignore": ".*\nign/\n",
|
".gitignore": ".*\nign/\n",
|
||||||
".env": "",
|
".env": "",
|
||||||
@@ -43,15 +45,15 @@ func TestCollectFilesKeepsWhatGitTracksOrDoesNotIgnore(t *testing.T) {
|
|||||||
"sub/kept": "",
|
"sub/kept": "",
|
||||||
"nested/kept": "",
|
"nested/kept": "",
|
||||||
} {
|
} {
|
||||||
require.NoError(t, os.MkdirAll(filepath.Dir(filepath.Join(repoDir, name)), 0o755))
|
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(repoDir, name), []byte(body), 0o644))
|
require.NoError(t, os.WriteFile(filepath.Join(repoDir, name), []byte(body), 0o644))
|
||||||
}
|
}
|
||||||
require.NoError(t, os.Mkdir(filepath.Join(repoDir, "uninitialized"), 0o755))
|
require.NoError(t, os.Mkdir(filepath.Join(repoDir, "uninitialized"), 0o755))
|
||||||
gitCmd(t, "-C", repoDir, "add", "-f", ".gitignore", "Renamed", "ign/tracked")
|
gitCmd(t, "-C", repoDir, "add", "-f", ".gitignore", "Renamed", "ign/tracked")
|
||||||
require.NoError(t, os.Rename(filepath.Join(repoDir, "Renamed"), filepath.Join(repoDir, "renamed")))
|
require.NoError(t, os.Rename(filepath.Join(repoDir, "Renamed"), filepath.Join(repoDir, "renamed")))
|
||||||
for _, gitlink := range []string{"sub", "uninitialized"} {
|
gitCmd(t, "-C", repoDir, "update-index", "--add",
|
||||||
gitCmd(t, "-C", repoDir, "update-index", "--add", "--cacheinfo", "160000,4b825dc642cb6eb9a060e54bf8d69288fbee4904,"+gitlink)
|
"--cacheinfo", "160000,4b825dc642cb6eb9a060e54bf8d69288fbee4904,sub",
|
||||||
}
|
"--cacheinfo", "160000,4b825dc642cb6eb9a060e54bf8d69288fbee4904,uninitialized",
|
||||||
|
)
|
||||||
expected := map[string]string{".gitignore": "", "ign/tracked": "", "nested/kept": "", "renamed": "", "sub/.gitignore": "", "sub/kept": ""}
|
expected := map[string]string{".gitignore": "", "ign/tracked": "", "nested/kept": "", "renamed": "", "sub/.gitignore": "", "sub/kept": ""}
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
require.NoError(t, os.Chmod(filepath.Join(repoDir, "renamed"), 0o777|os.ModeSticky))
|
require.NoError(t, os.Chmod(filepath.Join(repoDir, "renamed"), 0o777|os.ModeSticky))
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ func TestCompositeActionParity(t *testing.T) {
|
|||||||
return "", "", assert.AnError
|
return "", "", assert.AnError
|
||||||
})
|
})
|
||||||
rc := &RunContext{
|
rc := &RunContext{
|
||||||
Config: &Config{GitHubInstance: "github.com", ActionCacheDir: t.TempDir(), PresetGitHubContext: &model.GithubContext{}},
|
Config: &Config{GitHubInstance: "github.com", PresetGitHubContext: &model.GithubContext{}},
|
||||||
Run: &model.Run{JobID: "job", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"job": {}}}},
|
Run: &model.Run{JobID: "job", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"job": {}}}},
|
||||||
JobContainer: &jobContainerMock{},
|
JobContainer: &jobContainerMock{},
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-13
@@ -249,6 +249,7 @@ func TestActionRunner(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGoActionUsesLinuxExecutablePaths(t *testing.T) {
|
func TestGoActionUsesLinuxExecutablePaths(t *testing.T) {
|
||||||
|
actionRoot := t.TempDir()
|
||||||
for _, stage := range []string{"main", "pre", "post"} {
|
for _, stage := range []string{"main", "pre", "post"} {
|
||||||
t.Run(stage, func(t *testing.T) {
|
t.Run(stage, func(t *testing.T) {
|
||||||
cm := &containerMock{}
|
cm := &containerMock{}
|
||||||
@@ -264,7 +265,7 @@ func TestGoActionUsesLinuxExecutablePaths(t *testing.T) {
|
|||||||
JobContainer: cm,
|
JobContainer: cm,
|
||||||
},
|
},
|
||||||
action: &model.Action{Runs: model.ActionRuns{Using: model.ActionRunsUsingGo, Main: "main.go", Pre: "pre.go", Post: "post.go"}},
|
action: &model.Action{Runs: model.ActionRuns{Using: model.ActionRunsUsingGo, Main: "main.go", Pre: "pre.go", Post: "post.go"}},
|
||||||
actionDir: t.TempDir(),
|
actionDir: filepath.Join(actionRoot, stage),
|
||||||
env: map[string]string{},
|
env: map[string]string{},
|
||||||
remoteAction: mustNewRemoteAction(t, "org/repo@ref"),
|
remoteAction: mustNewRemoteAction(t, "org/repo@ref"),
|
||||||
}
|
}
|
||||||
@@ -504,11 +505,21 @@ func TestExecAsDockerHoldsCloneLockForRemoteUncached(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExecAsDockerImageChecks(t *testing.T) {
|
func TestExecAsDockerImageChecks(t *testing.T) {
|
||||||
|
actionRoot := t.TempDir()
|
||||||
originalExists, originalBuild, originalContainer := ContainerImageExistsLocally, ContainerNewDockerBuildExecutor, ContainerNewContainer
|
originalExists, originalBuild, originalContainer := ContainerImageExistsLocally, ContainerNewDockerBuildExecutor, ContainerNewContainer
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
ContainerImageExistsLocally, ContainerNewDockerBuildExecutor, ContainerNewContainer = originalExists, originalBuild, originalContainer
|
ContainerImageExistsLocally, ContainerNewDockerBuildExecutor, ContainerNewContainer = originalExists, originalBuild, originalContainer
|
||||||
})
|
})
|
||||||
ContainerNewContainer = func(*container.NewContainerInput) container.ExecutionsEnvironment { return fakeContainer{} }
|
ContainerNewContainer = func(*container.NewContainerInput) container.ExecutionsEnvironment { return fakeContainer{} }
|
||||||
|
var removed bool
|
||||||
|
fakeDockerDaemon(t, func(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
if request.Method == http.MethodDelete {
|
||||||
|
removed = true
|
||||||
|
_, _ = io.WriteString(writer, `[]`)
|
||||||
|
} else {
|
||||||
|
_, _ = io.WriteString(writer, `{"Architecture":"aarch64"}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
name, platform string
|
name, platform string
|
||||||
@@ -529,18 +540,11 @@ func TestExecAsDockerImageChecks(t *testing.T) {
|
|||||||
checks = append(checks, platform)
|
checks = append(checks, platform)
|
||||||
return testcase.exists && (platform == "any" || testcase.matches), nil
|
return testcase.exists && (platform == "any" || testcase.matches), nil
|
||||||
}
|
}
|
||||||
var built, removed bool
|
var built bool
|
||||||
|
removed = false
|
||||||
ContainerNewDockerBuildExecutor = func(container.NewDockerBuildExecutorInput) common.Executor {
|
ContainerNewDockerBuildExecutor = func(container.NewDockerBuildExecutorInput) common.Executor {
|
||||||
return func(context.Context) error { built = true; return nil }
|
return func(context.Context) error { built = true; return nil }
|
||||||
}
|
}
|
||||||
fakeDockerDaemon(t, func(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
if request.Method == http.MethodDelete {
|
|
||||||
removed = true
|
|
||||||
_, _ = io.WriteString(writer, `[]`)
|
|
||||||
} else {
|
|
||||||
_, _ = io.WriteString(writer, `{"Architecture":"aarch64"}`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
step := &stepActionRemote{
|
step := &stepActionRemote{
|
||||||
Step: &model.Step{ID: "action"},
|
Step: &model.Step{ID: "action"},
|
||||||
RunContext: &RunContext{
|
RunContext: &RunContext{
|
||||||
@@ -555,7 +559,7 @@ func TestExecAsDockerImageChecks(t *testing.T) {
|
|||||||
action: &model.Action{Runs: model.ActionRuns{Using: "docker", Image: "Dockerfile"}},
|
action: &model.Action{Runs: model.ActionRuns{Using: "docker", Image: "Dockerfile"}},
|
||||||
env: map[string]string{},
|
env: map[string]string{},
|
||||||
}
|
}
|
||||||
dir := t.TempDir()
|
dir := filepath.Join(actionRoot, testcase.name)
|
||||||
require.NoError(t, execAsDocker(t.Context(), step, "action", dir, dir, false, stepStageMain))
|
require.NoError(t, execAsDocker(t.Context(), step, "action", dir, dir, false, stepStageMain))
|
||||||
assert.Equal(t, testcase.wantChecks, checks)
|
assert.Equal(t, testcase.wantChecks, checks)
|
||||||
assert.Equal(t, testcase.wantBuild, built)
|
assert.Equal(t, testcase.wantBuild, built)
|
||||||
@@ -727,9 +731,9 @@ func TestExecAsDockerStageEntrypoint(t *testing.T) {
|
|||||||
cm.On("Close").Return(func(context.Context) error { return nil })
|
cm.On("Close").Return(func(context.Context) error { return nil })
|
||||||
|
|
||||||
if tc.stage == stepStageMain {
|
if tc.stage == stepStageMain {
|
||||||
require.NoError(t, runActionImpl(step, t.TempDir(), step.remoteAction)(ctx))
|
require.NoError(t, runActionImpl(step, "", step.remoteAction)(ctx))
|
||||||
} else {
|
} else {
|
||||||
require.NoError(t, execAsDocker(ctx, step, "action", t.TempDir(), t.TempDir(), false, tc.stage))
|
require.NoError(t, execAsDocker(ctx, step, "action", "", "", false, tc.stage))
|
||||||
}
|
}
|
||||||
if tc.warning == "" {
|
if tc.warning == "" {
|
||||||
assert.Empty(t, hook.AllRecords())
|
assert.Empty(t, hook.AllRecords())
|
||||||
|
|||||||
@@ -193,6 +193,11 @@ func TestCommandLogWriter(t *testing.T) {
|
|||||||
log []string
|
log []string
|
||||||
masks []string
|
masks []string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
name: "mask commands decode modern and legacy escapes once",
|
||||||
|
steps: [][]string{{"::add-mask::%25", "##[add-mask]alpha beta%3Bgamma%5Ddelta%250A"}},
|
||||||
|
masks: []string{"%", "alpha beta;gamma]delta%0A"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "applied commands are hidden unless echoed",
|
name: "applied commands are hidden unless echoed",
|
||||||
steps: [][]string{{
|
steps: [][]string{{
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ func TestDockerProxyMountedJob(t *testing.T) {
|
|||||||
ContainerNamePrefix: resourceName,
|
ContainerNamePrefix: resourceName,
|
||||||
ContainerDaemonSocket: dockerClient.DaemonHost(),
|
ContainerDaemonSocket: dockerClient.DaemonHost(),
|
||||||
ContainerMaxLifetime: 2 * time.Minute,
|
ContainerMaxLifetime: 2 * time.Minute,
|
||||||
|
Sweep: true,
|
||||||
ContainerOptions: "-v /usr/local/bin/docker:/usr/local/bin/docker:ro -v /usr/local/libexec/docker/cli-plugins:/usr/local/libexec/docker/cli-plugins:ro",
|
ContainerOptions: "-v /usr/local/bin/docker:/usr/local/bin/docker:ro -v /usr/local/libexec/docker/cli-plugins:/usr/local/libexec/docker/cli-plugins:ro",
|
||||||
ValidVolumes: []string{"/usr/local/bin/docker", "/usr/local/libexec/docker/cli-plugins"},
|
ValidVolumes: []string{"/usr/local/bin/docker", "/usr/local/libexec/docker/cli-plugins"},
|
||||||
Env: map[string]string{"PROXY_TEST_RESOURCE": resourceName, "PROXY_TEST_MODE": mode, "PROXY_TEST_IMAGE": baseImage, "COMPOSE_PROJECT_NAME": resourceName},
|
Env: map[string]string{"PROXY_TEST_RESOURCE": resourceName, "PROXY_TEST_MODE": mode, "PROXY_TEST_IMAGE": baseImage, "COMPOSE_PROJECT_NAME": resourceName},
|
||||||
|
|||||||
@@ -412,11 +412,10 @@ func TestGetEvaluatorInputsBoolean(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, eventName := range []string{"workflow_call", "workflow_dispatch"} {
|
for _, eventName := range []string{"workflow_call", "workflow_dispatch"} {
|
||||||
|
wf, err := model.ReadWorkflow(strings.NewReader(workflow(eventName)))
|
||||||
|
require.NoError(t, err)
|
||||||
for _, table := range tables {
|
for _, table := range tables {
|
||||||
t.Run(eventName+"/"+table.name, func(t *testing.T) {
|
t.Run(eventName+"/"+table.name, func(t *testing.T) {
|
||||||
wf, err := model.ReadWorkflow(strings.NewReader(workflow(eventName)))
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
rc := &RunContext{
|
rc := &RunContext{
|
||||||
Config: &Config{Workdir: "."},
|
Config: &Config{Workdir: "."},
|
||||||
Run: &model.Run{JobID: "job1", Workflow: wf},
|
Run: &model.Run{JobID: "job1", Workflow: wf},
|
||||||
|
|||||||
@@ -993,6 +993,7 @@ func tarArchive(t *testing.T, entries ...tarEntry) []byte {
|
|||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
tw := tar.NewWriter(buf)
|
tw := tar.NewWriter(buf)
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
|
buf.Grow(len(entry.body) + 3*512)
|
||||||
typeflag := entry.typeflag
|
typeflag := entry.typeflag
|
||||||
if typeflag == 0 {
|
if typeflag == 0 {
|
||||||
typeflag = tar.TypeReg
|
typeflag = tar.TypeReg
|
||||||
@@ -1009,7 +1010,7 @@ func tarArchive(t *testing.T, entries ...tarEntry) []byte {
|
|||||||
}
|
}
|
||||||
require.NoError(t, tw.WriteHeader(header))
|
require.NoError(t, tw.WriteHeader(header))
|
||||||
if typeflag == tar.TypeReg {
|
if typeflag == tar.TypeReg {
|
||||||
_, err := tw.Write([]byte(entry.body))
|
_, err := io.CopyN(tw, strings.NewReader(entry.body), int64(len(entry.body)))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1149,12 +1150,12 @@ func TestTryUploadJobSummaryMasksSecrets(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
content, err := testcase.encoding.NewEncoder().Bytes([]byte(testcase.content))
|
content, err := testcase.encoding.NewEncoder().String(testcase.content)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cm := &containerMock{}
|
cm := &containerMock{}
|
||||||
cm.On("GetContainerArchive", mock.Anything, "/var/run/act/workflow/step-summary-0.md").Return(
|
cm.On("GetContainerArchive", mock.Anything, "/var/run/act/workflow/step-summary-0.md").Return(
|
||||||
io.NopCloser(bytes.NewReader(tarArchive(t, tarEntry{
|
io.NopCloser(bytes.NewReader(tarArchive(t, tarEntry{
|
||||||
name: "step-summary-0.md", body: string(content),
|
name: "step-summary-0.md", body: content,
|
||||||
}))),
|
}))),
|
||||||
nil,
|
nil,
|
||||||
).Once()
|
).Once()
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func (rc *RunContext) runJobHook(ctx context.Context, hookPath, name string) err
|
|||||||
}
|
}
|
||||||
rawLogger.Infof("::endgroup::")
|
rawLogger.Infof("::endgroup::")
|
||||||
|
|
||||||
env := mergeMaps(rc.containerSpec.Env, rc.GetEnv())
|
env := rc.mergeEnv(rc.caEnv, rc.containerSpec.Env, rc.GetEnv())
|
||||||
rc.withGithubEnv(ctx, rc.getGithubContext(ctx), env)
|
rc.withGithubEnv(ctx, rc.getGithubContext(ctx), env)
|
||||||
rc.ApplyExtraPath(ctx, &env)
|
rc.ApplyExtraPath(ctx, &env)
|
||||||
|
|
||||||
|
|||||||
+37
-9
@@ -263,29 +263,27 @@ func AppendSecretMaskers(oldnew []string, secrets map[string]string) []string {
|
|||||||
return oldnew
|
return oldnew
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendSecretMasker registers v and each of its lines, as GitHub does.
|
// AppendSecretMasker skips one-byte line fragments to avoid masking punctuation from structured secrets.
|
||||||
func AppendSecretMasker(oldnew []string, v string) []string {
|
func AppendSecretMasker(oldnew []string, v string) []string {
|
||||||
ret := appendMaskedValue(oldnew, v)
|
ret := appendMaskedValue(oldnew, v)
|
||||||
for l := range strings.FieldsFuncSeq(v, func(r rune) bool { return r == '\r' || r == '\n' }) {
|
for l := range strings.FieldsFuncSeq(v, func(r rune) bool { return r == '\r' || r == '\n' }) {
|
||||||
ret = appendMaskedValue(ret, strings.TrimSpace(l))
|
if line := strings.TrimSpace(l); len(line) > 1 {
|
||||||
|
ret = appendMaskedValue(ret, line)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// appendMaskedValue registers one value and every shape it takes on its way into a log.
|
|
||||||
func appendMaskedValue(ret []string, v string) []string {
|
func appendMaskedValue(ret []string, v string) []string {
|
||||||
// formatted JSON secrets could otherwise mask {,[,],} everywhere
|
if strings.TrimSpace(v) == "" || slices.Contains(ret, v) {
|
||||||
if len(strings.TrimSpace(v)) <= 1 || slices.Contains(ret, v) {
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
ret = append(ret, v, "***")
|
ret = append(ret, v, "***")
|
||||||
// command data reaches the log escaped, so "pass%word" also arrives as "pass%25word"
|
|
||||||
if strings.ContainsAny(v, "%\r\n") {
|
if strings.ContainsAny(v, "%\r\n") {
|
||||||
ret = append(ret, EscapeCommandData(v), "***")
|
ret = append(ret, EscapeCommandData(v), "***")
|
||||||
}
|
}
|
||||||
for _, encode := range secretValueEncoders {
|
for _, encode := range secretValueEncoders {
|
||||||
encoded := encode(v)
|
encoded := encode(v)
|
||||||
// An encoding that leaves the value unchanged is already masked above.
|
|
||||||
if encoded == v || len(encoded) <= 1 || slices.Contains(ret, encoded) {
|
if encoded == v || len(encoded) <= 1 || slices.Contains(ret, encoded) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -319,7 +317,7 @@ func valueMasker(insecureSecrets bool, oldnew []string) entryProcessor {
|
|||||||
masks := Masks(ctx)
|
masks := Masks(ctx)
|
||||||
|
|
||||||
if len(*masks) == 0 {
|
if len(*masks) == 0 {
|
||||||
r.Message = defReplacer.Replace(r.Message)
|
r.Message = MaskLog(r.Message, defReplacer)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,12 +337,42 @@ func valueMasker(insecureSecrets bool, oldnew []string) entryProcessor {
|
|||||||
cmasker := replacer
|
cmasker := replacer
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
|
||||||
r.Message = cmasker.Replace(r.Message)
|
r.Message = MaskLog(r.Message, cmasker)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MaskLog decodes command data before masking to cover partially escaped values.
|
||||||
|
func MaskLog(message string, replacer *strings.Replacer) string {
|
||||||
|
var command, data string
|
||||||
|
var found bool
|
||||||
|
unescape := UnescapeCommandData
|
||||||
|
if strings.HasPrefix(message, "##[") {
|
||||||
|
command, data, found = strings.Cut(message[3:], "]")
|
||||||
|
unescape = UnescapeLegacyCommand
|
||||||
|
} else if strings.HasPrefix(message, "::") {
|
||||||
|
command, data, found = strings.Cut(message[2:], "::")
|
||||||
|
if name, _, properties := strings.Cut(command, " "); properties {
|
||||||
|
switch name {
|
||||||
|
case "error", "warning", "notice", "debug":
|
||||||
|
command = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch command {
|
||||||
|
case "error", "warning", "notice", "debug", "group", "endgroup", "add-matcher":
|
||||||
|
if found {
|
||||||
|
trimmedData := strings.TrimRight(data, "\r\n")
|
||||||
|
normalized := message[:len(message)-len(data)] + EscapeCommandData(unescape(trimmedData)) + data[len(trimmedData):]
|
||||||
|
if masked := replacer.Replace(normalized); masked != normalized {
|
||||||
|
return masked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return replacer.Replace(message)
|
||||||
|
}
|
||||||
|
|
||||||
type maskedHandler struct {
|
type maskedHandler struct {
|
||||||
logging.Handler
|
logging.Handler
|
||||||
masker entryProcessor
|
masker entryProcessor
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ func TestValueMasker(t *testing.T) {
|
|||||||
secrets map[string]string
|
secrets map[string]string
|
||||||
masks []string
|
masks []string
|
||||||
disallowed []string
|
disallowed []string
|
||||||
|
want string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Multiline Private Key",
|
name: "Multiline Private Key",
|
||||||
@@ -49,6 +50,60 @@ func TestValueMasker(t *testing.T) {
|
|||||||
secrets: map[string]string{"TOKEN": "pass%word"},
|
secrets: map[string]string{"TOKEN": "pass%word"},
|
||||||
disallowed: []string{"pass%25word"},
|
disallowed: []string{"pass%25word"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "one-character mask",
|
||||||
|
lines: "%",
|
||||||
|
masks: []string{"%"},
|
||||||
|
want: "***",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "fully escaped legacy secret",
|
||||||
|
lines: "##[group]alpha beta%3Bgamma%5Ddelta",
|
||||||
|
secrets: map[string]string{"TOKEN": "alpha beta;gamma]delta"},
|
||||||
|
want: "##[group]***",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "partially escaped legacy mask",
|
||||||
|
lines: "##[group]alpha beta%3Bgamma]delta",
|
||||||
|
masks: []string{"alpha beta;gamma]delta"},
|
||||||
|
want: "##[group]***",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "partially escaped modern mask preserves unrelated escapes",
|
||||||
|
lines: "::group::alpha%25beta%gamma tail%250A%0A",
|
||||||
|
masks: []string{"alpha%beta%gamma"},
|
||||||
|
want: "::group::*** tail%250A%0A",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "command escapes are decoded once",
|
||||||
|
lines: "##[group]alpha%253Bbeta%5Dgamma",
|
||||||
|
masks: []string{"alpha;beta]gamma"},
|
||||||
|
want: "##[group]alpha%253Bbeta%5Dgamma",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "plain output preserves escapes",
|
||||||
|
lines: "alpha beta%3Bgamma%5Ddelta",
|
||||||
|
masks: []string{"alpha beta;gamma]delta"},
|
||||||
|
want: "alpha beta%3Bgamma%5Ddelta",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "command display preserves literal escapes around a mask",
|
||||||
|
lines: "##[command]alpha tail%3Bvalue%5D",
|
||||||
|
masks: []string{"alpha"},
|
||||||
|
want: "##[command]*** tail%3Bvalue%5D",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unknown modern commands preserve literal escapes",
|
||||||
|
lines: "::unknown::alpha tail%25value",
|
||||||
|
masks: []string{"alpha"},
|
||||||
|
want: "::unknown::*** tail%25value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "masks can span command headers and data",
|
||||||
|
lines: "::group::hidden other",
|
||||||
|
masks: []string{"group::hidden", "other"},
|
||||||
|
want: "::*** ***",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, entry := range table {
|
for _, entry := range table {
|
||||||
t.Run(entry.name, func(t *testing.T) {
|
t.Run(entry.name, func(t *testing.T) {
|
||||||
@@ -56,6 +111,9 @@ func TestValueMasker(t *testing.T) {
|
|||||||
masker := valueMasker(false, AppendSecretMaskers(nil, entry.secrets))
|
masker := valueMasker(false, AppendSecretMaskers(nil, entry.secrets))
|
||||||
for line := range strings.SplitSeq(entry.lines, "\n") {
|
for line := range strings.SplitSeq(entry.lines, "\n") {
|
||||||
lentry := masker(ctx, logging.Record{Message: line})
|
lentry := masker(ctx, logging.Record{Message: line})
|
||||||
|
if entry.want != "" {
|
||||||
|
assert.Equal(t, entry.want, lentry.Message)
|
||||||
|
}
|
||||||
for _, line := range entry.disallowed {
|
for _, line := range entry.disallowed {
|
||||||
assert.NotContains(t, lentry.Message, line)
|
assert.NotContains(t, lentry.Message, line)
|
||||||
}
|
}
|
||||||
@@ -139,6 +197,7 @@ func TestValueMaskerEncodedMasks(t *testing.T) {
|
|||||||
{"encoded: " + base64.StdEncoding.EncodeToString([]byte(" s3cr3t ")), "encoded: ***"},
|
{"encoded: " + base64.StdEncoding.EncodeToString([]byte(" s3cr3t ")), "encoded: ***"},
|
||||||
{"encoded: " + base64.StdEncoding.EncodeToString([]byte("s3cr3t")), "encoded: ***"},
|
{"encoded: " + base64.StdEncoding.EncodeToString([]byte("s3cr3t")), "encoded: ***"},
|
||||||
{"encoded: " + base64.StdEncoding.EncodeToString([]byte("first")), "encoded: ***"},
|
{"encoded: " + base64.StdEncoding.EncodeToString([]byte("first")), "encoded: ***"},
|
||||||
|
{"##[group]s3cr3t value\r\n", "##[group]***\r\n"},
|
||||||
} {
|
} {
|
||||||
entry := masker(WithMasks(t.Context(), &masks), logging.Record{Message: tc.line})
|
entry := masker(WithMasks(t.Context(), &masks), logging.Record{Message: tc.line})
|
||||||
assert.Equal(t, tc.want, entry.Message, tc.line)
|
assert.Equal(t, tc.want, entry.Message, tc.line)
|
||||||
@@ -194,17 +253,15 @@ func TestValueMaskerCachedReplacerSeesNewMasks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAppendSecretMaskerSkipsUselessEncodings(t *testing.T) {
|
func TestAppendSecretMaskerSkipsUselessEncodings(t *testing.T) {
|
||||||
// A token with no character an escape would touch only gains its base64 forms:
|
|
||||||
// JSON, query and path escaping all leave it unchanged.
|
|
||||||
pairs := AppendSecretMasker(nil, "plaintoken")
|
pairs := AppendSecretMasker(nil, "plaintoken")
|
||||||
assert.Equal(t, []string{
|
assert.Equal(t, []string{
|
||||||
"plaintoken", "***", "cGxhaW50b2tlbg==", "***", "bGFpbnRva2Vu", "***", "YWludG9rZW4=", "***",
|
"plaintoken", "***", "cGxhaW50b2tlbg==", "***", "bGFpbnRva2Vu", "***", "YWludG9rZW4=", "***",
|
||||||
"aW50b2tl", "***", "YWludG9r", "***", "bGFpbnRv", "***",
|
"aW50b2tl", "***", "YWludG9r", "***", "bGFpbnRv", "***",
|
||||||
}, pairs)
|
}, pairs)
|
||||||
|
|
||||||
// Too short to mask.
|
assert.Contains(t, AppendSecretMasker(nil, "x"), "x")
|
||||||
assert.Empty(t, AppendSecretMasker(nil, "x"))
|
|
||||||
assert.Empty(t, AppendSecretMasker(nil, " \t"))
|
assert.Empty(t, AppendSecretMasker(nil, " \t"))
|
||||||
|
assert.NotContains(t, AppendSecretMasker(nil, "{\nvalue\n}"), "{")
|
||||||
assert.NotContains(t, AppendSecretMasker(nil, `"123456"`), "123456")
|
assert.NotContains(t, AppendSecretMasker(nil, `"123456"`), "123456")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package runner
|
package runner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"io"
|
"io"
|
||||||
@@ -209,14 +210,14 @@ func TestPatchedBundleAcrossActions(t *testing.T) {
|
|||||||
assert.Equal(t, data, out, "an untouched bundle must come back byte for byte")
|
assert.Equal(t, data, out, "an untouched bundle must come back byte for byte")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.NotContains(t, string(out), ".LOCALHOST", "a copy of the gate was missed")
|
assert.False(t, bytes.Contains(out, []byte(".LOCALHOST")), "a copy of the gate was missed")
|
||||||
|
|
||||||
if !strings.Contains(string(data), CacheServiceV2Env) {
|
if !bytes.Contains(data, []byte(CacheServiceV2Env)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.NotZero(t, strings.Count(string(out), "(process.env."+cacheURLEnv+"||process.env"),
|
assert.NotZero(t, bytes.Count(out, []byte("(process.env."+cacheURLEnv+"||process.env")),
|
||||||
"the cache service URL was not redirected")
|
"the cache service URL was not redirected")
|
||||||
assert.Equal(t, strings.Count(string(data), resultsURLEnv), strings.Count(string(out), resultsURLEnv),
|
assert.Equal(t, bytes.Count(data, []byte(resultsURLEnv)), bytes.Count(out, []byte(resultsURLEnv)),
|
||||||
"a read of the results URL was lost, it must stay as the fallback")
|
"a read of the results URL was lost, it must stay as the fallback")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -311,18 +312,18 @@ func TestCodeSplitActionFindsTheCacheService(t *testing.T) {
|
|||||||
requireHostTools(t, "node", "rustc")
|
requireHostTools(t, "node", "rustc")
|
||||||
|
|
||||||
dir := tempDirPath(t)
|
dir := tempDirPath(t)
|
||||||
|
require.NoError(t, os.Mkdir(filepath.Join(dir, "dist"), 0o755))
|
||||||
for _, name := range []string{
|
for _, name := range []string{
|
||||||
"action.yml", "dist/restore.js", "dist/save.js", "dist/cleanup-BWEbZ6YT.js",
|
"action.yml", "dist/restore.js", "dist/save.js", "dist/cleanup-BWEbZ6YT.js",
|
||||||
"dist/cache-CTfQoCTL.js", "dist/cache-DC26rUaF.js", "dist/state-cjs-CkvFUaNy.js",
|
"dist/cache-CTfQoCTL.js", "dist/cache-DC26rUaF.js", "dist/state-cjs-CkvFUaNy.js",
|
||||||
} {
|
} {
|
||||||
body, err := os.ReadFile(bundleFromGitHub(t, "Swatinem/rust-cache", "v2.9.2", name))
|
body, err := os.ReadFile(bundleFromGitHub(t, "Swatinem/rust-cache", "v2.9.2", name))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, os.MkdirAll(filepath.Dir(filepath.Join(dir, name)), 0o755))
|
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(dir, name), body, 0o600))
|
require.NoError(t, os.WriteFile(filepath.Join(dir, name), body, 0o600))
|
||||||
}
|
}
|
||||||
body, err := os.ReadFile(filepath.Join(dir, "action.yml"))
|
body, err := os.ReadFile(filepath.Join(dir, "action.yml"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
action, err := model.ReadAction(strings.NewReader(string(body)))
|
action, err := model.ReadAction(bytes.NewReader(body))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
inputs := map[string]string{"lookup-only": "true", "add-rust-environment-hash-key": "false", "cache-bin": "false"}
|
inputs := map[string]string{"lookup-only": "true", "add-rust-environment-hash-key": "false", "cache-bin": "false"}
|
||||||
for name, input := range action.Inputs {
|
for name, input := range action.Inputs {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package runner
|
package runner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -182,9 +183,9 @@ func TestPatchedBundleSurvivesInsideAStringLiteral(t *testing.T) {
|
|||||||
out, patched := patchedBundle([]byte(embedded))
|
out, patched := patchedBundle([]byte(embedded))
|
||||||
require.True(t, patched)
|
require.True(t, patched)
|
||||||
|
|
||||||
file := filepath.Join(t.TempDir(), "bundle.js")
|
cmd := exec.CommandContext(t.Context(), "node", "--check", "-")
|
||||||
require.NoError(t, os.WriteFile(file, out, 0o600))
|
cmd.Stdin = bytes.NewReader(out)
|
||||||
checked, err := exec.CommandContext(t.Context(), "node", "--check", file).CombinedOutput()
|
checked, err := cmd.CombinedOutput()
|
||||||
require.NoError(t, err, "%s", checked)
|
require.NoError(t, err, "%s", checked)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,6 +257,14 @@ func TestActionScriptPaths(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPatchActionsAtTheContainerCopy(t *testing.T) {
|
func TestPatchActionsAtTheContainerCopy(t *testing.T) {
|
||||||
|
actionDir := t.TempDir()
|
||||||
|
script := filepath.Join(actionDir, "dist", "cache.js")
|
||||||
|
require.NoError(t, os.MkdirAll(filepath.Dir(script), 0o755))
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(filepath.Dir(script), "index.js"), []byte("require('./cache.js')"), 0o600))
|
||||||
|
require.NoError(t, os.WriteFile(script, []byte(gateTSC), 0o600))
|
||||||
|
info, err := os.Stat(script)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
copiedBundles := func(t *testing.T, noPatch bool) ([]string, []*container.FileEntry, int64) {
|
copiedBundles := func(t *testing.T, noPatch bool) ([]string, []*container.FileEntry, int64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -264,19 +273,12 @@ func TestPatchActionsAtTheContainerCopy(t *testing.T) {
|
|||||||
Step: &model.Step{Uses: "owner/repo/sub@v1"},
|
Step: &model.Step{Uses: "owner/repo/sub@v1"},
|
||||||
remoteAction: &remoteAction{Org: "owner", Repo: "repo", Path: "sub", Ref: "v1"},
|
remoteAction: &remoteAction{Org: "owner", Repo: "repo", Path: "sub", Ref: "v1"},
|
||||||
action: &model.Action{Runs: model.ActionRuns{Using: "node20", Main: "../dist/index.js"}},
|
action: &model.Action{Runs: model.ActionRuns{Using: "node20", Main: "../dist/index.js"}},
|
||||||
actionDir: t.TempDir(),
|
actionDir: actionDir,
|
||||||
RunContext: &RunContext{
|
RunContext: &RunContext{
|
||||||
Config: &Config{ActionCacheDir: t.TempDir(), NoActionPatch: noPatch},
|
Config: &Config{NoActionPatch: noPatch},
|
||||||
JobContainer: cm,
|
JobContainer: cm,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
script := filepath.Join(sar.actionDir, "dist", "cache.js")
|
|
||||||
require.NoError(t, os.MkdirAll(filepath.Dir(script), 0o755))
|
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(filepath.Dir(script), "index.js"), []byte("require('./cache.js')"), 0o600))
|
|
||||||
require.NoError(t, os.WriteFile(script, []byte(gateTSC), 0o600))
|
|
||||||
info, err := os.Stat(script)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
var calls []string
|
var calls []string
|
||||||
var copied []*container.FileEntry
|
var copied []*container.FileEntry
|
||||||
cm.On("CopyDir", "/var/run/act/actions/repo/", sar.actionDir+"/", false, true).Return(func(context.Context) error {
|
cm.On("CopyDir", "/var/run/act/actions/repo/", sar.actionDir+"/", false, true).Return(func(context.Context) error {
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ func (c Config) withInstanceAuth(input git.NewGitCloneExecutorInput, token strin
|
|||||||
}
|
}
|
||||||
input.ClientCertFile, input.ClientKeyFile = c.ClientCertFile, c.ClientKeyFile
|
input.ClientCertFile, input.ClientKeyFile = c.ClientCertFile, c.ClientKeyFile
|
||||||
if onInstanceHost(u.Host, c.GitHubInstance) {
|
if onInstanceHost(u.Host, c.GitHubInstance) {
|
||||||
input.InsecureSkipTLS, input.Transport = c.InsecureSkipTLS, c.InstanceTransport
|
input.InsecureSkipTLS, input.CAFile, input.Transport = c.InsecureSkipTLS, c.CAFile, c.InstanceTransport
|
||||||
}
|
}
|
||||||
if u.User == nil {
|
if u.User == nil {
|
||||||
input.Token = token
|
input.Token = token
|
||||||
|
|||||||
@@ -33,24 +33,17 @@ func TestReusableWorkflowCachedBranchRefRefreshes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remoteDir := t.TempDir()
|
remoteDir := t.TempDir()
|
||||||
gitMust(t, "", "init", "--bare", "--initial-branch=master", remoteDir)
|
gitMust(t, "", "init", "--template=", "--initial-branch=master", remoteDir)
|
||||||
|
|
||||||
workDir := t.TempDir()
|
|
||||||
gitMust(t, "", "clone", remoteDir, workDir)
|
|
||||||
gitMust(t, workDir, "config", "user.email", "test@test")
|
|
||||||
gitMust(t, workDir, "config", "user.name", "test")
|
|
||||||
gitMust(t, workDir, "checkout", "-b", "master")
|
|
||||||
|
|
||||||
const workflowPath = ".gitea/workflows/reusable.yml"
|
const workflowPath = ".gitea/workflows/reusable.yml"
|
||||||
tmpl := func(tag string) string {
|
tmpl := func(tag string) string {
|
||||||
return "name: reusable\non:\n workflow_call:\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - run: echo " + tag + "\n"
|
return "name: reusable\non:\n workflow_call:\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - run: echo " + tag + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, os.MkdirAll(filepath.Join(workDir, ".gitea/workflows"), 0o755))
|
require.NoError(t, os.MkdirAll(filepath.Join(remoteDir, ".gitea/workflows"), 0o755))
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(workDir, workflowPath), []byte(tmpl("v1")), 0o644))
|
require.NoError(t, os.WriteFile(filepath.Join(remoteDir, workflowPath), []byte(tmpl("v1")), 0o644))
|
||||||
gitMust(t, workDir, "add", workflowPath)
|
gitMust(t, remoteDir, "add", workflowPath)
|
||||||
gitMust(t, workDir, "commit", "-m", "v1")
|
gitMust(t, remoteDir, "commit", "-m", "v1")
|
||||||
gitMust(t, workDir, "push", "-u", "origin", "master")
|
|
||||||
|
|
||||||
rc := &RunContext{
|
rc := &RunContext{
|
||||||
Config: &Config{Env: testCheckoutEnv()},
|
Config: &Config{Env: testCheckoutEnv()},
|
||||||
@@ -70,9 +63,8 @@ func TestReusableWorkflowCachedBranchRefRefreshes(t *testing.T) {
|
|||||||
require.Equal(t, tmpl("v1"), string(got))
|
require.Equal(t, tmpl("v1"), string(got))
|
||||||
|
|
||||||
// Branch tip moves; cache key (cacheDir) does not.
|
// Branch tip moves; cache key (cacheDir) does not.
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(workDir, workflowPath), []byte(tmpl("v2")), 0o644))
|
require.NoError(t, os.WriteFile(filepath.Join(remoteDir, workflowPath), []byte(tmpl("v2")), 0o644))
|
||||||
gitMust(t, workDir, "commit", "-am", "v2")
|
gitMust(t, remoteDir, "commit", "-am", "v2")
|
||||||
gitMust(t, workDir, "push", "origin", "master")
|
|
||||||
|
|
||||||
require.NoError(t, cloneRemoteReusableWorkflow(rc, remoteDir, "master", cacheDir)(t.Context()))
|
require.NoError(t, cloneRemoteReusableWorkflow(rc, remoteDir, "master", cacheDir)(t.Context()))
|
||||||
got, err = os.ReadFile(filepath.Join(cacheDir, workflowPath))
|
got, err = os.ReadFile(filepath.Join(cacheDir, workflowPath))
|
||||||
@@ -130,7 +122,7 @@ func TestNewLocalReusableWorkflowExecutorFindsSameRepositoryPaths(t *testing.T)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCloneRemoteReusableWorkflowSendsInstanceTokenAndClientCert(t *testing.T) {
|
func TestCloneRemoteReusableWorkflowSendsInstanceTokenAndClientCertTrustingCA(t *testing.T) {
|
||||||
var gotCert bool
|
var gotCert bool
|
||||||
var gotToken string
|
var gotToken string
|
||||||
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -150,12 +142,12 @@ func TestCloneRemoteReusableWorkflowSendsInstanceTokenAndClientCert(t *testing.T
|
|||||||
require.NoError(t, os.WriteFile(keyFile, pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: keyDER}), 0o600))
|
require.NoError(t, os.WriteFile(keyFile, pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: keyDER}), 0o600))
|
||||||
rc := &RunContext{
|
rc := &RunContext{
|
||||||
Config: &Config{
|
Config: &Config{
|
||||||
Env: testCheckoutEnv(),
|
Env: testCheckoutEnv(),
|
||||||
GitHubInstance: server.URL,
|
GitHubInstance: server.URL,
|
||||||
Secrets: map[string]string{"GITEA_TOKEN": "token"},
|
Secrets: map[string]string{"GITEA_TOKEN": "token"},
|
||||||
InsecureSkipTLS: true,
|
ClientCertFile: certFile,
|
||||||
ClientCertFile: certFile,
|
ClientKeyFile: keyFile,
|
||||||
ClientKeyFile: keyFile,
|
CAFile: certFile,
|
||||||
},
|
},
|
||||||
Run: &model.Run{JobID: "j1", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"j1": {}}}},
|
Run: &model.Run{JobID: "j1", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"j1": {}}}},
|
||||||
}
|
}
|
||||||
@@ -188,11 +180,12 @@ func TestInstanceAuthAndTransportOnlyApplyToTheInstance(t *testing.T) {
|
|||||||
InsecureSkipTLS: true,
|
InsecureSkipTLS: true,
|
||||||
ClientCertFile: "/cert",
|
ClientCertFile: "/cert",
|
||||||
ClientKeyFile: "/key",
|
ClientKeyFile: "/key",
|
||||||
|
CAFile: "/ca",
|
||||||
InstanceTransport: &http.Transport{},
|
InstanceTransport: &http.Transport{},
|
||||||
}
|
}
|
||||||
want := git.NewGitCloneExecutorInput{URL: tt.cloneURL, InsecureSkipTLS: tt.insecure}
|
want := git.NewGitCloneExecutorInput{URL: tt.cloneURL, InsecureSkipTLS: tt.insecure}
|
||||||
if tt.insecure {
|
if tt.insecure {
|
||||||
want.Transport = conf.InstanceTransport
|
want.CAFile, want.Transport = conf.CAFile, conf.InstanceTransport
|
||||||
}
|
}
|
||||||
if tt.token {
|
if tt.token {
|
||||||
want.Token = "token"
|
want.Token = "token"
|
||||||
@@ -213,7 +206,7 @@ func TestInstanceAuthAndTransportOnlyApplyToTheInstance(t *testing.T) {
|
|||||||
|
|
||||||
func gitMust(t *testing.T, dir string, args ...string) {
|
func gitMust(t *testing.T, dir string, args ...string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
cmd := exec.Command("git", args...)
|
cmd := exec.Command("git", append([]string{"-c", "user.name=test", "-c", "user.email=test@test"}, args...)...)
|
||||||
if dir != "" {
|
if dir != "" {
|
||||||
cmd.Dir = dir
|
cmd.Dir = dir
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ type RunContext struct {
|
|||||||
kubernetes bool
|
kubernetes bool
|
||||||
containerSpec model.ContainerSpec // container:, resolved once with platformImage
|
containerSpec model.ContainerSpec // container:, resolved once with platformImage
|
||||||
containerEnv yaml.Node // container.env of the kept containerSpec, decoded once the job env resolves
|
containerEnv yaml.Node // container.env of the kept containerSpec, decoded once the job env resolves
|
||||||
|
caEnv map[string]string // NODE_EXTRA_CA_CERTS for the runner CA, beneath any env the job and its image set
|
||||||
JobName string
|
JobName string
|
||||||
ActionPath string
|
ActionPath string
|
||||||
Parent *RunContext
|
Parent *RunContext
|
||||||
@@ -278,11 +279,37 @@ func (rc *RunContext) validVolumes() []string {
|
|||||||
if rc.dockerProxy != nil {
|
if rc.dockerProxy != nil {
|
||||||
volumes = append(volumes, rc.dockerProxy.Socket)
|
volumes = append(volumes, rc.dockerProxy.Socket)
|
||||||
}
|
}
|
||||||
|
volumes = append(volumes, rc.Config.containerVolumeSources()...)
|
||||||
// TODO: add a new configuration to control whether the docker daemon can be mounted
|
// TODO: add a new configuration to control whether the docker daemon can be mounted
|
||||||
return append(volumes, name, name+"-env",
|
return append(volumes, name, name+"-env",
|
||||||
getDockerDaemonSocketMountPath(rc.containerDaemonSocket()))
|
getDockerDaemonSocketMountPath(rc.containerDaemonSocket()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// containerVolumeSources lets workflows mount the container.volumes sources with no more access than they give.
|
||||||
|
func (c *Config) containerVolumeSources() []string {
|
||||||
|
var sources []string
|
||||||
|
for _, spec := range c.ContainerVolumes {
|
||||||
|
parsed, _ := container.ParseVolume(spec) // validated on config load
|
||||||
|
if parsed.ReadOnly {
|
||||||
|
parsed.Source += ":ro"
|
||||||
|
}
|
||||||
|
sources = append(sources, parsed.Source)
|
||||||
|
}
|
||||||
|
return sources
|
||||||
|
}
|
||||||
|
|
||||||
|
// mountVolumes sanitizes volumes and adds the container.volumes on the targets they leave unclaimed.
|
||||||
|
func (rc *RunContext) mountVolumes(ctx context.Context, validVolumes, volumes []string) ([]string, map[string]string, map[string]bool) {
|
||||||
|
binds, mounts, claimed := splitVolumes(container.SanitizeBinds(ctx, validVolumes, volumes))
|
||||||
|
for _, spec := range rc.Config.ContainerVolumes {
|
||||||
|
if parsed, _ := container.ParseVolume(spec); !claimed[parsed.Target] { // validated on config load
|
||||||
|
claimed[parsed.Target] = true
|
||||||
|
binds = append(binds, spec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return binds, mounts, claimed
|
||||||
|
}
|
||||||
|
|
||||||
func (rc *RunContext) workdirMountRoot() string {
|
func (rc *RunContext) workdirMountRoot() string {
|
||||||
if rc.Config.PresetGitHubContext != nil {
|
if rc.Config.PresetGitHubContext != nil {
|
||||||
return filepath.Dir(filepath.Dir(rc.Config.Workdir)) // only the daemon presets, its workdir is <parent>/<owner>/<repo>
|
return filepath.Dir(filepath.Dir(rc.Config.Workdir)) // only the daemon presets, its workdir is <parent>/<owner>/<repo>
|
||||||
@@ -357,7 +384,7 @@ func (rc *RunContext) GetBindsAndMounts(ctx context.Context) ([]string, map[stri
|
|||||||
ext := container.LinuxContainerEnvironmentExtensions{}
|
ext := container.LinuxContainerEnvironmentExtensions{}
|
||||||
|
|
||||||
// the runner's own mounts below yield to the targets the job claims
|
// the runner's own mounts below yield to the targets the job claims
|
||||||
binds, mounts, claimed := splitVolumes(container.SanitizeBinds(ctx, rc.validVolumes(), rc.containerSpec.Volumes))
|
binds, mounts, claimed := rc.mountVolumes(ctx, rc.validVolumes(), rc.containerSpec.Volumes)
|
||||||
|
|
||||||
if rc.containerDaemonSocket() != "-" && !claimed["/var/run/docker.sock"] {
|
if rc.containerDaemonSocket() != "-" && !claimed["/var/run/docker.sock"] {
|
||||||
binds = append(binds, rc.jobDockerSocket()+":/var/run/docker.sock")
|
binds = append(binds, rc.jobDockerSocket()+":/var/run/docker.sock")
|
||||||
@@ -705,7 +732,12 @@ func (rc *RunContext) jobServices(ctx context.Context, networkName string) (map[
|
|||||||
entrypoint = []string{spec.Entrypoint}
|
entrypoint = []string{spec.Entrypoint}
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceBinds, serviceMounts, _ := splitVolumes(spec.Volumes)
|
serviceBinds, serviceMounts, _ := splitVolumes(spec.Volumes) // as given on Kubernetes, which rejects them
|
||||||
|
validVolumes := rc.Config.ValidVolumes // not validVolumes(), a service gets no docker socket
|
||||||
|
if !rc.kubernetes {
|
||||||
|
validVolumes = append(slices.Clone(validVolumes), rc.Config.containerVolumeSources()...)
|
||||||
|
serviceBinds, serviceMounts, _ = rc.mountVolumes(ctx, validVolumes, spec.Volumes)
|
||||||
|
}
|
||||||
|
|
||||||
exposedPorts, portBindings, err := nat.ParsePortSpecs(spec.Ports)
|
exposedPorts, portBindings, err := nat.ParsePortSpecs(spec.Ports)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -734,7 +766,7 @@ func (rc *RunContext) jobServices(ctx context.Context, networkName string) (map[
|
|||||||
NetworkAliases: []string{serviceID},
|
NetworkAliases: []string{serviceID},
|
||||||
ExposedPorts: exposedPorts,
|
ExposedPorts: exposedPorts,
|
||||||
PortBindings: portBindings,
|
PortBindings: portBindings,
|
||||||
ValidVolumes: rc.Config.ValidVolumes, // not validVolumes(), a service gets no docker socket
|
ValidVolumes: validVolumes,
|
||||||
AllocatePTY: rc.Config.AllocatePTY,
|
AllocatePTY: rc.Config.AllocatePTY,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -778,7 +810,7 @@ func (rc *RunContext) cleanupJobResources(networkName string, createAndDeleteNet
|
|||||||
errs = append(errs, runAll(ctx, containers))
|
errs = append(errs, runAll(ctx, containers))
|
||||||
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), jobCleanupTimeout)
|
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), jobCleanupTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if !common.Dryrun(ctx) && !rc.Config.NoSweep && (preclean || rc.hadDockerProxy) {
|
if !common.Dryrun(ctx) && rc.Config.Sweep && (preclean || rc.hadDockerProxy) {
|
||||||
errs = append(errs, container.RemoveDockerJobResources(ctx, rc.jobContainerName())) // after the containers, whose endpoints would block removing the job networks
|
errs = append(errs, container.RemoveDockerJobResources(ctx, rc.jobContainerName())) // after the containers, whose endpoints would block removing the job networks
|
||||||
}
|
}
|
||||||
var rest []common.Executor
|
var rest []common.Executor
|
||||||
@@ -1119,10 +1151,35 @@ func (svc *serviceContainer) healthOutputSuffix() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RunContext) copyWorkflowFiles() common.Executor {
|
func (rc *RunContext) copyWorkflowFiles() common.Executor {
|
||||||
return rc.JobContainer.Copy(rc.JobContainer.GetActPath()+"/",
|
return func(ctx context.Context) error {
|
||||||
&container.FileEntry{Name: "workflow/event.json", Mode: 0o644, Body: rc.EventJSON},
|
files := []*container.FileEntry{
|
||||||
&container.FileEntry{Name: "workflow/envs.txt", Mode: 0o666},
|
{Name: "workflow/event.json", Mode: 0o644, Body: rc.EventJSON},
|
||||||
)
|
{Name: "workflow/envs.txt", Mode: 0o666},
|
||||||
|
}
|
||||||
|
if rc.Config.CAFile != "" {
|
||||||
|
ca, err := os.ReadFile(rc.Config.CAFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("read runner CA file: %w", err)
|
||||||
|
}
|
||||||
|
files = append(files, &container.FileEntry{Name: "ca.crt", Mode: 0o644, Body: string(ca)})
|
||||||
|
imageEnv := map[string]string{}
|
||||||
|
if err = rc.JobContainer.UpdateFromImageEnv(&imageEnv)(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, set := imageEnv["NODE_EXTRA_CA_CERTS"]; !set {
|
||||||
|
rc.caEnv = map[string]string{"NODE_EXTRA_CA_CERTS": rc.jobCAFile()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rc.JobContainer.Copy(rc.JobContainer.GetActPath()+"/", files...)(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// jobCAFile is where copyWorkflowFiles puts the runner CA in the job, empty without one.
|
||||||
|
func (rc *RunContext) jobCAFile() string {
|
||||||
|
if rc.Config.CAFile == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return rc.JobContainer.GetActPath() + "/ca.crt"
|
||||||
}
|
}
|
||||||
|
|
||||||
// captureJobContainerInfo is a convenience: failing to describe the container must not
|
// captureJobContainerInfo is a convenience: failing to describe the container must not
|
||||||
|
|||||||
@@ -277,25 +277,38 @@ jobs:
|
|||||||
require.Equal(t, [2]string{"", ""}, credentials["redis:latest"])
|
require.Equal(t, [2]string{"", ""}, credentials["redis:latest"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStartJobContainerGivesServicesTheirVolumes(t *testing.T) {
|
func TestStartJobContainerMountsWorkflowVolumesAndContainerVolumesOnUnclaimedTargets(t *testing.T) {
|
||||||
redis := startJobContainerInputs(t, `
|
const ca, certs = "/host/ca.crt:/etc/ssl/certs/ca-certificates.crt:ro", "/host/certs:/certs"
|
||||||
|
inputs := startJobContainerInputs(t, `
|
||||||
jobs:
|
jobs:
|
||||||
job:
|
job:
|
||||||
|
container:
|
||||||
|
image: node:24
|
||||||
|
volumes:
|
||||||
|
- /job/certs:/certs
|
||||||
services:
|
services:
|
||||||
redis:
|
redis:
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
volumes:
|
volumes:
|
||||||
- data:/data
|
- data:/data
|
||||||
- data:/backup
|
- data:/backup
|
||||||
`, &Config{ValidVolumes: []string{"data"}})[0]
|
- /blocked/ca.crt:/etc/ssl/certs/ca-certificates.crt:ro
|
||||||
|
- blocked:/certs
|
||||||
|
`, &Config{ValidVolumes: []string{"data", "/job/certs"}, ContainerVolumes: []string{ca, certs}})
|
||||||
|
require.Len(t, inputs, 2)
|
||||||
|
redis, job := inputs[0], inputs[1]
|
||||||
|
|
||||||
require.Equal(t, "redis:latest", redis.Image)
|
require.Equal(t, "redis:latest", redis.Image)
|
||||||
require.Equal(t, []string{"data"}, redis.ValidVolumes)
|
require.Equal(t, []string{"data", "/job/certs", "/host/ca.crt:ro", "/host/certs"}, redis.ValidVolumes)
|
||||||
require.Equal(t, map[string]string{"data": "/data"}, redis.Mounts)
|
require.Equal(t, map[string]string{"data": "/data"}, redis.Mounts)
|
||||||
require.Equal(t, []string{"data:/backup"}, redis.Binds)
|
require.Equal(t, []string{"data:/backup", ca, certs}, redis.Binds)
|
||||||
require.Empty(t, redis.WorkingDir)
|
require.Empty(t, redis.WorkingDir)
|
||||||
require.Nil(t, redis.Entrypoint)
|
require.Nil(t, redis.Entrypoint)
|
||||||
require.Nil(t, redis.Cmd)
|
require.Nil(t, redis.Cmd)
|
||||||
|
assert.Subset(t, job.Binds, []string{"/job/certs:/certs", ca})
|
||||||
|
assert.NotContains(t, job.Binds, certs)
|
||||||
|
assert.Subset(t, job.ValidVolumes, []string{"/job/certs", "/host/ca.crt:ro", "/host/certs"})
|
||||||
|
assert.NotContains(t, job.ValidVolumes, "/host/ca.crt", "a workflow must not mount a read-only source writable")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStartJobContainerBuildsEvaluatedJobAndServiceInputs(t *testing.T) {
|
func TestStartJobContainerBuildsEvaluatedJobAndServiceInputs(t *testing.T) {
|
||||||
@@ -304,7 +317,7 @@ jobs:
|
|||||||
job:
|
job:
|
||||||
container: ${{ fromJSON('{"image":"docker://node:20","options":"--label ${{ github.job }}","credentials":{"username":"user","password":"${{ vars.TITLE }}"}}') }}
|
container: ${{ fromJSON('{"image":"docker://node:20","options":"--label ${{ github.job }}","credentials":{"username":"user","password":"${{ vars.TITLE }}"}}') }}
|
||||||
services: ${{ fromJSON('{"redis":{"image":"docker://redis:latest","volumes":["data:/data"],"env":{"TITLE":"${{ github.job }}"},"credentials":{"username":"user","password":"${{ github.job }}"},"entrypoint":"/entry.sh","command":"redis-server --port 6380"}}') }}
|
services: ${{ fromJSON('{"redis":{"image":"docker://redis:latest","volumes":["data:/data"],"env":{"TITLE":"${{ github.job }}"},"credentials":{"username":"user","password":"${{ github.job }}"},"entrypoint":"/entry.sh","command":"redis-server --port 6380"}}') }}
|
||||||
`, &Config{})
|
`, &Config{ValidVolumes: []string{"data"}})
|
||||||
redis, job := inputs[0], inputs[1]
|
redis, job := inputs[0], inputs[1]
|
||||||
|
|
||||||
require.Equal(t, "redis:latest", redis.Image)
|
require.Equal(t, "redis:latest", redis.Image)
|
||||||
@@ -712,7 +725,7 @@ func TestCleanupJobResources(t *testing.T) {
|
|||||||
service.On("Remove").Return(removeAlongside(serviceRemoving, jobRemoving, removeError)).Once()
|
service.On("Remove").Return(removeAlongside(serviceRemoving, jobRemoving, removeError)).Once()
|
||||||
service.On("Close").Return(func(context.Context) error { return closeError }).Once()
|
service.On("Close").Return(func(context.Context) error { return closeError }).Once()
|
||||||
rc := &RunContext{
|
rc := &RunContext{
|
||||||
Config: &Config{CacheContainer: "cache-container", NoSweep: name == "kept proxy"},
|
Config: &Config{CacheContainer: "cache-container", Sweep: name != "kept proxy"},
|
||||||
Run: &model.Run{Workflow: &model.Workflow{Name: "wf"}, JobID: "job"},
|
Run: &model.Run{Workflow: &model.Workflow{Name: "wf"}, JobID: "job"},
|
||||||
JobContainer: job,
|
JobContainer: job,
|
||||||
serviceContainers: []*serviceContainer{{name: "svc", container: service}},
|
serviceContainers: []*serviceContainer{{name: "svc", container: service}},
|
||||||
@@ -1450,6 +1463,43 @@ func TestGetJobContextReportsContainers(t *testing.T) {
|
|||||||
}, jobContext.Services)
|
}, jobContext.Services)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type imageEnvContainer struct {
|
||||||
|
*container.HostEnvironment
|
||||||
|
imageEnv map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c imageEnvContainer) UpdateFromImageEnv(env *map[string]string) common.Executor {
|
||||||
|
return func(_ctx context.Context) error { maps.Copy(*env, c.imageEnv); return nil }
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCopyWorkflowFilesHandsNodeTheRunnerCAUnlessTheJobOrImageSetsIt(t *testing.T) {
|
||||||
|
caFile, actPath := filepath.Join(t.TempDir(), "ca.crt"), t.TempDir()
|
||||||
|
require.NoError(t, os.WriteFile(caFile, []byte("PEM\n"), 0o600))
|
||||||
|
own := map[string]string{"NODE_EXTRA_CA_CERTS": "/own.pem"}
|
||||||
|
stepEnv := func(caFile string, jobEnv, containerEnv, imageEnv map[string]string) map[string]string {
|
||||||
|
rc := &RunContext{
|
||||||
|
Config: &Config{CAFile: caFile},
|
||||||
|
Run: &model.Run{JobID: "job", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"job": {}}}},
|
||||||
|
Env: maps.Clone(jobEnv),
|
||||||
|
JobContainer: imageEnvContainer{&container.HostEnvironment{Path: t.TempDir(), ActPath: actPath, StdOut: io.Discard}, imageEnv},
|
||||||
|
}
|
||||||
|
rc.containerSpec.Env = containerEnv
|
||||||
|
require.NoError(t, rc.copyWorkflowFiles()(t.Context()))
|
||||||
|
env := map[string]string{}
|
||||||
|
require.NoError(t, setupEnv(t.Context(), &stepRun{RunContext: rc, Step: &model.Step{}, env: env}))
|
||||||
|
return env
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, filepath.ToSlash(actPath)+"/ca.crt", stepEnv(caFile, nil, nil, nil)["NODE_EXTRA_CA_CERTS"])
|
||||||
|
ca, err := os.ReadFile(filepath.Join(actPath, "ca.crt"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "PEM\n", string(ca))
|
||||||
|
assert.Equal(t, "/own.pem", stepEnv(caFile, own, nil, nil)["NODE_EXTRA_CA_CERTS"])
|
||||||
|
assert.Equal(t, "/own.pem", stepEnv(caFile, nil, own, nil)["NODE_EXTRA_CA_CERTS"])
|
||||||
|
assert.NotContains(t, stepEnv(caFile, nil, nil, own), "NODE_EXTRA_CA_CERTS")
|
||||||
|
assert.NotContains(t, stepEnv("", nil, nil, nil), "NODE_EXTRA_CA_CERTS")
|
||||||
|
}
|
||||||
|
|
||||||
func TestCaptureJobContainerInfoExportsDockerWorkspace(t *testing.T) {
|
func TestCaptureJobContainerInfoExportsDockerWorkspace(t *testing.T) {
|
||||||
workdir := t.TempDir()
|
workdir := t.TempDir()
|
||||||
job := &containerMock{}
|
job := &containerMock{}
|
||||||
@@ -1616,21 +1666,21 @@ func TestRunContextUpdateExtraPath(t *testing.T) {
|
|||||||
longPath := strings.Repeat("x", 64*1024+1)
|
longPath := strings.Repeat("x", 64*1024+1)
|
||||||
for _, testcase := range []struct {
|
for _, testcase := range []struct {
|
||||||
name string
|
name string
|
||||||
content []byte
|
content string
|
||||||
want string
|
want string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{name: "UTF-8 BOM", content: []byte("\xef\xbb\xbf/utf8/tools\n"), want: "/utf8/tools"},
|
{name: "UTF-8 BOM", content: "\xef\xbb\xbf/utf8/tools\n", want: "/utf8/tools"},
|
||||||
{name: "UTF-16 BOM", content: []byte{0xff, 0xfe, 'C', 0, ':', 0, '\\', 0, 't', 0, 'o', 0, 'o', 0, 'l', 0, 's', 0, '\n', 0}, want: `C:\tools`},
|
{name: "UTF-16 BOM", content: "\xff\xfeC\x00:\x00\\\x00t\x00o\x00o\x00l\x00s\x00\n\x00", want: `C:\tools`},
|
||||||
{name: "over 64 KiB", content: []byte(longPath + "\n"), want: longPath},
|
{name: "over 64 KiB", content: longPath + "\n", want: longPath},
|
||||||
{name: "over 16 MiB", content: []byte(strings.Repeat("x", 16*1024*1024+1)), wantErr: true},
|
{name: "over 16 MiB", content: strings.Repeat("x", 16*1024*1024+1), wantErr: true},
|
||||||
} {
|
} {
|
||||||
t.Run(testcase.name, func(t *testing.T) {
|
t.Run(testcase.name, func(t *testing.T) {
|
||||||
logger := logging.New(logging.DiscardHandler)
|
logger := logging.New(logging.DiscardHandler)
|
||||||
ctx := common.WithLogger(t.Context(), logger)
|
ctx := common.WithLogger(t.Context(), logger)
|
||||||
jobContainer := &containerMock{}
|
jobContainer := &containerMock{}
|
||||||
jobContainer.On("GetContainerArchive", mock.Anything, "/github/path").
|
jobContainer.On("GetContainerArchive", mock.Anything, "/github/path").
|
||||||
Return(io.NopCloser(bytes.NewReader(tarArchive(t, tarEntry{name: "path", body: string(testcase.content)}))), nil).Once()
|
Return(io.NopCloser(bytes.NewReader(tarArchive(t, tarEntry{name: "path", body: testcase.content}))), nil).Once()
|
||||||
defer jobContainer.AssertExpectations(t)
|
defer jobContainer.AssertExpectations(t)
|
||||||
rc := &RunContext{JobContainer: jobContainer}
|
rc := &RunContext{JobContainer: jobContainer}
|
||||||
|
|
||||||
|
|||||||
@@ -83,13 +83,15 @@ type Config struct {
|
|||||||
InstanceTransport http.RoundTripper
|
InstanceTransport http.RoundTripper
|
||||||
JobLoggerLevel *logging.Level // the level of job logger
|
JobLoggerLevel *logging.Level // the level of job logger
|
||||||
ValidVolumes []string // only volumes (and bind mounts) in this slice can be mounted on the job container or service containers
|
ValidVolumes []string // only volumes (and bind mounts) in this slice can be mounted on the job container or service containers
|
||||||
|
ContainerVolumes []string // mounted into every job, service and docker action container
|
||||||
SharedToolCache bool // one tool cache for all jobs instead of one per job
|
SharedToolCache bool // one tool cache for all jobs instead of one per job
|
||||||
InsecureSkipTLS bool // whether to skip verifying TLS certificate of the Gitea instance
|
InsecureSkipTLS bool // whether to skip verifying TLS certificate of the Gitea instance
|
||||||
ClientCertFile, ClientKeyFile string // PEM client certificate for the Gitea instance
|
ClientCertFile, ClientKeyFile string // PEM client certificate for the Gitea instance
|
||||||
|
CAFile string // PEM CA certificates the Gitea instance's certificate chains to
|
||||||
MaxParallel int // max parallel jobs to run across all workflows (0 = no limit, uses CPU count)
|
MaxParallel int // max parallel jobs to run across all workflows (0 = no limit, uses CPU count)
|
||||||
AllocatePTY bool // allocate a pseudo-TTY for each step's process
|
AllocatePTY bool // allocate a pseudo-TTY for each step's process
|
||||||
ServiceReadyTimeout time.Duration // how long a job waits for its service containers to report healthy (0 uses the default)
|
ServiceReadyTimeout time.Duration // how long a job waits for its service containers to report healthy (0 uses the default)
|
||||||
NoSweep bool // keep the containers, networks and volumes a job creates through its docker proxy
|
Sweep bool // remove the containers, networks and volumes a job creates through its docker proxy
|
||||||
RunnerName string // name this runner registered with, reported as `runner.name`, defaults to the hostname
|
RunnerName string // name this runner registered with, reported as `runner.name`, defaults to the hostname
|
||||||
JobStartedHook string // script run inside the job environment before the job's first step; ACTIONS_RUNNER_HOOK_JOB_STARTED is read from Env when empty
|
JobStartedHook string // script run inside the job environment before the job's first step; ACTIONS_RUNNER_HOOK_JOB_STARTED is read from Env when empty
|
||||||
JobCompletedHook string // script run inside the job environment after the job's last step; ACTIONS_RUNNER_HOOK_JOB_COMPLETED is read from Env when empty
|
JobCompletedHook string // script run inside the job environment after the job's last step; ACTIONS_RUNNER_HOOK_JOB_COMPLETED is read from Env when empty
|
||||||
|
|||||||
+1
-1
@@ -263,7 +263,7 @@ func setupEnv(ctx context.Context, step step) error {
|
|||||||
|
|
||||||
env := step.getEnv()
|
env := step.getEnv()
|
||||||
// container env is the image's baseline, which job env and $GITHUB_ENV override
|
// container env is the image's baseline, which job env and $GITHUB_ENV override
|
||||||
mergeIntoMap(step, env, rc.containerSpec.Env, rc.GetEnv())
|
mergeIntoMap(step, env, rc.caEnv, rc.containerSpec.Env, rc.GetEnv())
|
||||||
rc.withGithubEnv(ctx, getStepGithubContext(ctx, step), *env)
|
rc.withGithubEnv(ctx, getStepGithubContext(ctx, step), *env)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ func (sab *stepActionBuiltin) main() common.Executor {
|
|||||||
InsecureSkipTLS: rc.Config.InsecureSkipTLS,
|
InsecureSkipTLS: rc.Config.InsecureSkipTLS,
|
||||||
ClientCertFile: rc.Config.ClientCertFile,
|
ClientCertFile: rc.Config.ClientCertFile,
|
||||||
ClientKeyFile: rc.Config.ClientKeyFile,
|
ClientKeyFile: rc.Config.ClientKeyFile,
|
||||||
|
CAFile: rc.jobCAFile(),
|
||||||
Env: sab.env,
|
Env: sab.env,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -35,14 +35,8 @@ func setFetch(t *testing.T, fetch func(context.Context, git.NewGitCloneExecutorI
|
|||||||
func TestShortSHAActionRejected(t *testing.T) {
|
func TestShortSHAActionRejected(t *testing.T) {
|
||||||
actionRoot := t.TempDir()
|
actionRoot := t.TempDir()
|
||||||
repo := filepath.Join(actionRoot, "actions", "hello-world-docker-action")
|
repo := filepath.Join(actionRoot, "actions", "hello-world-docker-action")
|
||||||
require.NoError(t, os.MkdirAll(repo, 0o755))
|
gitMust(t, "", "init", "--template=", "--initial-branch=main", repo)
|
||||||
gitMust(t, "", "init", "--initial-branch=main", repo)
|
gitMust(t, repo, "commit", "--allow-empty", "-m", "initial")
|
||||||
gitMust(t, repo, "config", "user.email", "test@test")
|
|
||||||
gitMust(t, repo, "config", "user.name", "test")
|
|
||||||
require.NoError(t, os.WriteFile(filepath.Join(repo, "action.yml"),
|
|
||||||
[]byte("name: hello\nruns:\n using: node24\n main: index.js\n"), 0o644))
|
|
||||||
gitMust(t, repo, "add", ".")
|
|
||||||
gitMust(t, repo, "commit", "-m", "initial")
|
|
||||||
output, err := exec.Command("git", "-C", repo, "rev-parse", "--short=7", "HEAD").Output()
|
output, err := exec.Command("git", "-C", repo, "rev-parse", "--short=7", "HEAD").Output()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -393,7 +387,7 @@ func TestStepActionRemotePreResolvesDownloadedCommit(t *testing.T) {
|
|||||||
[]byte("name: setup-go\nruns:\n using: node20\n main: index.js\n"), 0o600))
|
[]byte("name: setup-go\nruns:\n using: node20\n main: index.js\n"), 0o600))
|
||||||
|
|
||||||
for _, args := range [][]string{
|
for _, args := range [][]string{
|
||||||
{"init", "--initial-branch=main", actionDir},
|
{"init", "--template=", "--initial-branch=main", actionDir},
|
||||||
{"-C", actionDir, "add", "action.yml"},
|
{"-C", actionDir, "add", "action.yml"},
|
||||||
{"-C", actionDir, "-c", "user.name=runner", "-c", "[email protected]", "-c", "commit.gpgsign=false", "commit", "-m", "action"},
|
{"-C", actionDir, "-c", "user.name=runner", "-c", "[email protected]", "-c", "commit.gpgsign=false", "commit", "-m", "action"},
|
||||||
} {
|
} {
|
||||||
|
|||||||
@@ -34,6 +34,6 @@ Works like `actions/checkout` with these inputs. Any other input fails the step.
|
|||||||
|
|
||||||
A branch is checked out as a local branch tracking `origin`, a tag or commit as a detached `HEAD`. A triggering tag that moved since the event fails the step. The step outputs `ref` and `commit` like `actions/checkout`.
|
A branch is checked out as a local branch tracking `origin`, a tag or commit as a detached `HEAD`. A triggering tag that moved since the event fails the step. The step outputs `ref` and `commit` like `actions/checkout`.
|
||||||
|
|
||||||
Persisted credentials end with the job. `token` is only sent to `github.server_url`, while `ssh-key` is offered to any SSH host, as with `actions/checkout`. The runner's `client_cert_file` is only offered to `github.server_url` and only during the step, so later steps do not get it. Without `ssh-key`, submodule URLs of the form `git@<server host>:` are fetched from `github.server_url` with `token`. With `ssh-key`, the repository is fetched from the SSH URL in the event's `repository.ssh_url`, or from the server's host on port 22.
|
Persisted credentials end with the job. `token` is only sent to `github.server_url`, while `ssh-key` is offered to any SSH host, as with `actions/checkout`. The runner's `client_cert_file` is only offered to `github.server_url` and only during the step, so later steps do not get it. Its `ca_file` replaces the job image's CA bundle for `github.server_url`, in later steps too when credentials persist. Without `ssh-key`, submodule URLs of the form `git@<server host>:` are fetched from `github.server_url` with `token`. With `ssh-key`, the repository is fetched from the SSH URL in the event's `repository.ssh_url`, or from the server's host on port 22.
|
||||||
|
|
||||||
With `gitea-runner exec`, checking out the workflow's own repository copies your local working directory, unless `--no-skip-checkout` or `ssh-key` is set.
|
With `gitea-runner exec`, checking out the workflow's own repository copies your local working directory, unless `--no-skip-checkout` or `ssh-key` is set.
|
||||||
+1
-1
@@ -109,4 +109,4 @@ Services share the pod's network, so a step reaches one by its id or `localhost`
|
|||||||
|
|
||||||
## Unsupported
|
## Unsupported
|
||||||
|
|
||||||
Docker actions, `docker://` steps, and the `options`, `volumes` and `credentials` of the job container fail the job, as do `volumes` and `credentials` of services. Run such workflows on a [Docker in Docker](../examples/kubernetes/README.md) runner. Pull private images with `imagePullSecrets` in `pod_template`.
|
Docker actions, `docker://` steps, and the `options`, `volumes` and `credentials` of the job container fail the job, as do `volumes` and `credentials` of services. Run such workflows on a [Docker in Docker](../examples/kubernetes/README.md) runner. Pull private images with `imagePullSecrets` in `pod_template`, and mount what `container.volumes` would through its `volumes`.
|
||||||
@@ -8,7 +8,7 @@ docker run --privileged \
|
|||||||
-e GITEA_RUNNER_REGISTRATION_TOKEN=<runner_token> \
|
-e GITEA_RUNNER_REGISTRATION_TOKEN=<runner_token> \
|
||||||
-v "$PWD/data:/data" \
|
-v "$PWD/data:/data" \
|
||||||
-v runner-docker:/var/lib/docker \
|
-v runner-docker:/var/lib/docker \
|
||||||
--name my_runner gitea/runner:nightly-dind
|
--name my_runner gitea/runner:latest-dind
|
||||||
```
|
```
|
||||||
|
|
||||||
The volumes keep the runner's registration and the job image cache. See [image flavours](../../README.md#image-flavours) for alternatives.
|
The volumes keep the runner's registration and the job image cache. See [image flavours](../../README.md#image-flavours) for alternatives.
|
||||||
@@ -85,7 +85,7 @@ spec:
|
|||||||
restartPolicy: Always
|
restartPolicy: Always
|
||||||
containers:
|
containers:
|
||||||
- name: runner
|
- name: runner
|
||||||
image: gitea/runner:nightly
|
image: gitea/runner:latest
|
||||||
env:
|
env:
|
||||||
- name: GITEA_INSTANCE_URL
|
- name: GITEA_INSTANCE_URL
|
||||||
value: http://gitea-http.gitea.svc.cluster.local:3000
|
value: http://gitea-http.gitea.svc.cluster.local:3000
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ spec:
|
|||||||
terminationGracePeriodSeconds: 10800 # keep above runner.shutdown_timeout, see README
|
terminationGracePeriodSeconds: 10800 # keep above runner.shutdown_timeout, see README
|
||||||
containers:
|
containers:
|
||||||
- name: runner
|
- name: runner
|
||||||
image: gitea/runner:nightly
|
image: gitea/runner:latest
|
||||||
env:
|
env:
|
||||||
- name: GITEA_INSTANCE_URL
|
- name: GITEA_INSTANCE_URL
|
||||||
value: http://gitea-http.gitea.svc.cluster.local:3000
|
value: http://gitea-http.gitea.svc.cluster.local:3000
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ spec:
|
|||||||
fsGroup: 1000
|
fsGroup: 1000
|
||||||
containers:
|
containers:
|
||||||
- name: runner
|
- name: runner
|
||||||
image: gitea/runner:nightly-dind-rootless
|
image: gitea/runner:latest-dind-rootless
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
env:
|
env:
|
||||||
- name: DOCKER_HOST
|
- name: DOCKER_HOST
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ spec:
|
|||||||
restartPolicy: Always
|
restartPolicy: Always
|
||||||
containers:
|
containers:
|
||||||
- name: runner
|
- name: runner
|
||||||
image: gitea/runner:nightly
|
image: gitea/runner:latest
|
||||||
env:
|
env:
|
||||||
- name: GITEA_INSTANCE_URL
|
- name: GITEA_INSTANCE_URL
|
||||||
value: http://gitea-http.gitea.svc.cluster.local:3000
|
value: http://gitea-http.gitea.svc.cluster.local:3000
|
||||||
|
|||||||
@@ -128,6 +128,11 @@ func (*daemonTestService) UpdateLog(_ context.Context, req *runnerv1.UpdateLogRe
|
|||||||
func TestDaemonRetriesDeclareOutagesAndRemovesOnlyConsumedEphemeralRegistration(t *testing.T) {
|
func TestDaemonRetriesDeclareOutagesAndRemovesOnlyConsumedEphemeralRegistration(t *testing.T) {
|
||||||
defer func(delay time.Duration) { declareRetryDelay = delay }(declareRetryDelay)
|
defer func(delay time.Duration) { declareRetryDelay = delay }(declareRetryDelay)
|
||||||
declareRetryDelay = 0
|
declareRetryDelay = 0
|
||||||
|
dir := t.TempDir()
|
||||||
|
regFile := filepath.Join(dir, "registration.json")
|
||||||
|
configFile := filepath.Join(dir, "config.yaml")
|
||||||
|
require.NoError(t, os.WriteFile(configFile, []byte("runner:\n file: "+regFile+"\n idle_cleanup_interval: 0s\ncache:\n enabled: false\n"), 0o600))
|
||||||
|
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
ephemeral, beforeTask bool
|
ephemeral, beforeTask bool
|
||||||
@@ -154,10 +159,6 @@ func TestDaemonRetriesDeclareOutagesAndRemovesOnlyConsumedEphemeralRegistration(
|
|||||||
connecthttp.Mount(mux, rpcServer, connecthttp.WithReadMaxBytes(0))
|
connecthttp.Mount(mux, rpcServer, connecthttp.WithReadMaxBytes(0))
|
||||||
server := httptest.NewServer(http.StripPrefix("/api/actions", mux))
|
server := httptest.NewServer(http.StripPrefix("/api/actions", mux))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
dir := t.TempDir()
|
|
||||||
regFile := filepath.Join(dir, "registration.json")
|
|
||||||
configFile := filepath.Join(dir, "config.yaml")
|
|
||||||
require.NoError(t, os.WriteFile(configFile, []byte("runner:\n file: "+regFile+"\n idle_cleanup_interval: 0s\ncache:\n enabled: false\n"), 0o600))
|
|
||||||
require.NoError(t, config.SaveRegistration(regFile, &config.Registration{Address: server.URL, UUID: "test", Name: "test", Token: "test", Labels: []string{"host:host"}, Ephemeral: tc.ephemeral}))
|
require.NoError(t, config.SaveRegistration(regFile, &config.Registration{Address: server.URL, UUID: "test", Name: "test", Token: "test", Labels: []string{"host:host"}, Ephemeral: tc.ephemeral}))
|
||||||
err := runDaemon(ctx, &daemonArgs{Once: true}, &configFile)(nil, nil)
|
err := runDaemon(ctx, &daemonArgs{Once: true}, &configFile)(nil, nil)
|
||||||
if tc.declareErr == nil && tc.fetchErr == nil || tc.beforeTask {
|
if tc.declareErr == nil && tc.fetchErr == nil || tc.beforeTask {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"encoding/json/v2"
|
"encoding/json/v2"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"maps"
|
"maps"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@@ -228,7 +229,7 @@ func (i *executeArgs) resolve(path string) string {
|
|||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
func printList(plan *model.Plan) {
|
func printList(out io.Writer, plan *model.Plan) {
|
||||||
type lineInfoDef struct {
|
type lineInfoDef struct {
|
||||||
jobID string
|
jobID string
|
||||||
jobName string
|
jobName string
|
||||||
@@ -288,7 +289,7 @@ func printList(plan *model.Plan) {
|
|||||||
wfNameMaxWidth += 2
|
wfNameMaxWidth += 2
|
||||||
wfFileMaxWidth += 2
|
wfFileMaxWidth += 2
|
||||||
|
|
||||||
fmt.Printf("%*s%*s%*s%*s%*s%*s\n",
|
fmt.Fprintf(out, "%*s%*s%*s%*s%*s%*s\n",
|
||||||
-stageMaxWidth, header.stage,
|
-stageMaxWidth, header.stage,
|
||||||
-jobIDMaxWidth, header.jobID,
|
-jobIDMaxWidth, header.jobID,
|
||||||
-jobNameMaxWidth, header.jobName,
|
-jobNameMaxWidth, header.jobName,
|
||||||
@@ -297,7 +298,7 @@ func printList(plan *model.Plan) {
|
|||||||
-eventsMaxWidth, header.events,
|
-eventsMaxWidth, header.events,
|
||||||
)
|
)
|
||||||
for _, line := range lineInfos {
|
for _, line := range lineInfos {
|
||||||
fmt.Printf("%*s%*s%*s%*s%*s%*s\n",
|
fmt.Fprintf(out, "%*s%*s%*s%*s%*s%*s\n",
|
||||||
-stageMaxWidth, line.stage,
|
-stageMaxWidth, line.stage,
|
||||||
-jobIDMaxWidth, line.jobID,
|
-jobIDMaxWidth, line.jobID,
|
||||||
-jobNameMaxWidth, line.jobName,
|
-jobNameMaxWidth, line.jobName,
|
||||||
@@ -307,11 +308,11 @@ func printList(plan *model.Plan) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
if duplicateJobIDs {
|
if duplicateJobIDs {
|
||||||
fmt.Print("\nDetected multiple jobs with the same job name, use `-W` to specify the path to the specific workflow.\n")
|
fmt.Fprint(out, "\nDetected multiple jobs with the same job name, use `-W` to specify the path to the specific workflow.\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runExecList(planner model.WorkflowPlanner, execArgs *executeArgs) error {
|
func runExecList(out io.Writer, planner model.WorkflowPlanner, execArgs *executeArgs) error {
|
||||||
// plan with filtered jobs - to be used for filtering only
|
// plan with filtered jobs - to be used for filtering only
|
||||||
var filterPlan *model.Plan
|
var filterPlan *model.Plan
|
||||||
|
|
||||||
@@ -347,7 +348,7 @@ func runExecList(planner model.WorkflowPlanner, execArgs *executeArgs) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
printList(filterPlan)
|
printList(out, filterPlan)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -405,7 +406,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
if execArgs.runList {
|
if execArgs.runList {
|
||||||
return runExecList(planner, execArgs)
|
return runExecList(cmd.OutOrStdout(), planner, execArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// plan with triggered jobs
|
// plan with triggered jobs
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -76,40 +75,35 @@ func TestExecuteArgsLoadInputs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExecuteArgsEventJSON(t *testing.T) {
|
func TestExecuteArgsEventJSON(t *testing.T) {
|
||||||
payload := func(content string) string {
|
dir := t.TempDir()
|
||||||
path := filepath.Join(t.TempDir(), "event.json")
|
|
||||||
require.NoError(t, os.WriteFile(path, []byte(content), 0o600))
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
eventpath string
|
payload string
|
||||||
inputs []string
|
inputs []string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "keeps a payload without inputs to merge",
|
name: "keeps a payload without inputs to merge",
|
||||||
eventpath: payload(`{"inputs": {"kept": "from_event"}}`),
|
payload: `{"inputs": {"kept": "from_event"}}`,
|
||||||
expected: `{"inputs": {"kept": "from_event"}}`,
|
expected: `{"inputs": {"kept": "from_event"}}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "overrides the event inputs it names, keeping the rest",
|
name: "overrides the event inputs it names, keeping the rest",
|
||||||
eventpath: payload(`{"inputs": {"kept": "from_event", "named": "from_event"}}`),
|
payload: `{"inputs": {"kept": "from_event", "named": "from_event"}}`,
|
||||||
inputs: []string{"named=from_cli"},
|
inputs: []string{"named=from_cli"},
|
||||||
expected: `{"inputs": {"kept": "from_event", "named": "from_cli"}}`,
|
expected: `{"inputs": {"kept": "from_event", "named": "from_cli"}}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "adds inputs to a payload carrying none",
|
name: "adds inputs to a payload carrying none",
|
||||||
eventpath: payload(`{"repository": {"name": "test-repo"}}`),
|
payload: `{"repository": {"name": "test-repo"}}`,
|
||||||
inputs: []string{"flag=val"},
|
inputs: []string{"flag=val"},
|
||||||
expected: `{"repository": {"name": "test-repo"}, "inputs": {"flag": "val"}}`,
|
expected: `{"repository": {"name": "test-repo"}, "inputs": {"flag": "val"}}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "handles a null payload",
|
name: "handles a null payload",
|
||||||
eventpath: payload("null"),
|
payload: "null",
|
||||||
inputs: []string{"flag=val"},
|
inputs: []string{"flag=val"},
|
||||||
expected: `{"inputs": {"flag": "val"}}`,
|
expected: `{"inputs": {"flag": "val"}}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "builds a payload without an event file",
|
name: "builds a payload without an event file",
|
||||||
@@ -120,7 +114,12 @@ func TestExecuteArgsEventJSON(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
eventJSON, err := (&executeArgs{eventpath: tt.eventpath, inputs: tt.inputs}).eventJSON()
|
var eventpath string
|
||||||
|
if tt.payload != "" {
|
||||||
|
eventpath = filepath.Join(dir, tt.name+".json")
|
||||||
|
require.NoError(t, os.WriteFile(eventpath, []byte(tt.payload), 0o600))
|
||||||
|
}
|
||||||
|
eventJSON, err := (&executeArgs{eventpath: eventpath, inputs: tt.inputs}).eventJSON()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.JSONEq(t, tt.expected, eventJSON)
|
require.JSONEq(t, tt.expected, eventJSON)
|
||||||
})
|
})
|
||||||
@@ -182,19 +181,18 @@ func TestRunExecListUsesJobEventAndAllPlans(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
out := captureStdout(t, func() {
|
var out bytes.Buffer
|
||||||
require.NoError(t, runExecList(planner, &executeArgs{job: "build"}))
|
require.NoError(t, runExecList(&out, planner, &executeArgs{job: "build"}))
|
||||||
require.NoError(t, runExecList(planner, &executeArgs{event: "push"}))
|
require.NoError(t, runExecList(&out, planner, &executeArgs{event: "push"}))
|
||||||
require.NoError(t, runExecList(planner, &executeArgs{autodetectEvent: true}))
|
require.NoError(t, runExecList(&out, planner, &executeArgs{autodetectEvent: true}))
|
||||||
require.NoError(t, runExecList(planner, &executeArgs{}))
|
require.NoError(t, runExecList(&out, planner, &executeArgs{}))
|
||||||
emptyPlanner, err := model.NewWorkflowPlanner(t.TempDir(), false)
|
emptyPlanner, err := model.NewWorkflowPlanner(t.TempDir(), false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, runExecList(emptyPlanner, &executeArgs{autodetectEvent: true}))
|
require.NoError(t, runExecList(&out, emptyPlanner, &executeArgs{autodetectEvent: true}))
|
||||||
})
|
|
||||||
|
|
||||||
require.Contains(t, out, "Build")
|
require.Contains(t, out.String(), "Build")
|
||||||
require.Contains(t, out, "Test")
|
require.Contains(t, out.String(), "Test")
|
||||||
require.Contains(t, out, "Lint")
|
require.Contains(t, out.String(), "Lint")
|
||||||
require.Equal(t, []string{"job:build", "event:push", "event:push", "all"}, planner.calls)
|
require.Equal(t, []string{"job:build", "event:push", "event:push", "all"}, planner.calls)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,14 +206,13 @@ func TestPrintListReportsDuplicateJobIDs(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}}}
|
}}}
|
||||||
|
|
||||||
out := captureStdout(t, func() {
|
var out bytes.Buffer
|
||||||
printList(plan)
|
printList(&out, plan)
|
||||||
})
|
|
||||||
|
|
||||||
require.Contains(t, out, "Workflow file")
|
require.Contains(t, out.String(), "Workflow file")
|
||||||
require.Contains(t, out, "Build A")
|
require.Contains(t, out.String(), "Build A")
|
||||||
require.Contains(t, out, "Build B")
|
require.Contains(t, out.String(), "Build B")
|
||||||
require.Contains(t, out, "Detected multiple jobs with the same job name")
|
require.Contains(t, out.String(), "Detected multiple jobs with the same job name")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadExecCmdDefinesExpectedFlags(t *testing.T) {
|
func TestLoadExecCmdDefinesExpectedFlags(t *testing.T) {
|
||||||
@@ -278,41 +275,13 @@ func workflowForList(name, file, event, jobID, jobName string) *model.Workflow {
|
|||||||
return &model.Workflow{
|
return &model.Workflow{
|
||||||
Name: name,
|
Name: name,
|
||||||
File: file,
|
File: file,
|
||||||
RawOn: rawOnNode(event),
|
RawOn: yaml.Node{Kind: yaml.ScalarNode, Tag: "!!str", Value: event},
|
||||||
Jobs: map[string]*model.Job{
|
Jobs: map[string]*model.Job{
|
||||||
jobID: {Name: jobName},
|
jobID: {Name: jobName},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawOnNode(event string) yaml.Node {
|
|
||||||
var node yaml.Node
|
|
||||||
if err := yaml.Unmarshal([]byte(event), &node); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return *node.Content[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
func captureStdout(t *testing.T, fn func()) string {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
old := os.Stdout
|
|
||||||
r, w, err := os.Pipe()
|
|
||||||
require.NoError(t, err)
|
|
||||||
os.Stdout = w
|
|
||||||
|
|
||||||
fn()
|
|
||||||
|
|
||||||
require.NoError(t, w.Close())
|
|
||||||
os.Stdout = old
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
_, err = io.Copy(&buf, r)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.NoError(t, r.Close())
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExecuteArgsLoadEnvsResultsOrigin(t *testing.T) {
|
func TestExecuteArgsLoadEnvsResultsOrigin(t *testing.T) {
|
||||||
t.Setenv("ACTIONS_RESULTS_URL", "") // the default is only supplied when nothing else does
|
t.Setenv("ACTIONS_RESULTS_URL", "") // the default is only supplied when nothing else does
|
||||||
handler, err := artifactcache.StartHandler(artifactcache.Options{Dir: t.TempDir(), OutboundIP: "127.0.0.1"})
|
handler, err := artifactcache.StartHandler(artifactcache.Options{Dir: t.TempDir(), OutboundIP: "127.0.0.1"})
|
||||||
|
|||||||
@@ -27,16 +27,9 @@ func TestRunPostTaskScriptSkippedWhenEmpty(t *testing.T) {
|
|||||||
r := &Runner{
|
r := &Runner{
|
||||||
cfg: &config.Config{},
|
cfg: &config.Config{},
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(t.Context())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
taskCtx, err := structpb.NewStruct(map[string]any{})
|
|
||||||
require.NoError(t, err)
|
|
||||||
task := &runnerv1.Task{Id: 1, Context: taskCtx}
|
|
||||||
reporter := report.NewReporter(ctx, cancel, nil, task, r.cfg)
|
|
||||||
|
|
||||||
require.NotPanics(t, func() {
|
require.NotPanics(t, func() {
|
||||||
r.runPostTaskScript(ctx, reporter, task, "/workspace/owner/repo")
|
r.runPostTaskScript(t.Context(), nil, nil, "/workspace/owner/repo")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,9 +52,7 @@ func TestRunPostTaskScriptNonZeroExitDoesNotPanic(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(t.Context())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
taskCtx, err := structpb.NewStruct(map[string]any{})
|
task := &runnerv1.Task{Id: 1, Context: &structpb.Struct{}}
|
||||||
require.NoError(t, err)
|
|
||||||
task := &runnerv1.Task{Id: 1, Context: taskCtx}
|
|
||||||
reporter := report.NewReporter(ctx, cancel, nil, task, cfg)
|
reporter := report.NewReporter(ctx, cancel, nil, task, cfg)
|
||||||
|
|
||||||
require.NotPanics(t, func() {
|
require.NotPanics(t, func() {
|
||||||
@@ -146,9 +137,7 @@ func TestRunPostTaskScriptIntegration(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(t.Context())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
taskCtx, err := structpb.NewStruct(map[string]any{})
|
task := &runnerv1.Task{Id: 11, Context: &structpb.Struct{}}
|
||||||
require.NoError(t, err)
|
|
||||||
task := &runnerv1.Task{Id: 11, Context: taskCtx}
|
|
||||||
reporter := report.NewReporter(ctx, cancel, nil, task, cfg)
|
reporter := report.NewReporter(ctx, cancel, nil, task, cfg)
|
||||||
setReporterJobResult(t, reporter, runnerv1.Result_RESULT_SUCCESS)
|
setReporterJobResult(t, reporter, runnerv1.Result_RESULT_SUCCESS)
|
||||||
|
|
||||||
|
|||||||
@@ -98,18 +98,20 @@ func NewRunner(cfg *config.Config, reg *config.Registration, cli client.Client)
|
|||||||
}
|
}
|
||||||
envs := make(map[string]string, len(cfg.Runner.Envs))
|
envs := make(map[string]string, len(cfg.Runner.Envs))
|
||||||
maps.Copy(envs, cfg.Runner.Envs)
|
maps.Copy(envs, cfg.Runner.Envs)
|
||||||
|
instanceTransport := client.NewTransport(cli.Address(), cfg.Runner.TLSConfig())
|
||||||
var cacheHandler *artifactcache.Handler
|
var cacheHandler *artifactcache.Handler
|
||||||
if cfg.Cache.Enabled == nil || *cfg.Cache.Enabled {
|
if cfg.Cache.Enabled == nil || *cfg.Cache.Enabled {
|
||||||
warnIgnoredCachePolicy(cfg)
|
warnIgnoredCachePolicy(cfg)
|
||||||
warnIgnoredCacheSecret(cfg)
|
warnIgnoredCacheSecret(cfg)
|
||||||
handler, err := artifactcache.StartHandler(artifactcache.Options{
|
handler, err := artifactcache.StartHandler(artifactcache.Options{
|
||||||
Dir: cfg.Cache.Dir,
|
Dir: cfg.Cache.Dir,
|
||||||
OutboundIP: cfg.Cache.Host,
|
OutboundIP: cfg.Cache.Host,
|
||||||
Port: cfg.Cache.Port,
|
Port: cfg.Cache.Port,
|
||||||
Upstream: cfg.Cache.ExternalServer,
|
Upstream: cfg.Cache.ExternalServer,
|
||||||
S3: cacheS3(cfg),
|
S3: cacheS3(cfg),
|
||||||
Policy: CachePolicy(cfg),
|
Policy: CachePolicy(cfg),
|
||||||
Logger: logging.Default().With("module", "cache_request"),
|
Logger: logging.Default().With("module", "cache_request"),
|
||||||
|
InstanceTransport: instanceTransport,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Errorf("cannot init cache server, it will be disabled: %v", err)
|
logging.Errorf("cannot init cache server, it will be disabled: %v", err)
|
||||||
@@ -140,7 +142,7 @@ func NewRunner(cfg *config.Config, reg *config.Registration, cli client.Client)
|
|||||||
runHealthCheck: executeHealthCheck,
|
runHealthCheck: executeHealthCheck,
|
||||||
}
|
}
|
||||||
runner.isolatedCacheContainer = sync.OnceValue(runner.detectIsolatedCacheContainer)
|
runner.isolatedCacheContainer = sync.OnceValue(runner.detectIsolatedCacheContainer)
|
||||||
runner.instanceTransport = client.NewTransport(cli.Address(), cfg.Runner.TLSConfig())
|
runner.instanceTransport = instanceTransport
|
||||||
return runner
|
return runner
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,7 +612,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
|||||||
},
|
},
|
||||||
ContainerOptions: r.cfg.Container.Options,
|
ContainerOptions: r.cfg.Container.Options,
|
||||||
ServiceReadyTimeout: r.cfg.Container.ServiceReadyTimeout,
|
ServiceReadyTimeout: r.cfg.Container.ServiceReadyTimeout,
|
||||||
NoSweep: r.cfg.Container.Sweep != nil && !*r.cfg.Container.Sweep,
|
Sweep: r.cfg.Container.Sweep,
|
||||||
ContainerDaemonSocket: r.cfg.Container.DockerHost,
|
ContainerDaemonSocket: r.cfg.Container.DockerHost,
|
||||||
Privileged: r.cfg.Container.Privileged,
|
Privileged: r.cfg.Container.Privileged,
|
||||||
DefaultActionInstance: r.getDefaultActionsURL(task),
|
DefaultActionInstance: r.getDefaultActionsURL(task),
|
||||||
@@ -620,10 +622,12 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
|||||||
JobCompletedHook: r.cfg.Runner.Hooks.JobCompleted,
|
JobCompletedHook: r.cfg.Runner.Hooks.JobCompleted,
|
||||||
Vars: task.Vars,
|
Vars: task.Vars,
|
||||||
ValidVolumes: r.cfg.Container.ValidVolumes,
|
ValidVolumes: r.cfg.Container.ValidVolumes,
|
||||||
|
ContainerVolumes: r.cfg.Container.Volumes,
|
||||||
SharedToolCache: r.cfg.Runner.ToolCacheMode == config.ToolCacheModeShared,
|
SharedToolCache: r.cfg.Runner.ToolCacheMode == config.ToolCacheModeShared,
|
||||||
InsecureSkipTLS: r.cfg.Runner.Insecure,
|
InsecureSkipTLS: r.cfg.Runner.Insecure,
|
||||||
ClientCertFile: r.cfg.Runner.ClientCertFile,
|
ClientCertFile: r.cfg.Runner.ClientCertFile,
|
||||||
ClientKeyFile: r.cfg.Runner.ClientKeyFile,
|
ClientKeyFile: r.cfg.Runner.ClientKeyFile,
|
||||||
|
CAFile: r.cfg.Runner.CAFile,
|
||||||
InstanceTransport: r.instanceTransport,
|
InstanceTransport: r.instanceTransport,
|
||||||
RunnerName: r.name,
|
RunnerName: r.name,
|
||||||
KubernetesPicker: r.kubernetesOptions,
|
KubernetesPicker: r.kubernetesOptions,
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ import (
|
|||||||
|
|
||||||
func TestRunnerCleanupStaleTaskDirs(t *testing.T) {
|
func TestRunnerCleanupStaleTaskDirs(t *testing.T) {
|
||||||
now := time.Date(2026, time.April, 29, 20, 0, 0, 0, time.UTC)
|
now := time.Date(2026, time.April, 29, 20, 0, 0, 0, time.UTC)
|
||||||
workdirRoot := filepath.Join(t.TempDir(), "workspace")
|
workdirRoot := t.TempDir()
|
||||||
require.NoError(t, os.MkdirAll(workdirRoot, 0o700))
|
|
||||||
|
|
||||||
oldTask := filepath.Join(workdirRoot, "1001")
|
oldTask := filepath.Join(workdirRoot, "1001")
|
||||||
freshTask := filepath.Join(workdirRoot, "1002")
|
freshTask := filepath.Join(workdirRoot, "1002")
|
||||||
@@ -59,8 +58,7 @@ func TestRunnerCleanupStaleTaskDirs(t *testing.T) {
|
|||||||
// be reclaimed, while the shared tool_cache and operator data are preserved.
|
// be reclaimed, while the shared tool_cache and operator data are preserved.
|
||||||
func TestRunnerOnIdleCleansStaleHostScratchDirs(t *testing.T) {
|
func TestRunnerOnIdleCleansStaleHostScratchDirs(t *testing.T) {
|
||||||
now := time.Date(2026, time.April, 29, 20, 0, 0, 0, time.UTC)
|
now := time.Date(2026, time.April, 29, 20, 0, 0, 0, time.UTC)
|
||||||
hostRoot := filepath.Join(t.TempDir(), "act")
|
hostRoot := t.TempDir()
|
||||||
require.NoError(t, os.MkdirAll(hostRoot, 0o700))
|
|
||||||
|
|
||||||
staleScratch := filepath.Join(hostRoot, "0123456789abcdef") // 16 hex
|
staleScratch := filepath.Join(hostRoot, "0123456789abcdef") // 16 hex
|
||||||
freshScratch := filepath.Join(hostRoot, "fedcba9876543210")
|
freshScratch := filepath.Join(hostRoot, "fedcba9876543210")
|
||||||
@@ -118,8 +116,7 @@ func TestRunnerCleanupStaleTaskDirsMissingRoot(t *testing.T) {
|
|||||||
|
|
||||||
func TestRunnerCleanupStaleTaskDirsHonorsContext(t *testing.T) {
|
func TestRunnerCleanupStaleTaskDirsHonorsContext(t *testing.T) {
|
||||||
now := time.Date(2026, time.April, 29, 20, 0, 0, 0, time.UTC)
|
now := time.Date(2026, time.April, 29, 20, 0, 0, 0, time.UTC)
|
||||||
workdirRoot := filepath.Join(t.TempDir(), "workspace")
|
workdirRoot := t.TempDir()
|
||||||
require.NoError(t, os.MkdirAll(workdirRoot, 0o700))
|
|
||||||
|
|
||||||
for i := 1001; i <= 1003; i++ {
|
for i := 1001; i <= 1003; i++ {
|
||||||
dir := filepath.Join(workdirRoot, strconv.Itoa(i))
|
dir := filepath.Join(workdirRoot, strconv.Itoa(i))
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ func TestSetupLinesInputs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrettyOSName(t *testing.T) {
|
func TestPrettyOSName(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
for _, tt := range []struct {
|
for _, tt := range []struct {
|
||||||
name string
|
name string
|
||||||
osRelease string
|
osRelease string
|
||||||
@@ -109,7 +110,7 @@ func TestPrettyOSName(t *testing.T) {
|
|||||||
{"missing file", "", "", true},
|
{"missing file", "", "", true},
|
||||||
} {
|
} {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
path := filepath.Join(t.TempDir(), "os-release")
|
path := filepath.Join(dir, tt.name)
|
||||||
if !tt.missing {
|
if !tt.missing {
|
||||||
require.NoError(t, os.WriteFile(path, []byte(tt.osRelease), 0o600))
|
require.NoError(t, os.WriteFile(path, []byte(tt.osRelease), 0o600))
|
||||||
}
|
}
|
||||||
|
|||||||
Loaded 50 of 62 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user