Compare commits

...
20 Commits
Author SHA1 Message Date
rosekanari bcc0b715cd fix: repair free-disk-space build on illumos, Solaris, NetBSD and OpenBSD (#1416)
The runner did not build on illumos, Solaris, NetBSD and OpenBSD: `internal/pkg/disk` called `unix.Statfs`, which `golang.org/x/sys/unix` lacks on illumos, Solaris and NetBSD (they have `statvfs(2)`) and exposes with `F_`-prefixed fields on OpenBSD. Each now has an implementation matching its syscall.

FreeBSD and DragonFly report a negative available-block count once root writes into the reserved blocks. It wrapped to ~16 EiB free, so the disk health check and cache eviction saw plenty of space exactly when the disk was full. A shared helper clamps it to zero and absorbs the per-platform integer types.

CI only built for the host, which let this and https://gitea.com/gitea/runner/pulls/1098 through. `make cross-check` vets code and tests on one target per distinct set of platform files, plus linux/arm for its 32-bit syscall fields, and runs as its own job in parallel to the others. It also surfaced docker-only tests lacking the docker build tag, which are fixed too.

Assisted-by: Claude Code:claude-opus-5-5
Co-authored-by: rosekanari <[email protected]>
2026-11-18 04:20:56 +00:00
silverwindandbircni 0e4c8b6b78 fix: misc improvements (#1415)
- Stop overwriting the image's `ImageOS`. `ubuntu-latest` got `ubuntu20` on the 24.04 default image.
- Derive `ImageOS` from `os-release` when the image sets none. Fall back to `ubuntu24` for `ubuntu-latest`.
- Keep an `ImageOS` set in the job, step or container env.
- Honor the image's `ImageOS` on Kubernetes.
- Treat steps after a job timeout as cancelled. `cancelled()` and `always()` cleanup now runs. The job still fails.
- Record nested reusable workflow results. Jobs that `needs:` a nested call now run.
- Forward outputs through nested reusable workflows. A bad output fails the call.
- Pass the job's `GITHUB_TOKEN` and `GITEA_TOKEN` to called workflows by default. An explicit mapping overrides them.
- Probe a started container's uid and gid concurrently.
- Cache the Docker container env from its first inspect.
- Check `ImageOS` in the Kubernetes e2e test.

---------

Co-authored-by: bircni <[email protected]>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1415
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
2026-11-16 20:51:26 +00:00
silverwind 1f2ea1b83a fix: honor zero and empty values for fetch backoff and idle cleanup (#1418)
`fetch_interval_max: 0` is documented to disable polling backoff but became 5s. Zeros for `workdir_cleanup_age` and `idle_cleanup_interval` were ignored when they came from a YAML merge key or alias, so cleanup still ran, while an empty or null value turned cleanup off. These defaults are now seeded before the file is read, as `cache` already does, so a written 0 means off and an empty value keeps the default.

_Written by Claude (Opus 5.5)._

Reviewed-on: https://gitea.com/gitea/runner/pulls/1418
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
2026-11-16 20:43:37 +00:00
Renovate Bot 891f3fde38 fix(deps): update dependencies (#1414)
This PR contains the following updates:

| Package | Type | Update | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|---|---|
| docker.gitea.com/runner-images |  | digest | `b96ba46` → `139605d` |  |  |
| [docker/login-action](https://github.com/docker/login-action) ([changelog](https://github.com/docker/login-action/compare/81c6f93d4bc991e510b342a00b419b3bb4efc5c6..8aa5831fb8d48d8f76594c7ddde61ae58019f550)) | action | digest | `81c6f93` → `8aa5831` |  |  |
| [github.com/spf13/pflag](https://github.com/spf13/pflag) | require | minor | `v1.0.10` → `v1.1.0` | ![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fspf13%2fpflag/v1.1.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fspf13%2fpflag/v1.0.10/v1.1.0?slim=true) |
| [go](https://go.dev/) ([source](https://github.com/golang/go)) | toolchain | patch | `1.27.3` → `1.27.4` | ![age](https://developer.mend.io/api/mc/badges/age/golang-version/go/1.27.4?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/golang-version/go/1.27.3/1.27.4?slim=true) |
| [golang.org/x/sync](https://pkg.go.dev/golang.org/x/sync) | require | minor | [`v0.24.0` → `v0.25.0`](https://cs.opensource.google/go/x/sync/+/refs/tags/v0.24.0...refs/tags/v0.25.0) | ![age](https://developer.mend.io/api/mc/badges/age/go/golang.org%2fx%2fsync/v0.25.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/golang.org%2fx%2fsync/v0.24.0/v0.25.0?slim=true) |
| [golang.org/x/sys](https://pkg.go.dev/golang.org/x/sys) | require | minor | [`v0.49.0` → `v0.50.0`](https://cs.opensource.google/go/x/sys/+/refs/tags/v0.49.0...refs/tags/v0.50.0) | ![age](https://developer.mend.io/api/mc/badges/age/go/golang.org%2fx%2fsys/v0.50.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/golang.org%2fx%2fsys/v0.49.0/v0.50.0?slim=true) |
| [golang.org/x/term](https://pkg.go.dev/golang.org/x/term) | require | minor | [`v0.47.0` → `v0.48.0`](https://cs.opensource.google/go/x/term/+/refs/tags/v0.47.0...refs/tags/v0.48.0) | ![age](https://developer.mend.io/api/mc/badges/age/go/golang.org%2fx%2fterm/v0.48.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/golang.org%2fx%2fterm/v0.47.0/v0.48.0?slim=true) |
| [golang.org/x/text](https://pkg.go.dev/golang.org/x/text) | require | minor | [`v0.43.0` → `v0.44.0`](https://cs.opensource.google/go/x/text/+/refs/tags/v0.43.0...refs/tags/v0.44.0) | ![age](https://developer.mend.io/api/mc/badges/age/go/golang.org%2fx%2ftext/v0.44.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/golang.org%2fx%2ftext/v0.43.0/v0.44.0?slim=true) |
| [quay.io/containers/podman](https://quay.io/containers/podman) ([source](https://github.com/podman-container-tools/podman)) |  | major | `v5.8.9-immutable` → `v6.1.3-immutable` | ![age](https://developer.mend.io/api/mc/badges/age/docker/quay.io%2fcontainers%2fpodman/v6.1.3?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/docker/quay.io%2fcontainers%2fpodman/v5.8.9/v6.1.3?slim=true) |

---

### HTTP/1 server crash due to MaxBytesReader header race in net/http
[CVE-2026-97054](https://nvd.nist.gov/vuln/detail/CVE-2026-97054) / [GO-2026-6859](https://pkg.go.dev/vuln/GO-2026-6859)

<details>
<summary>More information</summary>

#### Details
For HTTP/1 servers, when MaxBytesReader's limit is exceeded, "Connection: close" header is automatically set without synchronization, which might race with another header being set explicitly in the server handler. As a result, an HTTP/1 server that utilizes MaxBytesReader or MaxBytesHandler can crash due to runtime panic if its handler reads the request body concurrently with writing the response header.

#### Severity
Unknown

#### References
- [https://go.dev/cl/862185](https://go.dev/cl/862185)
- [https://go.dev/issue/82563](https://go.dev/issue/82563)
- [https://groups.google.com/g/golang-announce/c/iY8TY0wWgbM](https://groups.google.com/g/golang-announce/c/iY8TY0wWgbM)

This data is provided by [OSV](https://osv.dev/vulnerability/GO-2026-6859) and the [Go Vulnerability Database](https://github.com/golang/vulndb) ([CC-BY 4.0](https://github.com/golang/vulndb#license)).
</details>

---

### Release Notes

<details>
<summary>spf13/pflag (github.com/spf13/pflag)</summary>

### [`v1.1.0`](https://github.com/spf13/pflag/releases/tag/v1.1.0)

[Compare Source](https://github.com/spf13/pflag/compare/v1.0.10...v1.1.0)

It's been long enough, and enough things have been fixed, that it might be time to release a new version, even if there isn't any particular big new issue to market as the reason for this release.

If you notice anything breaking, it is entirely un-intentional, but you might also have been relying on [undocumented](https://www.hyrumslaw.com/) or [buggy](https://xkcd.com/1172/) behavior. Please file an issue describing what you're doing, how it worked before this release and why it doesn't work anymore, and pin your projects to `v1.0.10` (the latest release before this one) while we decide how to address your concerns.

#### What's Changed

- README: update badges and minor linting fixes by [@&#8203;thaJeztah](https://github.com/thaJeztah) in [#&#8203;452](https://github.com/spf13/pflag/pull/452)
- Show 'correct' explicit bool value syntax in help by [@&#8203;alimpfard](https://github.com/alimpfard) in [#&#8203;453](https://github.com/spf13/pflag/pull/453)
- Fix for Go 1.24 by [@&#8203;pterjan](https://github.com/pterjan) in [#&#8203;460](https://github.com/spf13/pflag/pull/460)
- fix(map): ensure string-to-string flags maintain stable pointers by [@&#8203;brandon1024](https://github.com/brandon1024) in [#&#8203;457](https://github.com/spf13/pflag/pull/457)
- Fix getFlagType error message by [@&#8203;wellitonscheer](https://github.com/wellitonscheer) in [#&#8203;462](https://github.com/spf13/pflag/pull/462)
- update actions, and fix linting issues by [@&#8203;thaJeztah](https://github.com/thaJeztah) in [#&#8203;450](https://github.com/spf13/pflag/pull/450)
- fix: README.md indicating the use of godoc(deprecated) by [@&#8203;malklera](https://github.com/malklera) in [#&#8203;467](https://github.com/spf13/pflag/pull/467)
- Fix broken link to POSIX argument conventions by [@&#8203;tomasaschan](https://github.com/tomasaschan) in [#&#8203;464](https://github.com/spf13/pflag/pull/464)
- Replace raw stdlib parse errors in typed flag Set methods ([#&#8203;269](https://github.com/spf13/pflag/issues/269)) by [@&#8203;reuvenharrison](https://github.com/reuvenharrison) in [#&#8203;469](https://github.com/spf13/pflag/pull/469)
- Extend `UnknownFlags` to `UnknownFlagsHandling` and introduce `PassUnknownFlagToArgs` ([#&#8203;337](https://github.com/spf13/pflag/issues/337)) by [@&#8203;ikedam](https://github.com/ikedam) in [#&#8203;440](https://github.com/spf13/pflag/pull/440)
- fix: allow nil default IP flags in GetIP by [@&#8203;happysnaker](https://github.com/happysnaker) in [#&#8203;483](https://github.com/spf13/pflag/pull/483)
- fix: allow hex input in UintSlice by [@&#8203;happysnaker](https://github.com/happysnaker) in [#&#8203;484](https://github.com/spf13/pflag/pull/484)
- fix: honor custom IsBoolFlag compatibility by [@&#8203;happysnaker](https://github.com/happysnaker) in [#&#8203;487](https://github.com/spf13/pflag/pull/487)
- docs: clarify SortFlags example with complete runnable program by [@&#8203;happysnaker](https://github.com/happysnaker) in [#&#8203;488](https://github.com/spf13/pflag/pull/488)
- docs: add release process documentation by [@&#8203;happysnaker](https://github.com/happysnaker) in [#&#8203;490](https://github.com/spf13/pflag/pull/490)
- fix: print to set destination, not hardcoded os.Stderr by [@&#8203;quite](https://github.com/quite) in [#&#8203;502](https://github.com/spf13/pflag/pull/502)
- ci: bump golangci-lint to v2.13 for Go 1.27 by [@&#8203;hdimer](https://github.com/hdimer) in [#&#8203;508](https://github.com/spf13/pflag/pull/508)
- Initialize the target map when a StringToString flag has a nil default by [@&#8203;nikolauspschuetz](https://github.com/nikolauspschuetz) in [#&#8203;506](https://github.com/spf13/pflag/pull/506)
- fix: honour deprecated ParseErrorsWhitelist.UnknownFlagsHandling by [@&#8203;lenamonj](https://github.com/lenamonj) in [#&#8203;507](https://github.com/spf13/pflag/pull/507)
- test: add StringSlice Append coverage by [@&#8203;LY-19418](https://github.com/LY-19418) in [#&#8203;504](https://github.com/spf13/pflag/pull/504)
- Keep wrapping after an unbreakable usage word by [@&#8203;AzazelSensei](https://github.com/AzazelSensei) in [#&#8203;503](https://github.com/spf13/pflag/pull/503)
- Validate IP slice values before appending or replacing by [@&#8203;agammann](https://github.com/agammann) in [#&#8203;513](https://github.com/spf13/pflag/pull/513)
- fix(ci): Use the latest golangci-lint release by [@&#8203;tomasaschan](https://github.com/tomasaschan) in [#&#8203;525](https://github.com/spf13/pflag/pull/525)
- Reject IPv6 addresses as IPv4 masks by [@&#8203;yuefdev](https://github.com/yuefdev) in [#&#8203;524](https://github.com/spf13/pflag/pull/524)
- Report the flag name as typed in deprecation warnings by [@&#8203;hdimer](https://github.com/hdimer) in [#&#8203;500](https://github.com/spf13/pflag/pull/500)
- Document non-interspersed argument parsing by [@&#8203;yuefdev](https://github.com/yuefdev) in [#&#8203;523](https://github.com/spf13/pflag/pull/523)
- Preserve trailing whitespace in StringToString formatting by [@&#8203;r4venrudy](https://github.com/r4venrudy) in [#&#8203;522](https://github.com/spf13/pflag/pull/522)
- Reject extra CSV records in StringToString arguments by [@&#8203;Harshil-1603](https://github.com/Harshil-1603) in [#&#8203;521](https://github.com/spf13/pflag/pull/521)
- Preserve current string values in CopyToGoFlagSet by [@&#8203;adenzhou1350](https://github.com/adenzhou1350) in [#&#8203;520](https://github.com/spf13/pflag/pull/520)
- Fix type identification and mismatch checks for text flags by [@&#8203;dewanshshekhar](https://github.com/dewanshshekhar) in [#&#8203;526](https://github.com/spf13/pflag/pull/526)
- fix: enforce native integer flag bounds on 32-bit platforms by [@&#8203;gdpu11](https://github.com/gdpu11) in [#&#8203;534](https://github.com/spf13/pflag/pull/534)
- fix: preserve count flag values when parsing fails by [@&#8203;gdpu11](https://github.com/gdpu11) in [#&#8203;533](https://github.com/spf13/pflag/pull/533)

#### New Contributors

- [@&#8203;alimpfard](https://github.com/alimpfard) made their first contribution in [#&#8203;453](https://github.com/spf13/pflag/pull/453)
- [@&#8203;pterjan](https://github.com/pterjan) made their first contribution in [#&#8203;460](https://github.com/spf13/pflag/pull/460)
- [@&#8203;brandon1024](https://github.com/brandon1024) made their first contribution in [#&#8203;457](https://github.com/spf13/pflag/pull/457)
- [@&#8203;wellitonscheer](https://github.com/wellitonscheer) made their first contribution in [#&#8203;462](https://github.com/spf13/pflag/pull/462)
- [@&#8203;malklera](https://github.com/malklera) made their first contribution in [#&#8203;467](https://github.com/spf13/pflag/pull/467)
- [@&#8203;reuvenharrison](https://github.com/reuvenharrison) made their first contribution in [#&#8203;469](https://github.com/spf13/pflag/pull/469)
- [@&#8203;ikedam](https://github.com/ikedam) made their first contribution in [#&#8203;440](https://github.com/spf13/pflag/pull/440)
- [@&#8203;happysnaker](https://github.com/happysnaker) made their first contribution in [#&#8203;483](https://github.com/spf13/pflag/pull/483)
- [@&#8203;quite](https://github.com/quite) made their first contribution in [#&#8203;502](https://github.com/spf13/pflag/pull/502)
- [@&#8203;hdimer](https://github.com/hdimer) made their first contribution in [#&#8203;508](https://github.com/spf13/pflag/pull/508)
- [@&#8203;nikolauspschuetz](https://github.com/nikolauspschuetz) made their first contribution in [#&#8203;506](https://github.com/spf13/pflag/pull/506)
- [@&#8203;lenamonj](https://github.com/lenamonj) made their first contribution in [#&#8203;507](https://github.com/spf13/pflag/pull/507)
- [@&#8203;LY-19418](https://github.com/LY-19418) made their first contribution in [#&#8203;504](https://github.com/spf13/pflag/pull/504)
- [@&#8203;AzazelSensei](https://github.com/AzazelSensei) made their first contribution in [#&#8203;503](https://github.com/spf13/pflag/pull/503)
- [@&#8203;agammann](https://github.com/agammann) made their first contribution in [#&#8203;513](https://github.com/spf13/pflag/pull/513)
- [@&#8203;yuefdev](https://github.com/yuefdev) made their first contribution in [#&#8203;524](https://github.com/spf13/pflag/pull/524)
- [@&#8203;r4venrudy](https://github.com/r4venrudy) made their first contribution in [#&#8203;522](https://github.com/spf13/pflag/pull/522)
- [@&#8203;Harshil-1603](https://github.com/Harshil-1603) made their first contribution in [#&#8203;521](https://github.com/spf13/pflag/pull/521)
- [@&#8203;adenzhou1350](https://github.com/adenzhou1350) made their first contribution in [#&#8203;520](https://github.com/spf13/pflag/pull/520)
- [@&#8203;dewanshshekhar](https://github.com/dewanshshekhar) made their first contribution in [#&#8203;526](https://github.com/spf13/pflag/pull/526)
- [@&#8203;gdpu11](https://github.com/gdpu11) made their first contribution in [#&#8203;534](https://github.com/spf13/pflag/pull/534)

**Full Changelog**: <https://github.com/spf13/pflag/compare/v1.0.10...v1.1.0>

</details>

<details>
<summary>podman-container-tools/podman (quay.io/containers/podman)</summary>

### [`v6.1.3`](https://github.com/podman-container-tools/podman/releases/tag/v6.1.3)

[Compare Source](https://github.com/podman-container-tools/podman/compare/v5.8.9...v6.1.3)

##### Security

- This release addresses [CVE-2026-94603](https://github.com/podman-container-tools/podman/security/advisories/GHSA-2cvf-wqm6-wr9g), where a `podman run` on a checkpoint image (any image with the `io.podman.annotations.checkpoint.runtime.name` annotation) could disable all sandboxing, including sandboxing specified by the user, when the container was created.

##### Breaking Changes

- Removed support for checkpoint images in `podman run` due to serious security concerns with the different security models of running images and running checkpoints. Checkpoints ignore user-specified security configuration and are very difficult to run safely.

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - Between 12:00 AM and 03:59 AM, only on Monday (`* 0-3 * * 1`)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yMjIuNSIsInVwZGF0ZWRJblZlciI6IjQ0LjIzOS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: https://gitea.com/gitea/runner/pulls/1414
Reviewed-by: silverwind <[email protected]>
Co-authored-by: Renovate Bot <[email protected]>
2026-11-16 15:15:09 +00:00
silverwind 4f59e3e418 fix: support cache-mode and make low-trust runs cache read-only (#1412)
Low-trust runs like `pull_request_target` on the default branch could poison caches that `push` runs restore. As on GitHub, they now only restore unless `cache-mode` allows saving.

This and the Gitea change can be deployed in any order.

Refs:
https://gitea.com/gitea/actionslib/pulls/33
https://github.com/go-gitea/gitea/pull/40343

_Written by Claude (Opus 5.5)._
Reviewed-on: https://gitea.com/gitea/runner/pulls/1412
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
2026-11-13 09:33:32 +00:00
clintlmartinandsilverwind c2046d597c fix: stop host teardown from deleting a workdir it never created (#1409)
Host jobs run in a per-job directory under `host.workdir_parent`, which teardown removes. Teardown also deleted `<container.workdir_parent>/<owner>/<repo>`, a path host jobs never create. With an empty parent and no repository that was the filesystem root, and any existing directory at that path was deleted although the job never used it.

This removes that delete instead of guarding it, so teardown only removes what the job created.

---------

Co-authored-by: silverwind <[email protected]>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1409
Reviewed-by: bircni <[email protected]>
Co-authored-by: clintlmartin <[email protected]>
2026-11-13 06:50:44 +00:00
silverwind 645b17de72 fix: align common behaviour with GitHub's runner (#1413)
Closes differences from GitHub's runner that common workflows hit:

- `ACTIONS_STEP_DEBUG` set as a repository variable enables debug output as on GitHub, where a secret of the same name still takes precedence. `runner.debug` and `RUNNER_DEBUG` are now also set inside composite actions, which lost the secret.
- `github.env` and `github.path` hold the file-command paths instead of being empty, so `echo "A=1" >> "${{ github.env }}"` works.
- Remote composite actions only get a pre stage when they nest actions. That stage evaluated `with:` before earlier steps ran, so an input like `${{ fromJSON(steps.meta.outputs.json).v }}` failed the job.
- `ports` on a job container are published, they were ignored while service ports worked.
- Dockerfile action build output reaches the job log. It was logged at debug and dropped, so a failing `RUN` showed only the final error.
- Local Docker actions honor their `.dockerignore`, as `docker build` does.
- Cancelling or timing out a host-mode step sends SIGINT, then SIGTERM after 7.5 seconds and SIGKILL after 2.5 more, as GitHub's runner does, so `trap` handlers and shutdown hooks run.
- `.sh` job hooks fall back to `sh` where bash is missing, and `.ps1` hooks to `powershell` where pwsh is missing, as on GitHub.

_Written by Claude (Opus 5.5)._

Reviewed-on: https://gitea.com/gitea/runner/pulls/1413
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
2026-11-12 15:28:47 +00:00
silverwind 0dfec377d2 fix: keep composite post steps in their own step scope (#1410)
Each composite step's post ran its earlier siblings' posts inside its own step-ID scope, so their log records listed siblings as ancestors, e.g. `outer.results.nodepost` instead of `outer.nodepost`. Every post now gets its own scope. Execution order and run-all-posts behavior are unchanged.

Prerequisite for https://gitea.com/gitea/runner/issues/809.

_Written by Claude (Opus 5.5)._

Reviewed-on: https://gitea.com/gitea/runner/pulls/1410
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
2026-11-11 19:31:21 +00:00
silverwind b5305c6785 docs: add a launchd example for macOS (#1408)
Adds `examples/launchd` with a plist and the steps to run the runner on macOS, next to the existing systemd example.

The runner runs in the login session of the user that jobs should run as, which gives jobs the login keychain and the GUI. The README also covers the two problems that setup runs into: macOS blocks the runner from hosts on the Mac's own subnet, and Git's keychain helper can stop a job at a dialog.

_Written by Claude (Fable 5.2)._

Reviewed-on: https://gitea.com/gitea/runner/pulls/1408
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
2026-11-10 17:17:35 +00:00
bircni a021d3139d enhance: make shared tool cache safe at any capacity (#1401)
Co-authored-by: bircni <[email protected]>
2026-11-10 14:25:50 +00:00
bircniandsilverwind 84c0fcd1fa fix!: remove the dbfs log workaround and require Gitea 1.26.2 (#1395)
Gitea 1.26.2 finalizes logs on an empty `UpdateLog` with `NoMore` (https://github.com/go-gitea/gitea/pull/37687), so the sentinel row is no longer needed. On older servers, the final log of most jobs would never be archived and stays in `dbfs_data`, so this raises the minimum Gitea version. It lives in `ver.MinGiteaVersion`, which the error for servers without `Declare` now names.

Fixes: https://gitea.com/gitea/runner/issues/953
Co-authored-by: silverwind <[email protected]>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1395
Reviewed-by: silverwind <[email protected]>
Co-authored-by: bircni <[email protected]>
2026-11-10 11:35:16 +00:00
bircniandsilverwind c59caa9689 refactor!: remove the builtin actions (#1407)
Removes `builtin:checkout`, `builtin:upload-artifact` and `builtin:download-artifact`, along with the container helpers only they used.

Builtin actions are tied to the runner version, so users cannot pin them, and they diverge from the shareable actions ecosystem that tools like zizmor build on. Workflows should use `actions/checkout`, `actions/upload-artifact` and `actions/download-artifact`, or lightweight third-party actions such as https://github.com/taiki-e/checkout-action.

**Breaking:** steps with `uses: builtin:checkout`, released in v4.0.0, now fail and need to switch to one of the actions above. The artifact actions were never released.

Docs: https://gitea.com/gitea/docs/pulls/643
Fixes: https://gitea.com/gitea/runner/issues/1405
Co-authored-by: silverwind <[email protected]>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1407
Reviewed-by: silverwind <[email protected]>
Co-authored-by: bircni <[email protected]>
2026-11-10 11:05:38 +00:00
Renovate Bot 85d007c47f chore(deps): update dependencies (#1406)
This PR contains the following updates:

| Package | Type | Update | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|---|---|
| docker.gitea.com/runner-images |  | digest | `657378e` → `b96ba46` |  |  |
| [github.com/docker/cli](https://github.com/docker/cli) | require | patch | `v29.9.2+incompatible` → `v29.9.3+incompatible` | ![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fdocker%2fcli/v29.9.3+incompatible?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fdocker%2fcli/v29.9.2+incompatible/v29.9.3+incompatible?slim=true) |
| [rancher/k3s](https://github.com/k3s-io/k3s) |  | patch | `v1.37.1-k3s1` → `v1.37.2-k3s1` | ![age](https://developer.mend.io/api/mc/badges/age/docker/rancher%2fk3s/v1.37.2?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/docker/rancher%2fk3s/v1.37.1/v1.37.2?slim=true) |

---

### Release Notes

<details>
<summary>docker/cli (github.com/docker/cli)</summary>

### [`v29.9.3+incompatible`](https://github.com/docker/cli/compare/v29.9.2...v29.9.3)

[Compare Source](https://github.com/docker/cli/compare/v29.9.2...v29.9.3)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - Between 12:00 AM and 03:59 AM, only on Monday (`* 0-3 * * 1`)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xOTkuMiIsInVwZGF0ZWRJblZlciI6IjQ0LjE5OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: https://gitea.com/gitea/runner/pulls/1406
Reviewed-by: Lunny Xiao <[email protected]>
Co-authored-by: Renovate Bot <[email protected]>
2026-11-09 04:31:50 +00:00
silverwindandbircni d34e4cf11a fix: stop a stalled docker daemon from hanging jobs and the e2e suite (#1404)
When the docker daemon stopped answering on https://gitea.com/gitea/runner/actions/runs/1204971, unbounded exec runs hung the e2e suite until the 20m `go test` panic, which skipped teardown. Exec runs and teardown are now bounded, and attached exec streams, including the runner's user ID probe, close with their context.

CLI daemons now stop with SIGTERM, so job volumes no longer leak.

_Written by Claude (Opus 5.5)._

---------

Co-authored-by: bircni <[email protected]>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1404
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
2026-11-07 08:07:41 +00:00
8e999cd039 fix: re-detect the cache address per job and prefer IPv4 (#1398)
The cache address was detected once at startup, and the interface fallback ranked ethernet names above IPv4. A runner that started before DHCPv4 finished could advertise a global IPv6 address to IPv4-only job networks until it restarted, failing every artifact and cache call.

IPv4 now ranks first, and the address is detected again for each job unless `cache.host` sets it. Detecting an IPv6 address logs a warning.

Fixes: https://gitea.com/gitea/runner/issues/1379
Co-authored-by: silverwind <[email protected]>
Co-authored-by: silverwind <[email protected]>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1398
Reviewed-by: silverwind <[email protected]>
Co-authored-by: bircni <[email protected]>
2026-11-07 06:41:25 +00:00
silverwind cd748053b0 docs: trim comments and docs from workspace emptying change (#1403)
Follow-up to https://gitea.com/gitea/runner/commit/79faf5e55df7a3b312fb4888b7405a58e01f567c. Reverts the post-task-script doc change, which is too much detail for that page. Also shortens the `DrainGracePeriod` comment and the other comments that commit added, since the code and log messages already say most of it.

Reviewed-on: https://gitea.com/gitea/runner/pulls/1403
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
2026-11-07 06:14:41 +00:00
bircni 9bb72bbe5c enhance: add ubuntu-26.04 to the default labels (#1396)
Newly registered runners get an `ubuntu-26.04` label alongside the existing defaults.

Ref: https://gitea.com/gitea/runner/issues/1334
Reviewed-on: https://gitea.com/gitea/runner/pulls/1396
Reviewed-by: Lunny Xiao <[email protected]>
2026-11-07 05:12:04 +00:00
79faf5e55d fix: empty root-owned bind workspaces for non-root runners (#1399)
A job running as root leaves root-owned files in the bind-mounted workspace. A non-root runner on Linux cannot remove them, so workspaces pile up with only a warning. Such a runner now empties the workspace as root from inside the job container, right before removing the container. Root runners and Docker Desktop already remove these files themselves and skip this.

The workspace is only emptied when it is exactly the runner's own mountpoint with no mount below it. Otherwise, or when the command fails, the existing removal and warning apply. Jobs of a reusable workflow share the workspace, so they are not covered and still end in the existing warning.

Fixes: https://gitea.com/gitea/runner/issues/879
Co-authored-by: silverwind <[email protected]>
Co-authored-by: silverwind <[email protected]>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1399
Reviewed-by: silverwind <[email protected]>
Co-authored-by: bircni <[email protected]>
2026-11-07 04:33:19 +00:00
bircni 993389d428 docs: trust a private registry CA in the dind images (#1397)
The bundled Docker daemon pulls job images, so it needs to trust a private registry's CA itself, which `runner.ca_file` doesn't cover. Documents the `certs.d` mount for both dind images.

Ref: https://gitea.com/gitea/runner/issues/1390
Reviewed-on: https://gitea.com/gitea/runner/pulls/1397
Reviewed-by: Lunny Xiao <[email protected]>
2026-11-06 21:36:06 +00:00
silverwind db76fd5159 enhance: improve hashFiles coercion and log grouping (#1394)
- Fix `hashFiles()` argument conversion for numbers, booleans, and null to match GitHub expression semantics.
- Fix rendering of mixed-case, indented, and prefixed legacy group commands while preserving recognized prefixes and escaping.

Reviewed-on: https://gitea.com/gitea/runner/pulls/1394
Reviewed-by: bircni <[email protected]>
Co-authored-by: silverwind <[email protected]>
2026-11-06 20:03:39 +00:00
135 changed files with 1579 additions and 6228 deletions

No files matched your search

+1 -1
View File
@@ -87,7 +87,7 @@ jobs:
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4 uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
+1 -1
View File
@@ -82,7 +82,7 @@ jobs:
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4 uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
+9
View File
@@ -57,6 +57,15 @@ jobs:
make coverage-report make coverage-report
cat .tmp/coverage.md >> "$GITHUB_STEP_SUMMARY" cat .tmp/coverage.md >> "$GITHUB_STEP_SUMMARY"
cross:
name: cross-compile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: ./.gitea/actions/go-setup
- name: cross-compile
run: make cross-check
windows: windows:
name: test on windows name: test on windows
runs-on: ubuntu-latest-kvm runs-on: ubuntu-latest-kvm
+1 -1
View File
@@ -11,7 +11,7 @@
- Read `DEVELOPMENT.md` for internals and conventions - Read `DEVELOPMENT.md` for internals and conventions
- Ensure no trailing whitespace in edited files - Ensure no trailing whitespace in edited files
- Run `make fmt` after `.go` edits, `make tidy` after `go.mod` edits, and `make checks` for the non-lint source checks - Run `make fmt` after `.go` edits, `make tidy` after `go.mod` edits, and `make checks` for the non-lint source checks
- Lint what changed with `make lint-go`, and `make lint-go-windows` for Windows and platform-split files - Lint what changed with `make lint-go`, and `make lint-go-windows` for Windows and platform-split files. Run `make cross-check` after platform-split edits
- Fix the cause rather than disabling a linter or weakening a test. Where unavoidable, use the narrowest scope with a trailing comment giving the reason - Fix the cause rather than disabling a linter or weakening a test. Where unavoidable, use the narrowest scope with a trailing comment giving the reason
- Run single go tests with `go test -run '^TestName$' ./modulepath/`. `make test` self-skips the integration tests without docker or network, `make test-dind` runs the daemon-facing tests against the built dind image - Run single go tests with `go test -run '^TestName$' ./modulepath/`. `make test` self-skips the integration tests without docker or network, `make test-dind` runs the daemon-facing tests against the built dind image
- Write the fewest, fastest tests covering the behavior, extending an existing one where possible. Prefer unit tests where logic is testable in isolation - Write the fewest, fastest tests covering the behavior, extending an existing one where possible. Prefer unit tests where logic is testable in isolation
-5
View File
@@ -51,11 +51,6 @@ fields.
- Tests read what was logged with `logtest.NewLogger()`, or `logtest.SetDefault(t)` for the - Tests read what was logged with `logtest.NewLogger()`, or `logtest.SetDefault(t)` for the
package functions. package functions.
## Built-in actions
Each lives in `internal/pkg/action/<name>` and is registered in `builtinActions` in
`act/runner/step_action_builtin.go`.
## End-to-end compatibility tests ## End-to-end compatibility tests
`make test-e2e` runs the runner against `E2E_GITEA_IMAGE`. It defaults to the nightly image. `make test-e2e` runs the runner against `E2E_GITEA_IMAGE`. It defaults to the nightly image.
+11 -3
View File
@@ -3,11 +3,11 @@ GO ?= go
EXECUTABLE := gitea-runner$(shell $(GO) env GOEXE) EXECUTABLE := gitea-runner$(shell $(GO) env GOEXE)
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" ) HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
PODMAN_TEST_IMAGE ?= quay.io/containers/podman:v5.8.9-immutable@sha256:87f42f37fa85b421664c30b8f5f9cfc23920057f5e5fcadf0b6f68d9edc6d415 # renovate: datasource=docker PODMAN_TEST_IMAGE ?= quay.io/containers/podman:v6.1.3-immutable@sha256:1d844fd1fc6ce68c1e72ae19550cc3caef039306219ee007d88f7e67c5df4dd1 # renovate: datasource=docker
E2E_JOB_IMAGE ?= docker.gitea.com/runner-images:ubuntu-latest@sha256:657378e5cfd898e36f820459c60ef8e69be8fcda9fd354e4381a8b654d091bbc # renovate: datasource=docker E2E_JOB_IMAGE ?= docker.gitea.com/runner-images:ubuntu-latest@sha256:139605d4a6ab61e48dfd7687b11184881c2d7fcf06bf739e9cadb34f73deb51d # renovate: datasource=docker
SERVICE_IMAGE ?= nginx:1.31.7-alpine@sha256:892bb2152464f0c5d8972593a5f5afaf8054552580b699d95f8ff4af08c2d33d # renovate: datasource=docker SERVICE_IMAGE ?= nginx:1.31.7-alpine@sha256:892bb2152464f0c5d8972593a5f5afaf8054552580b699d95f8ff4af08c2d33d # renovate: datasource=docker
E2E_GITEA_IMAGE ?= gitea/gitea:main-nightly E2E_GITEA_IMAGE ?= gitea/gitea:main-nightly
E2E_K3S_IMAGE ?= rancher/k3s:v1.37.1-k3s1@sha256:ca7f37d993d82ef0dcdcfecb2e0e2618ea541dbaffc620c8cedebe01a82acd0d # renovate: datasource=docker E2E_K3S_IMAGE ?= rancher/k3s:v1.37.2-k3s1@sha256:21ea6e0fac4e3930c2ce8aa40ddd41a8b18cb3e9a0222c030dc005e7e88c4332 # renovate: datasource=docker
WINDOWS_TEST_IMAGE ?= dockurr/windows:6.06@sha256:16fd7c39a3e48bb946d29c59dc6015942e5b900a1fa5d7e5552053bfc48ee2ea # renovate: datasource=docker WINDOWS_TEST_IMAGE ?= dockurr/windows:6.06@sha256:16fd7c39a3e48bb946d29c59dc6015942e5b900a1fa5d7e5552053bfc48ee2ea # renovate: datasource=docker
GOFILES := $(shell find . -type f -name "*.go" -o -name "go.mod" ! -name "generated.*") GOFILES := $(shell find . -type f -name "*.go" -o -name "go.mod" ! -name "generated.*")
@@ -21,6 +21,8 @@ GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/[email protected] # renovate: data
GOTEST_FLAGS ?= -race -timeout 20m -parallel 8 GOTEST_FLAGS ?= -race -timeout 20m -parallel 8
CROSS_TARGETS ?= darwin/arm64 freebsd/amd64 linux/arm netbsd/amd64 openbsd/amd64 solaris/amd64 # one per platform file set, linux/arm for 32-bit syscall fields
STATIC ?= STATIC ?=
EXTLDFLAGS ?= EXTLDFLAGS ?=
ifneq ($(STATIC),) ifneq ($(STATIC),)
@@ -100,6 +102,12 @@ deps-tools: ## install tool dependencies
.PHONY: checks .PHONY: checks
checks: tidy-check fmt-check security-check ## run the non-lint source checks checks: tidy-check fmt-check security-check ## run the non-lint source checks
.PHONY: cross-check
cross-check: $(addprefix cross-check/,$(CROSS_TARGETS)) ## check that code and tests compile on every supported platform
cross-check/%:
GOOS=$(word 1,$(subst /, ,$*)) GOARCH=$(word 2,$(subst /, ,$*)) CGO_ENABLED=0 $(GO) vet -gcflags='all=-N -l' ./...
.PHONY: lint .PHONY: lint
lint: lint-go lint-go-windows ## lint everything lint: lint-go lint-go-windows ## lint everything
+3 -9
View File
@@ -7,6 +7,7 @@ Gitea Runner runs the jobs of Gitea Actions workflows. Register it with a Gitea
### Prerequisites ### Prerequisites
- Linux, macOS or Windows, or FreeBSD. - Linux, macOS or Windows, or FreeBSD.
- Gitea 1.26.2 or newer.
- `git` 2.34.1 or newer. - `git` 2.34.1 or newer.
- `docker`, or `podman` with `podman.socket` enabled, for `docker` labels and Docker actions. See Docker's [install instructions](https://docs.docker.com/engine/install/). - `docker`, or `podman` with `podman.socket` enabled, for `docker` labels and Docker actions. See Docker's [install instructions](https://docs.docker.com/engine/install/).
@@ -14,9 +15,6 @@ In the job image, or on the host for host jobs:
- `bash` or `sh`, or `pwsh` or `powershell` on Windows. - `bash` or `sh`, or `pwsh` or `powershell` on Windows.
- `node` for JavaScript actions and `hashFiles()`. - `node` for JavaScript actions and `hashFiles()`.
- `git` 2.34.1 or newer for [`builtin:checkout`](docs/builtin-actions.md).
- `git-lfs` for `builtin:checkout` with `lfs: true`.
- `ssh` for `builtin:checkout` with `ssh-key`.
Kubernetes mode needs [a few more tools](docs/kubernetes.md) in job images. Kubernetes mode needs [a few more tools](docs/kubernetes.md) in job images.
@@ -112,7 +110,7 @@ Versioned and `nightly` tags take the same suffixes, like `nightly-dind`. The im
### Example deployments ### Example deployments
See the [examples](examples) directory for more deployments, among them systemd, Kubernetes and VMs. See the [examples](examples) directory for more deployments, among them systemd, launchd on macOS, Kubernetes and VMs.
## Configuration ## Configuration
@@ -183,7 +181,7 @@ Setup actions like `setup-go` install tools into `RUNNER_TOOL_CACHE`. `runner.to
| Mode | Tool cache | | Mode | Tool cache |
| --- | --- | | --- | --- |
| `none` (default) | Provided by the job image. Versions it lacks are downloaded in every job. | | `none` (default) | Provided by the job image. Versions it lacks are downloaded in every job. |
| `shared` | One volume for all jobs. Only safe with `runner.capacity: 1`. | | `shared` | One volume per `runner.capacity` slot, reused by later jobs. It hides the tools later job images ship, so use images without them. |
To ship tools in a job image, install them to `/opt/hostedtoolcache/<tool>/<version>/<arch>` with an empty `<arch>.complete` file next to it, as the `-full` [runner images](https://gitea.com/gitea/runner-images) do: To ship tools in a job image, install them to `/opt/hostedtoolcache/<tool>/<version>/<arch>` with an empty `<arch>.complete` file next to it, as the `-full` [runner images](https://gitea.com/gitea/runner-images) do:
@@ -245,10 +243,6 @@ volumes:
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. 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>`)
`uses: builtin:checkout`, `builtin:upload-artifact` and `builtin:download-artifact` replace their `actions/` counterparts without an action download or Node in the job image, see [docs/builtin-actions.md](docs/builtin-actions.md).
### Caching (`actions/cache`) ### Caching (`actions/cache`)
Each runner runs its own cache server. As on GitHub, a job restores caches of its own ref, its pull request's base branch and the default branch. Each runner runs its own cache server. As on GitHub, a job restores caches of its own ref, its pull request's base branch and the default branch.
+63 -11
View File
@@ -62,6 +62,7 @@ type JobCredential struct {
Ref string `json:"ref"` Ref string `json:"ref"`
BaseRef string `json:"base_ref"` BaseRef string `json:"base_ref"`
DefaultRef string `json:"default_ref"` DefaultRef string `json:"default_ref"`
CacheMode string `json:"cache_mode"` // empty allows everything
// Results is the instance whose artifact service this server forwards for the job, and // Results is the instance whose artifact service this server forwards for the job, and
// InsecureTLS how the runner reaches it; see results.go. // InsecureTLS how the runner reaches it; see results.go.
@@ -104,7 +105,9 @@ type Handler struct {
stopSync context.CancelFunc stopSync context.CancelFunc
syncing sync.WaitGroup syncing sync.WaitGroup
outboundIPMu sync.RWMutex
outboundIP string outboundIP string
detectOutboundIP func() net.IP // nil when the address is configured
instanceTransport http.RoundTripper instanceTransport http.RoundTripper
// internalSecret guards /_internal/{register,revoke}. When set, a remote // internalSecret guards /_internal/{register,revoke}. When set, a remote
@@ -158,6 +161,7 @@ func StartHandler(opts Options) (*Handler, error) {
policy: opts.Policy.withDefaults(), policy: opts.Policy.withDefaults(),
freeDisk: disk.FreeBytes, freeDisk: disk.FreeBytes,
dbLock: make(chan struct{}, 1), dbLock: make(chan struct{}, 1),
outboundIP: opts.OutboundIP,
instanceTransport: opts.InstanceTransport, instanceTransport: opts.InstanceTransport,
} }
@@ -167,12 +171,11 @@ func StartHandler(opts Options) (*Handler, error) {
logger = logger.With("module", "artifactcache") logger = logger.With("module", "artifactcache")
h.logger = logger h.logger = logger
if opts.OutboundIP != "" { if opts.OutboundIP == "" {
h.outboundIP = opts.OutboundIP h.detectOutboundIP = common.GetOutboundIP
} else if ip := common.GetOutboundIP(); ip == nil { if h.RefreshExternalURL() == "" {
return nil, errors.New("unable to determine outbound IP address") logger.Warn("unable to determine an outbound IP address for the cache server yet, set cache.host to configure one")
} else { }
h.outboundIP = ip.String()
} }
if opts.Upstream != "" { if opts.Upstream != "" {
@@ -216,10 +219,10 @@ func StartHandler(opts Options) (*Handler, error) {
} }
router := http.NewServeMux() router := http.NewServeMux()
router.HandleFunc("GET "+apiPath+"/cache", h.bearerAuth(h.find)) router.HandleFunc("GET "+apiPath+"/cache", h.cacheModeAuth(false, h.find))
router.HandleFunc("POST "+apiPath+"/caches", h.bearerAuth(h.reserve)) router.HandleFunc("POST "+apiPath+"/caches", h.cacheModeAuth(true, h.reserve))
router.HandleFunc("PATCH "+apiPath+"/caches/{id}", h.bearerAuth(h.upload)) router.HandleFunc("PATCH "+apiPath+"/caches/{id}", h.cacheModeAuth(true, h.upload))
router.HandleFunc("POST "+apiPath+"/caches/{id}", h.bearerAuth(h.commit)) router.HandleFunc("POST "+apiPath+"/caches/{id}", h.cacheModeAuth(true, h.commit))
router.HandleFunc("POST "+apiPath+"/clean", h.bearerAuth(h.clean)) router.HandleFunc("POST "+apiPath+"/clean", h.bearerAuth(h.clean))
// Artifact GET is signed via query-string HMAC because @actions/cache // Artifact GET is signed via query-string HMAC because @actions/cache
// does not attach Authorization when downloading archiveLocation. // does not attach Authorization when downloading archiveLocation.
@@ -304,11 +307,36 @@ func (h *Handler) cacheForwarder(upstream string) (http.Handler, error) {
}), nil }), nil
} }
// ExternalURL is "" while no address is known.
func (h *Handler) ExternalURL() string { func (h *Handler) ExternalURL() string {
// TODO: make the external url configurable if necessary if h == nil {
return ""
}
h.outboundIPMu.RLock()
defer h.outboundIPMu.RUnlock()
if h.outboundIP == "" {
return ""
}
return "http://" + net.JoinHostPort(h.outboundIP, strconv.Itoa(h.port)) return "http://" + net.JoinHostPort(h.outboundIP, strconv.Itoa(h.port))
} }
// RefreshExternalURL re-detects an unconfigured address, which can change after startup.
func (h *Handler) RefreshExternalURL() string {
if h != nil && h.detectOutboundIP != nil {
if ip := h.detectOutboundIP(); ip != nil {
h.outboundIPMu.Lock()
if address := ip.String(); address != h.outboundIP {
h.outboundIP = address
if ip.To4() == nil {
h.logger.Warnf("detected IPv6 address %s for the cache server, jobs on IPv4-only networks cannot reach it, set cache.host if they fail to", address)
}
}
h.outboundIPMu.Unlock()
}
}
return h.ExternalURL()
}
func (h *Handler) baseURL(cred JobCredential) string { func (h *Handler) baseURL(cred JobCredential) string {
if base := strings.TrimRight(cred.PublicURL, "/"); base != "" { if base := strings.TrimRight(cred.PublicURL, "/"); base != "" {
return base return base
@@ -929,6 +957,30 @@ func (h *Handler) bearerAuth(handler http.HandlerFunc) http.HandlerFunc {
} }
} }
// cacheModeAuth is bearerAuth refusing what the job's cache-mode forbids, in the shapes the toolkit reports as a warning.
func (h *Handler) cacheModeAuth(write bool, handler http.HandlerFunc) http.HandlerFunc {
return h.bearerAuth(func(w http.ResponseWriter, r *http.Request) {
mode := credFromContext(r.Context()).CacheMode
access, forbidden := "read", "write-only"
if write {
access, forbidden = "write", "read"
}
if mode != "none" && mode != forbidden {
handler(w, r)
return
}
message := fmt.Sprintf("cache %s denied: the job's cache-mode is %s", access, mode)
switch {
case !strings.HasPrefix(r.URL.Path, cacheServiceV2Path):
h.responseJSON(w, r, http.StatusForbidden, map[string]any{"message": message})
case write:
h.responseJSON(w, r, http.StatusOK, map[string]any{"ok": false, "message": message})
default:
h.twirpError(w, r, twirpDenied, errors.New(message))
}
})
}
func (h *Handler) unauthorized(w http.ResponseWriter, r *http.Request, err error) { func (h *Handler) unauthorized(w http.ResponseWriter, r *http.Request, err error) {
if strings.HasPrefix(r.URL.Path, cacheServiceV2Path) { if strings.HasPrefix(r.URL.Path, cacheServiceV2Path) {
h.twirpError(w, r, twirpUnauthenticated, err) h.twirpError(w, r, twirpUnauthenticated, err)
+44 -4
View File
@@ -11,6 +11,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
@@ -22,6 +23,8 @@ import (
"testing/synctest" "testing/synctest"
"time" "time"
"gitea.com/gitea/runner/act/common/logging/logtest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
@@ -50,7 +53,23 @@ func signArtifactURL(h *Handler, id int64) string {
func TestHandler_ExternalURL(t *testing.T) { func TestHandler_ExternalURL(t *testing.T) {
t.Parallel() t.Parallel()
assert.Equal(t, "http://[2001:db8::1]:8080", (&Handler{outboundIP: "2001:db8::1", port: 8080}).ExternalURL()) assert.Empty(t, (*Handler)(nil).RefreshExternalURL())
assert.Equal(t, "http://cache.example:8080", (&Handler{outboundIP: "cache.example", port: 8080}).RefreshExternalURL())
logger, logs := logtest.NewLogger()
var ip net.IP
handler := &Handler{port: 8080, logger: logger, detectOutboundIP: func() net.IP { return ip }}
assert.Empty(t, handler.RefreshExternalURL())
ip = net.ParseIP("2001:db8::1")
assert.Equal(t, "http://[2001:db8::1]:8080", handler.RefreshExternalURL())
assert.Equal(t, "http://[2001:db8::1]:8080", handler.RefreshExternalURL())
ip = net.ParseIP("192.0.2.1")
assert.Equal(t, "http://[2001:db8::1]:8080", handler.ExternalURL())
assert.Equal(t, "http://192.0.2.1:8080", handler.RefreshExternalURL())
ip = nil
assert.Equal(t, "http://192.0.2.1:8080", handler.RefreshExternalURL())
require.Len(t, logs.AllRecords(), 1)
assert.Contains(t, logs.LastRecord().Message, "IPv6")
} }
func TestHandler_Upstream(t *testing.T) { func TestHandler_Upstream(t *testing.T) {
@@ -984,7 +1003,7 @@ func TestHandler_UnregisterRevokes(t *testing.T) {
} }
} }
func TestHandler_CrossRepoIsolation(t *testing.T) { func TestHandler_CrossRepoAndCacheModeIsolation(t *testing.T) {
t.Parallel() t.Parallel()
dir := filepath.Join(t.TempDir(), "artifactcache") dir := filepath.Join(t.TempDir(), "artifactcache")
handler, err := StartHandler(Options{Dir: dir}) handler, err := StartHandler(Options{Dir: dir})
@@ -993,6 +1012,8 @@ func TestHandler_CrossRepoIsolation(t *testing.T) {
handler.RegisterJob("token-a", JobCredential{Repo: "owner/repoA"}) handler.RegisterJob("token-a", JobCredential{Repo: "owner/repoA"})
handler.RegisterJob("token-b", JobCredential{Repo: "owner/repoB"}) handler.RegisterJob("token-b", JobCredential{Repo: "owner/repoB"})
handler.RegisterJob("token-a-pull", JobCredential{Repo: "owner/repoA", Ref: "refs/pull/1/head"}) handler.RegisterJob("token-a-pull", JobCredential{Repo: "owner/repoA", Ref: "refs/pull/1/head"})
handler.RegisterJob("token-a-read", JobCredential{Repo: "owner/repoA", CacheMode: "read"})
handler.RegisterJob("token-a-write-only", JobCredential{Repo: "owner/repoA", CacheMode: "write-only"})
base := handler.ExternalURL() + apiPath base := handler.ExternalURL() + apiPath
key := "shared-key" key := "shared-key"
@@ -1022,12 +1043,31 @@ func TestHandler_CrossRepoIsolation(t *testing.T) {
resp.Body.Close() resp.Body.Close()
assert.Equal(t, http.StatusNoContent, resp.StatusCode) assert.Equal(t, http.StatusNoContent, resp.StatusCode)
resp, err = clientA.Get(fmt.Sprintf("%s/cache?keys=%s&version=%s", base, key, version)) clientRead := &http.Client{Transport: &bearerTransport{token: "token-a-read"}}
for _, client := range []*http.Client{clientA, clientRead} {
resp, err = client.Get(fmt.Sprintf("%s/cache?keys=%s&version=%s", base, key, version))
require.NoError(t, err) require.NoError(t, err)
resp.Body.Close() resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode) assert.Equal(t, http.StatusOK, resp.StatusCode)
}
for _, client := range []*http.Client{clientB, {Transport: &bearerTransport{token: "token-a-pull"}}} { requireDenied := func(prefix string, do func() (*http.Response, error)) {
resp, err := do()
require.NoError(t, err)
defer resp.Body.Close()
denied := map[string]string{}
require.NoError(t, json.UnmarshalRead(resp.Body, &denied))
assert.Equal(t, http.StatusForbidden, resp.StatusCode)
assert.True(t, strings.HasPrefix(denied["message"], prefix), denied["message"])
}
requireDenied("cache write denied:", func() (*http.Response, error) {
return clientRead.Post(base+"/caches", "application/json", strings.NewReader(`{"key":"new-key","version":"`+version+`"}`))
})
requireDenied("cache read denied:", func() (*http.Response, error) {
return (&http.Client{Transport: &bearerTransport{token: "token-a-write-only"}}).Get(fmt.Sprintf("%s/cache?keys=%s&version=%s", base, key, version))
})
for _, client := range []*http.Client{clientB, {Transport: &bearerTransport{token: "token-a-pull"}}, clientRead} {
req, err = http.NewRequest(http.MethodPatch, fmt.Sprintf("%s/caches/%d", base, id), bytes.NewReader([]byte("poison"))) req, err = http.NewRequest(http.MethodPatch, fmt.Sprintf("%s/caches/%d", base, id), bytes.NewReader([]byte("poison")))
require.NoError(t, err) require.NoError(t, err)
req.Header.Set("Content-Range", "bytes 0-5/*") req.Header.Set("Content-Range", "bytes 0-5/*")
+6 -3
View File
@@ -40,12 +40,13 @@ const (
twirpInternal = "internal" twirpInternal = "internal"
twirpUnavailable = "unavailable" twirpUnavailable = "unavailable"
twirpUnauthenticated = "unauthenticated" twirpUnauthenticated = "unauthenticated"
twirpDenied = "permission_denied"
) )
func (h *Handler) registerV2Routes(router *http.ServeMux) { func (h *Handler) registerV2Routes(router *http.ServeMux) {
router.HandleFunc("POST "+cacheServiceV2Path+"/CreateCacheEntry", h.bearerAuth(h.v2CreateCacheEntry)) router.HandleFunc("POST "+cacheServiceV2Path+"/CreateCacheEntry", h.cacheModeAuth(true, h.v2CreateCacheEntry))
router.HandleFunc("POST "+cacheServiceV2Path+"/FinalizeCacheEntryUpload", h.bearerAuth(h.v2FinalizeCacheEntryUpload)) router.HandleFunc("POST "+cacheServiceV2Path+"/FinalizeCacheEntryUpload", h.cacheModeAuth(true, h.v2FinalizeCacheEntryUpload))
router.HandleFunc("POST "+cacheServiceV2Path+"/GetCacheEntryDownloadURL", h.bearerAuth(h.v2GetCacheEntryDownloadURL)) router.HandleFunc("POST "+cacheServiceV2Path+"/GetCacheEntryDownloadURL", h.cacheModeAuth(false, h.v2GetCacheEntryDownloadURL))
router.HandleFunc("PUT "+blobPath+"/{id}", h.signedAuth(blobUploadPurpose, h.v2UploadBlob)) router.HandleFunc("PUT "+blobPath+"/{id}", h.signedAuth(blobUploadPurpose, h.v2UploadBlob))
} }
@@ -267,6 +268,8 @@ func (h *Handler) twirpError(w http.ResponseWriter, r *http.Request, code string
status = http.StatusServiceUnavailable status = http.StatusServiceUnavailable
case twirpUnauthenticated: case twirpUnauthenticated:
status = http.StatusUnauthorized status = http.StatusUnauthorized
case twirpDenied:
status = http.StatusForbidden
} }
h.responseJSON(w, r, status, map[string]any{"code": code, "msg": err.Error()}) h.responseJSON(w, r, status, map[string]any{"code": code, "msg": err.Error()})
} }
+24
View File
@@ -227,6 +227,30 @@ func TestCacheServiceV2Lookups(t *testing.T) {
assert.NotEmpty(t, got["archiveLocation"]) assert.NotEmpty(t, got["archiveLocation"])
}) })
t.Run("a read-only job only restores and a write-only one only saves", func(t *testing.T) {
handler.RegisterJob("read-only", JobCredential{Repo: testRepo, CacheMode: "read"})
readOnlyClient := &http.Client{Transport: &bearerTransport{token: "read-only"}}
assert.Equal(t, true, v2Call(t, handler, readOnlyClient, "GetCacheEntryDownloadURL", map[string]any{"key": "deps-abc", "version": "v1"})["ok"])
for _, method := range []string{"CreateCacheEntry", "FinalizeCacheEntryUpload"} {
got := v2Call(t, handler, readOnlyClient, method, map[string]any{"key": "deps-new", "version": "v1", "size_bytes": 1})
assert.Equal(t, false, got["ok"], method)
assert.True(t, strings.HasPrefix(got["message"].(string), "cache write denied:"), method)
}
handler.RegisterJob("write-only", JobCredential{Repo: testRepo, CacheMode: "write-only"})
writeOnlyClient := &http.Client{Transport: &bearerTransport{token: "write-only"}}
assert.Equal(t, true, v2Call(t, handler, writeOnlyClient, "CreateCacheEntry", map[string]any{"key": "deps-write-only", "version": "v1"})["ok"])
resp, err := writeOnlyClient.Post(handler.ExternalURL()+cacheServiceV2Path+"/GetCacheEntryDownloadURL", "application/json", strings.NewReader(`{"key":"deps-abc","version":"v1"}`))
require.NoError(t, err)
defer resp.Body.Close()
got := map[string]string{}
require.NoError(t, json.UnmarshalRead(resp.Body, &got))
assert.Equal(t, http.StatusForbidden, resp.StatusCode)
assert.Equal(t, twirpDenied, got["code"])
assert.True(t, strings.HasPrefix(got["msg"], "cache read denied:"), got["msg"])
})
t.Run("another repository sees nothing", func(t *testing.T) { t.Run("another repository sees nothing", func(t *testing.T) {
handler.RegisterJob("other-runtime-token", JobCredential{Repo: "other/repo"}) handler.RegisterJob("other-runtime-token", JobCredential{Repo: "other/repo"})
otherClient := &http.Client{Transport: &bearerTransport{token: "other-runtime-token"}} otherClient := &http.Client{Transport: &bearerTransport{token: "other-runtime-token"}}
+1 -1
View File
@@ -218,7 +218,7 @@ func Serve(ctx context.Context, artifactPath, addr, port string) context.CancelF
logger.Debugf("Artifacts base path '%s'", artifactPath) logger.Debugf("Artifacts base path '%s'", artifactPath)
uploads(router, artifactPath) uploads(router, artifactPath)
downloads(router, artifactPath) downloads(router, artifactPath)
RegisterV4(router, artifactPath) registerV4(router, artifactPath)
server := &http.Server{ server := &http.Server{
Addr: net.JoinHostPort(addr, port), Addr: net.JoinHostPort(addr, port),
+2 -2
View File
@@ -28,7 +28,7 @@ func TestArtifactFlow(t *testing.T) {
router := http.NewServeMux() router := http.NewServeMux()
uploads(router, artifactPath) uploads(router, artifactPath)
downloads(router, artifactPath) downloads(router, artifactPath)
RegisterV4(router, artifactPath) registerV4(router, artifactPath)
server := httptest.NewServer(router) server := httptest.NewServer(router)
defer server.Close() defer server.Close()
@@ -256,7 +256,7 @@ func TestArtifactFlow(t *testing.T) {
require.Equal(t, "attachment; filename*=UTF-8''50%25%20art%40v1", header.Get("Content-Disposition")) require.Equal(t, "attachment; filename*=UTF-8''50%25%20art%40v1", header.Get("Content-Disposition"))
rerun := http.NewServeMux() rerun := http.NewServeMux()
RegisterV4(rerun, artifactPath) registerV4(rerun, artifactPath)
recorder := httptest.NewRecorder() recorder := httptest.NewRecorder()
rerun.ServeHTTP(recorder, httptest.NewRequest(http.MethodPost, artifactServicePath+"/CreateArtifact", strings.NewReader("{"+artifactRef+"}"))) rerun.ServeHTTP(recorder, httptest.NewRequest(http.MethodPost, artifactServicePath+"/CreateArtifact", strings.NewReader("{"+artifactRef+"}")))
require.Equal(t, http.StatusOK, recorder.Code, recorder.Body.String()) require.Equal(t, http.StatusOK, recorder.Code, recorder.Body.String())
+1 -1
View File
@@ -35,7 +35,7 @@ const (
maxTwirpBytes = 1 << 20 maxTwirpBytes = 1 << 20
) )
func RegisterV4(router *http.ServeMux, baseDir string) { func registerV4(router *http.ServeMux, baseDir string) {
server := &serverV4{dir: filepath.Join(baseDir, "v4"), lastID: time.Now().UnixMilli(), created: map[string]bool{}} // IDs stay unique across invocations sharing baseDir server := &serverV4{dir: filepath.Join(baseDir, "v4"), lastID: time.Now().UnixMilli(), created: map[string]bool{}} // IDs stay unique across invocations sharing baseDir
router.HandleFunc("POST "+artifactServicePath+"/CreateArtifact", twirp(server.createArtifact)) router.HandleFunc("POST "+artifactServicePath+"/CreateArtifact", twirp(server.createArtifact))
router.HandleFunc("POST "+artifactServicePath+"/FinalizeArtifact", twirp(server.finalizeArtifact)) router.HandleFunc("POST "+artifactServicePath+"/FinalizeArtifact", twirp(server.finalizeArtifact))
+8 -4
View File
@@ -6,6 +6,7 @@ package common
import ( import (
"net" "net"
"slices"
"sort" "sort"
"strings" "strings"
) )
@@ -55,19 +56,22 @@ func GetOutboundIP() net.IP {
} }
func preferredIP(ips []interfaceIP) net.IP { func preferredIP(ips []interfaceIP) net.IP {
ips = slices.DeleteFunc(ips, func(ip interfaceIP) bool {
return len(ip.Name) == 15 && strings.HasPrefix(ip.Name, "br-") && strings.Trim(ip.Name[3:], "0123456789abcdef") == "" // a Docker network's bridge, removed with the network
})
if len(ips) == 0 { if len(ips) == 0 {
return nil return nil
} }
sort.Slice(ips, func(i, j int) bool { sort.Slice(ips, func(i, j int) bool {
first, second := ips[i], ips[j] first, second := ips[i], ips[j]
// ethernet is preferred // IPv4 is preferred, as job networks are IPv4-only by default
if vi, vj := strings.HasPrefix(first.Name, "e"), strings.HasPrefix(second.Name, "e"); vi != vj { if vi, vj := first.To4() != nil, second.To4() != nil; vi != vj {
return vi return vi
} }
// IPv4 is preferred // ethernet is preferred
if vi, vj := first.To4() != nil, second.To4() != nil; vi != vj { if vi, vj := strings.HasPrefix(first.Name, "e"), strings.HasPrefix(second.Name, "e"); vi != vj {
return vi return vi
} }
+2 -1
View File
@@ -13,8 +13,9 @@ import (
func TestPreferredIP(t *testing.T) { func TestPreferredIP(t *testing.T) {
assert.Nil(t, preferredIP(nil)) assert.Nil(t, preferredIP(nil))
assert.Equal(t, net.ParseIP("2001:db8::1"), preferredIP([]interfaceIP{{IP: net.ParseIP("2001:db8::1")}})) assert.Equal(t, net.ParseIP("2001:db8::1"), preferredIP([]interfaceIP{{IP: net.ParseIP("2001:db8::1")}}))
assert.Equal(t, net.ParseIP("2001:db8::1"), preferredIP([]interfaceIP{ assert.Equal(t, net.ParseIP("192.0.2.1"), preferredIP([]interfaceIP{
{IP: net.ParseIP("192.0.2.1"), Name: "wlan0"}, {IP: net.ParseIP("192.0.2.1"), Name: "wlan0"},
{IP: net.ParseIP("2001:db8::1"), Name: "eth0"}, {IP: net.ParseIP("2001:db8::1"), Name: "eth0"},
{IP: net.ParseIP("172.18.0.1"), Name: "br-0123456789ab"},
})) }))
} }
+6 -35
View File
@@ -5,7 +5,6 @@
package container package container
import ( import (
"bytes"
"context" "context"
"errors" "errors"
"fmt" "fmt"
@@ -15,6 +14,7 @@ import (
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time"
"gitea.com/gitea/runner/act/common" "gitea.com/gitea/runner/act/common"
@@ -24,6 +24,9 @@ import (
var hostOS = runtime.GOOS // replaced in tests var hostOS = runtime.GOOS // replaced in tests
// DrainGracePeriod caps the wait for container output to drain so the log tail is not truncated
const DrainGracePeriod = 2 * time.Second
// ExitCodeError reports a non-zero process exit code from a container command. // ExitCodeError reports a non-zero process exit code from a container command.
type ExitCodeError int type ExitCodeError int
@@ -31,38 +34,6 @@ func (e ExitCodeError) Error() string {
return fmt.Sprintf("Process completed with exit code %d.", int(e)) return fmt.Sprintf("Process completed with exit code %d.", int(e))
} }
type commandOutput struct {
*io.PipeReader
cancel context.CancelFunc
done chan struct{}
err error
}
func (output *commandOutput) Close() error {
_, _ = io.Copy(io.Discard, output.PipeReader)
output.PipeReader.Close()
output.cancel()
<-output.done
return output.err
}
func streamOutput(ctx context.Context, run func(context.Context, io.Writer, io.Writer) error) io.ReadCloser {
ctx, cancel := context.WithCancel(ctx)
reader, writer := io.Pipe()
output := &commandOutput{PipeReader: reader, cancel: cancel, done: make(chan struct{})}
go func() {
defer close(output.done)
defer cancel()
var stderr bytes.Buffer
output.err = run(ctx, writer, &stderr)
if output.err != nil && strings.TrimSpace(stderr.String()) != "" {
output.err = fmt.Errorf("%w: %s", output.err, strings.TrimSpace(stderr.String()))
}
writer.CloseWithError(output.err)
}()
return output
}
// NewContainerInput the input for the New function // NewContainerInput the input for the New function
type NewContainerInput struct { type NewContainerInput struct {
Image string Image string
@@ -163,9 +134,7 @@ type Container interface {
Create(capAdd, capDrop []string) common.Executor Create(capAdd, capDrop []string) common.Executor
Copy(destPath string, files ...*FileEntry) common.Executor Copy(destPath string, files ...*FileEntry) common.Executor
CopyDir(destPath, srcPath string, useGitIgnore, skipGitDir bool) common.Executor CopyDir(destPath, srcPath string, useGitIgnore, skipGitDir bool) common.Executor
ExecOutput(ctx context.Context, command []string) (io.ReadCloser, error)
GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error)
CopyTarStream(ctx context.Context, destPath string, write func(*TarWriter) error) error
Inspect(ctx context.Context) (*Info, error) Inspect(ctx context.Context) (*Info, error)
DumpLogs(ctx context.Context) error DumpLogs(ctx context.Context) error
Pull(forcePull bool) common.Executor Pull(forcePull bool) common.Executor
@@ -183,6 +152,8 @@ type NewDockerBuildExecutorInput struct {
ContextDir string ContextDir string
Dockerfile string Dockerfile string
BuildContext io.Reader BuildContext io.Reader
Dockerignore []byte // applied to BuildContext as the docker CLI applies it
Stdout io.Writer
ImageTag string ImageTag string
Platform string Platform string
BuildArgs map[string]*string BuildArgs map[string]*string
+92 -2
View File
@@ -8,10 +8,13 @@ package container
import ( import (
"archive/tar" "archive/tar"
"bytes"
"context" "context"
"fmt"
"io" "io"
"io/fs" "io/fs"
"os" "os"
"path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
@@ -63,7 +66,7 @@ func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
} }
var buildContext io.ReadCloser var buildContext io.ReadCloser
if input.BuildContext != nil { if input.BuildContext != nil {
buildContext = io.NopCloser(input.BuildContext) buildContext, err = filterBuildContext(input.BuildContext, input.Dockerignore, input.Dockerfile)
} else { } else {
buildContext, err = createBuildContext(ctx, input.ContextDir, input.Dockerfile) buildContext, err = createBuildContext(ctx, input.ContextDir, input.Dockerfile)
} }
@@ -78,10 +81,97 @@ func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
if err != nil { if err != nil {
return err return err
} }
return logDockerResponse(logger, resp.Body, false) err = logDockerResponse(logger, resp.Body, func(format string, args ...any) { fmt.Fprintf(input.Stdout, format, args...) })
common.FlushWriter(input.Stdout)
return err
} }
} }
func filterBuildContext(buildContext io.Reader, dockerignore []byte, relDockerfile string) (io.ReadCloser, error) {
excludes, err := ignorefile.ReadAll(bytes.NewReader(dockerignore))
if err != nil || len(excludes) == 0 {
return io.NopCloser(buildContext), err
}
pm, err := patternmatcher.New(excludes)
if err != nil {
return nil, err
}
reader, writer := io.Pipe()
go func() {
writer.CloseWithError(writeFilteredBuildContext(writer, buildContext, pm, path.Clean(filepath.ToSlash(relDockerfile))))
}()
return reader, nil
}
func writeFilteredBuildContext(w io.Writer, buildContext io.Reader, pm *patternmatcher.PatternMatcher, relDockerfile string) error {
spool, err := os.CreateTemp("", "gitea-runner-build-") // excluded content, for a kept hardlink to it
if err != nil {
return err
}
defer os.Remove(spool.Name())
defer spool.Close()
reader := tar.NewReader(buildContext)
writer := tar.NewWriter(w)
buffer := make([]byte, 32*1024)
excluded := map[string]*excludedBuildContextEntry{}
for {
header, err := reader.Next()
if err == io.EOF {
return writer.Close()
}
if err != nil {
return err
}
name := path.Clean(header.Name)
var target *excludedBuildContextEntry
if header.Typeflag == tar.TypeLink {
target = excluded[path.Clean(header.Linkname)]
}
if name != ".dockerignore" && name != relDockerfile {
skip, err := pm.MatchesOrParentMatches(name)
if err != nil {
return err
}
if skip {
if target != nil {
excluded[name] = target
} else if header.Typeflag != tar.TypeDir {
offset, err := spool.Seek(0, io.SeekCurrent)
if err != nil {
return err
}
excluded[name] = &excludedBuildContextEntry{header: header, offset: offset}
if _, err := io.CopyBuffer(spool, reader, buffer); err != nil {
return err
}
}
continue
}
}
var content io.Reader = reader
if target != nil && target.keptName != "" {
header.Linkname = target.keptName
} else if target != nil {
header.Typeflag, header.Linkname, header.Size = target.header.Typeflag, target.header.Linkname, target.header.Size
content = io.NewSectionReader(spool, target.offset, header.Size)
target.keptName = header.Name
}
if err := writer.WriteHeader(header); err != nil {
return err
}
if _, err := io.CopyBuffer(writer, content, buffer); err != nil {
return err
}
}
}
type excludedBuildContextEntry struct {
header *tar.Header
offset int64
keptName string
}
func createBuildContext(ctx context.Context, contextDir, relDockerfile string) (io.ReadCloser, error) { func createBuildContext(ctx context.Context, contextDir, relDockerfile string) (io.ReadCloser, error) {
common.Logger(ctx).Debugf("Creating archive for build context dir '%s' with relative dockerfile '%s'", contextDir, relDockerfile) common.Logger(ctx).Debugf("Creating archive for build context dir '%s' with relative dockerfile '%s'", contextDir, relDockerfile)
+56 -1
View File
@@ -7,6 +7,8 @@ package container
import ( import (
"archive/tar" "archive/tar"
"bytes"
"fmt"
"io" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@@ -35,7 +37,7 @@ func TestDockerBuildLabelsImageWithItsTagAndReportsDaemonError(t *testing.T) {
t.Setenv("DOCKER_AUTH_CONFIG", "") t.Setenv("DOCKER_AUTH_CONFIG", "")
require.ErrorContains(t, NewDockerBuildExecutor(NewDockerBuildExecutorInput{ require.ErrorContains(t, NewDockerBuildExecutor(NewDockerBuildExecutorInput{
ImageTag: "action:test", Dockerfile: "Dockerfile", BuildContext: strings.NewReader(""), ImageTag: "action:test", Dockerfile: "Dockerfile", BuildContext: strings.NewReader(""), Stdout: io.Discard,
})(t.Context()), "build rejected") })(t.Context()), "build rejected")
require.JSONEq(t, `{"com.gitea.runner.image":"action:test"}`, labels) require.JSONEq(t, `{"com.gitea.runner.image":"action:test"}`, labels)
} }
@@ -72,3 +74,56 @@ func TestCreateBuildContextFollowsDockerignoreAndSymlinkedRootButKeepsDockerfile
require.Equal(t, []string{".dockerignore", "a.txt", "build/keep.txt", "empty/", "Dockerfile"}, names, contextDir) require.Equal(t, []string{".dockerignore", "a.txt", "build/keep.txt", "empty/", "Dockerfile"}, names, contextDir)
} }
} }
func TestFilterBuildContextAppliesDockerignoreAndMaterializesHardlinksToExcludedFiles(t *testing.T) {
const dockerignore = "*.log\nbuild\n!build/keep.txt\nActionfile\n.dockerignore\n"
for _, prefix := range []string{"", "./"} {
var archive bytes.Buffer
writer := tar.NewWriter(&archive)
for _, entry := range []struct {
name, body, link string
typeflag byte
}{
{"Actionfile", "FROM scratch", "", tar.TypeReg},
{"output.log", "log", "", tar.TypeReg},
{"build/", "", "", tar.TypeDir},
{"build/drop.txt", "drop", "", tar.TypeReg},
{"build/keep.txt", "keep", "", tar.TypeReg},
{"entrypoint", "", prefix + "output.log", tar.TypeLink},
{"other-entrypoint", "", prefix + "output.log", tar.TypeLink},
{".dockerignore", dockerignore, "", tar.TypeReg},
} {
require.NoError(t, writer.WriteHeader(&tar.Header{Name: prefix + entry.name, Linkname: entry.link, Typeflag: entry.typeflag, Size: int64(len(entry.body)), Mode: 0o644}))
_, err := io.WriteString(writer, entry.body)
require.NoError(t, err)
}
require.NoError(t, writer.Close())
unfiltered, err := filterBuildContext(bytes.NewReader(archive.Bytes()), nil, "Actionfile")
require.NoError(t, err)
passedThrough, err := io.ReadAll(unfiltered)
require.NoError(t, err)
require.Equal(t, archive.Bytes(), passedThrough)
filtered, err := filterBuildContext(bytes.NewReader(archive.Bytes()), []byte(dockerignore), "Actionfile")
require.NoError(t, err)
var entries []string
for reader := tar.NewReader(filtered); ; {
header, err := reader.Next()
if err == io.EOF {
break
}
require.NoError(t, err)
body, err := io.ReadAll(reader)
require.NoError(t, err)
entries = append(entries, fmt.Sprintf("%s %c %s %s", strings.TrimPrefix(header.Name, prefix), header.Typeflag, strings.TrimPrefix(header.Linkname, prefix), body))
}
require.Equal(t, []string{
"Actionfile 0 FROM scratch",
"build/keep.txt 0 keep",
"entrypoint 0 log",
"other-entrypoint 1 entrypoint ",
".dockerignore 0 " + dockerignore,
}, entries, prefix)
}
}
+2
View File
@@ -2,6 +2,8 @@
// Copyright 2022 The nektos/act Authors. All rights reserved. // Copyright 2022 The nektos/act Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
// This file is based on https://github.com/docker/cli/blob/4a63305d74332de5ceba7fcbccbc3cbb7412f5ba/cli/command/container/opts_test.go with: // This file is based on https://github.com/docker/cli/blob/4a63305d74332de5ceba7fcbccbc3cbb7412f5ba/cli/command/container/opts_test.go with:
// * appended with license information // * appended with license information
// * added tests for the locally changed parseDevice, validateDevice and invalidParameter // * added tests for the locally changed parseDevice, validateDevice and invalidParameter
@@ -1,6 +1,8 @@
// Copyright 2026 The Gitea Authors. All rights reserved. // Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
package container package container
import ( import (
+3 -1
View File
@@ -2,6 +2,8 @@
// Copyright 2020 The nektos/act Authors. All rights reserved. // Copyright 2020 The nektos/act Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
package container package container
import ( import (
@@ -38,7 +40,7 @@ func loadScratchImage(t *testing.T, platform string) string {
response, err := cli.ImageLoad(t.Context(), &archive) response, err := cli.ImageLoad(t.Context(), &archive)
require.NoError(t, err) require.NoError(t, err)
defer response.Close() defer response.Close()
require.NoError(t, logDockerResponse(common.Logger(t.Context()), response, false)) require.NoError(t, logDockerResponse(common.Logger(t.Context()), response, common.Logger(t.Context()).Debugf))
t.Cleanup(func() { t.Cleanup(func() {
_, _ = cli.ImageRemove(context.WithoutCancel(t.Context()), tag, mobyclient.ImageRemoveOptions{Force: true}) _, _ = cli.ImageRemove(context.WithoutCancel(t.Context()), tag, mobyclient.ImageRemoveOptions{Force: true})
}) })
+10 -25
View File
@@ -8,6 +8,7 @@ package container
import ( import (
"bufio" "bufio"
"cmp"
"encoding/json/v2" "encoding/json/v2"
"errors" "errors"
"io" "io"
@@ -26,10 +27,7 @@ type dockerMessage struct {
Progress string `json:"progress"` Progress string `json:"progress"`
} }
func logDockerResponse(logger *logging.Logger, dockerResponse io.ReadCloser, isError bool) error { func logDockerResponse(logger *logging.Logger, dockerResponse io.ReadCloser, log func(string, ...any)) error {
if dockerResponse == nil {
return nil
}
defer dockerResponse.Close() defer dockerResponse.Close()
scanner := bufio.NewScanner(dockerResponse) scanner := bufio.NewScanner(dockerResponse)
@@ -38,41 +36,28 @@ func logDockerResponse(logger *logging.Logger, dockerResponse io.ReadCloser, isE
line := scanner.Bytes() line := scanner.Bytes()
var msg dockerMessage var msg dockerMessage
if err := json.Unmarshal(line, &msg); err != nil { if err := json.Unmarshal(line, &msg); err != nil {
writeLog(logger, false, "Unable to unmarshal line [%s] ==> %v", string(line), err) logger.Debugf("Unable to unmarshal line [%s] ==> %v", string(line), err)
continue continue
} }
if msg.Error != "" { if message := cmp.Or(msg.Error, msg.ErrorDetail.Message); message != "" {
writeLog(logger, isError, "%s", msg.Error) log("%s", message)
return errors.New(msg.Error) return errors.New(message)
}
if msg.ErrorDetail.Message != "" {
writeLog(logger, isError, "%s", msg.ErrorDetail.Message)
return errors.New(msg.ErrorDetail.Message)
} }
switch { switch {
case msg.Status != "": case msg.Status != "":
if msg.Progress != "" { if msg.Progress != "" {
writeLog(logger, isError, "%s :: %s :: %s\n", msg.Status, msg.ID, msg.Progress) log("%s :: %s :: %s\n", msg.Status, msg.ID, msg.Progress)
} else { } else {
writeLog(logger, isError, "%s :: %s\n", msg.Status, msg.ID) log("%s :: %s\n", msg.Status, msg.ID)
} }
case msg.Stream != "": case msg.Stream != "":
writeLog(logger, isError, "%s", msg.Stream) log("%s", msg.Stream)
default: default:
writeLog(logger, false, "Unable to handle line: %s", string(line)) logger.Debugf("Unable to handle line: %s", string(line))
} }
} }
return scanner.Err() return scanner.Err()
} }
func writeLog(logger *logging.Logger, isError bool, format string, args ...any) {
if isError {
logger.Errorf(format, args...)
} else {
logger.Debugf(format, args...)
}
}
+2
View File
@@ -1,6 +1,8 @@
// Copyright 2026 The Gitea Authors. All rights reserved. // Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
package container package container
import ( import (
+2
View File
@@ -1,6 +1,8 @@
// Copyright 2026 The Gitea Authors. All rights reserved. // Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
package container package container
import ( import (
+1 -2
View File
@@ -61,11 +61,10 @@ func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor {
// stream rather than on the call itself, so both have to be checked // stream rather than on the call itself, so both have to be checked
pullOnce := func(opts client.ImagePullOptions) error { pullOnce := func(opts client.ImagePullOptions) error {
reader, err := cli.ImagePull(ctx, imageRef, opts) reader, err := cli.ImagePull(ctx, imageRef, opts)
streamErr := logDockerResponse(logger, reader, err != nil)
if err != nil { if err != nil {
return err return err
} }
return streamErr return logDockerResponse(logger, reader, logger.Debugf)
} }
err = pullOnce(imagePullOptions) err = pullOnce(imagePullOptions)
+6 -3
View File
@@ -2,6 +2,8 @@
// Copyright 2020 The nektos/act Authors. All rights reserved. // Copyright 2020 The nektos/act Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
package container package container
import ( import (
@@ -95,15 +97,16 @@ func TestIsPinnedImage(t *testing.T) {
// The pull path reports a failure the daemon sent mid-stream, so it must carry the reason // The pull path reports a failure the daemon sent mid-stream, so it must carry the reason
// whichever of the two shapes the daemon used. // whichever of the two shapes the daemon used.
func TestLogDockerResponseError(t *testing.T) { func TestLogDockerResponseError(t *testing.T) {
logger := logging.New(logtest.New()) logger, hook := logtest.NewLogger()
streamErr := func(line string) error { streamErr := func(line string) error {
return logDockerResponse(logger, io.NopCloser(strings.NewReader(line)), false) return logDockerResponse(logger, io.NopCloser(strings.NewReader(line)), logger.Infof)
} }
require.EqualError(t, streamErr(`{"error":"toomanyrequests: rate limit exceeded"}`), "toomanyrequests: rate limit exceeded") require.EqualError(t, streamErr(`{"error":"toomanyrequests: rate limit exceeded"}`), "toomanyrequests: rate limit exceeded")
require.EqualError(t, streamErr(`{"errorDetail":{"message":"unexpected EOF"}}`), "unexpected EOF") require.EqualError(t, streamErr(`{"errorDetail":{"message":"unexpected EOF"}}`), "unexpected EOF")
require.NoError(t, streamErr(`{"status":"Downloading"}`)) require.NoError(t, streamErr(`{"status":"Downloading"}`))
require.NoError(t, streamErr(`{"stream":"`+strings.Repeat("x", 70000)+`"}`)) require.NoError(t, streamErr(`{"stream":"`+strings.Repeat("x", 70000)+`"}`))
assert.Equal(t, logging.LevelInfo, hook.LastRecord().Level)
require.ErrorIs(t, logDockerResponse(logger, io.NopCloser(io.MultiReader( require.ErrorIs(t, logDockerResponse(logger, io.NopCloser(io.MultiReader(
strings.NewReader(`{"status":"Downloading"}`+"\n"), iotest.ErrReader(io.ErrUnexpectedEOF), strings.NewReader(`{"status":"Downloading"}`+"\n"), iotest.ErrReader(io.ErrUnexpectedEOF),
)), false), io.ErrUnexpectedEOF) )), logger.Infof), io.ErrUnexpectedEOF)
} }
+19 -88
View File
@@ -23,6 +23,7 @@ import (
"slices" "slices"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
"gitea.com/gitea/runner/act/common" "gitea.com/gitea/runner/act/common"
@@ -41,13 +42,6 @@ import (
specs "github.com/opencontainers/image-spec/specs-go/v1" specs "github.com/opencontainers/image-spec/specs-go/v1"
) )
// drainGracePeriod bounds how long we wait for an output-copy goroutine to
// finish draining a container's output before returning, so that neither a
// cancellation (waitForCommand) nor a normal container exit (wait) truncates
// the tail of the log. It is a safety bound: in the common case the stream
// reaches EOF and the goroutine returns well before this elapses.
const drainGracePeriod = 2 * time.Second
// NewContainer creates a reference to a container // NewContainer creates a reference to a container
func NewContainer(input *NewContainerInput) ExecutionsEnvironment { func NewContainer(input *NewContainerInput) ExecutionsEnvironment {
// Resolved up front because the image pull runs before the container is created. // Resolved up front because the image pull runs before the container is created.
@@ -90,8 +84,13 @@ func (cr *containerReference) Start(attach bool) common.Executor {
cr.attach().IfBool(attach), cr.attach().IfBool(attach),
cr.start(), cr.start(),
cr.wait().IfBool(attach), cr.wait().IfBool(attach),
cr.tryReadID("-u", func(id int) { cr.UID = id }), func(ctx context.Context) error {
cr.tryReadID("-g", func(id int) { cr.GID = id }), var wg sync.WaitGroup
wg.Go(func() { _ = cr.tryReadID("-u", func(id int) { cr.UID = id })(ctx) })
_ = cr.tryReadID("-g", func(id int) { cr.GID = id })(ctx)
wg.Wait()
return nil
},
func(ctx context.Context) error { func(ctx context.Context) error {
// If this fails, then folders have wrong permissions on non root container // If this fails, then folders have wrong permissions on non root container
if cr.UID != 0 || cr.GID != 0 { if cr.UID != 0 || cr.GID != 0 {
@@ -146,47 +145,6 @@ func (cr *containerReference) CopyDir(destPath, srcPath string, useGitIgnore, sk
).IfNot(common.Dryrun) ).IfNot(common.Dryrun)
} }
func (cr *containerReference) ExecOutput(ctx context.Context, command []string) (io.ReadCloser, error) {
if common.Dryrun(ctx) {
return nil, errors.New("DRYRUN is not supported in ExecOutput")
}
if err := cr.connect()(ctx); err != nil {
return nil, err
}
if err := cr.find()(ctx); err != nil {
return nil, err
}
if cr.id == "" {
return nil, cr.missingContainerError("exec %v", command)
}
return streamOutput(ctx, func(ctx context.Context, stdout, stderr io.Writer) error {
created, err := cr.cli.ExecCreate(ctx, cr.id, client.ExecCreateOptions{
Cmd: command, AttachStdout: true, AttachStderr: true,
})
if err != nil {
return err
}
attached, err := cr.cli.ExecAttach(ctx, created.ID, client.ExecAttachOptions{})
if err != nil {
return err
}
defer attached.Close()
stop := context.AfterFunc(ctx, func() { attached.Close() })
defer stop()
if _, err := stdcopy.StdCopy(stdout, stderr, attached.Reader); err != nil {
return err
}
inspected, err := cr.cli.ExecInspect(ctx, created.ID, client.ExecInspectOptions{})
if err != nil {
return err
}
if inspected.ExitCode != 0 {
return ExitCodeError(inspected.ExitCode)
}
return nil
}), nil
}
func (cr *containerReference) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) { func (cr *containerReference) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) {
if common.Dryrun(ctx) { if common.Dryrun(ctx) {
return nil, errors.New("DRYRUN is not supported in GetContainerArchive") return nil, errors.New("DRYRUN is not supported in GetContainerArchive")
@@ -232,6 +190,9 @@ func (cr *containerReference) Inspect(ctx context.Context) (*Info, error) {
} else if err != nil { } else if err != nil {
return nil, err return nil, err
} }
if cr.containerEnvID != cr.id && result.Container.Config != nil {
cr.containerEnv, cr.containerEnvID = opts.ConvertKVStringsToMap(result.Container.Config.Env), cr.id
}
return containerInfoFromInspect(result.Container), nil return containerInfoFromInspect(result.Container), nil
} }
@@ -355,15 +316,13 @@ func (cr *containerReference) UpdateFromEnv(srcPath string, env *map[string]stri
func (cr *containerReference) UpdateFromImageEnv(env *map[string]string) common.Executor { func (cr *containerReference) UpdateFromImageEnv(env *map[string]string) common.Executor {
envMap := *env envMap := *env
return common.Executor(func(ctx context.Context) error { return common.Executor(func(ctx context.Context) error {
inspect, err := cr.cli.ContainerInspect(ctx, cr.id, client.ContainerInspectOptions{}) if cr.containerEnvID != cr.id {
if err != nil { if _, err := cr.Inspect(ctx); err != nil {
common.Logger(ctx).Error(err) common.Logger(ctx).Error(err)
return fmt.Errorf("inspect container: %w", err) return fmt.Errorf("inspect container: %w", err)
} }
if inspect.Container.Config == nil {
return nil
} }
for key, value := range opts.ConvertKVStringsToMap(inspect.Container.Config.Env) { for key, value := range cr.containerEnv {
if envMap[key] == "" { if envMap[key] == "" {
envMap[key] = value envMap[key] = value
} else if key == "PATH" { } else if key == "PATH" {
@@ -414,6 +373,8 @@ type containerReference struct {
// drained and flushed the container's output. wait() blocks on it so the // drained and flushed the container's output. wait() blocks on it so the
// tail of the log lands before the step proceeds. // tail of the log lands before the step proceeds.
attachDone chan struct{} attachDone chan struct{}
containerEnv map[string]string // fixed at creation, cached by inspect for containerEnvID
containerEnvID string
LinuxContainerEnvironmentExtensions LinuxContainerEnvironmentExtensions
} }
@@ -902,6 +863,7 @@ func (cr *containerReference) tryReadID(opt string, cbk func(id int)) common.Exe
return nil return nil
} }
defer resp.Close() defer resp.Close()
defer context.AfterFunc(ctx, resp.Close)()
sid, err := resp.Reader.ReadString('\n') sid, err := resp.Reader.ReadString('\n')
if err != nil { if err != nil {
@@ -947,7 +909,7 @@ func (cr *containerReference) waitForCommand(ctx context.Context, resp client.Hi
if err != nil { if err != nil {
logger.Debugf("Failed to drain command output after cancellation: %v", err) logger.Debugf("Failed to drain command output after cancellation: %v", err)
} }
case <-time.After(drainGracePeriod): case <-time.After(DrainGracePeriod):
logger.Warn("Timed out draining command output after cancellation") logger.Warn("Timed out draining command output after cancellation")
} }
@@ -999,37 +961,6 @@ func (cr *containerReference) extractionRoot(dstPath string) string {
return "/" return "/"
} }
func (cr *containerReference) CopyTarStream(ctx context.Context, destPath string, write func(*TarWriter) error) error {
if common.Dryrun(ctx) {
return nil
}
if err := cr.connect()(ctx); err != nil {
return err
}
if err := cr.find()(ctx); err != nil {
return err
}
if cr.id == "" {
return cr.missingContainerError("copy to %s", destPath)
}
destPath = path.Clean(destPath)
root := cr.extractionRoot(destPath)
rel := func(fullPath string) string { return strings.TrimPrefix(strings.TrimPrefix(fullPath, root), "/") }
var parents []string // sent as entries so they belong to the job user, the daemon creates missing ones as root
for dir := destPath; dir != root && dir != "/" && dir != "."; dir = path.Dir(dir) {
if _, err := cr.cli.ContainerStatPath(ctx, cr.id, client.ContainerStatPathOptions{Path: dir}); err == nil {
break
} else if !cerrdefs.IsNotFound(err) {
return fmt.Errorf("stat %s: %w", dir, err)
}
parents = append(parents, rel(dir))
}
slices.Reverse(parents)
content := pipeTar(cr.UID, cr.GID, rel(destPath), parents, write)
defer content.Close()
return cr.upload(ctx, root, content)
}
func (cr *containerReference) copyContent(dstPath string, files ...*FileEntry) common.Executor { func (cr *containerReference) copyContent(dstPath string, files ...*FileEntry) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
if cr.id == "" { if cr.id == "" {
@@ -1122,7 +1053,7 @@ func (cr *containerReference) wait() common.Executor {
if cr.attachDone != nil { if cr.attachDone != nil {
select { select {
case <-cr.attachDone: case <-cr.attachDone:
case <-time.After(drainGracePeriod): case <-time.After(DrainGracePeriod):
logger.Warn("Timed out draining container output") logger.Warn("Timed out draining container output")
} }
cr.attachDone = nil cr.attachDone = nil
+24 -66
View File
@@ -2,6 +2,8 @@
// Copyright 2020 The nektos/act Authors. All rights reserved. // Copyright 2020 The nektos/act Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
package container package container
import ( import (
@@ -45,14 +47,15 @@ func TestDockerEnvironmentUsesContainerPath(t *testing.T) {
Return(mobyclient.ContainerInspectResult{Container: container.InspectResponse{Config: &container.Config{Env: []string{ Return(mobyclient.ContainerInspectResult{Container: container.InspectResponse{Config: &container.Config{Env: []string{
"PATH=/opt/node/x64/bin:/usr/bin:/bin", "CONFLICT_VAR=container-value", "SOME_RANDOM_VAR=", "PATH=/opt/node/x64/bin:/usr/bin:/bin", "CONFLICT_VAR=container-value", "SOME_RANDOM_VAR=",
"ANOTHER_ONE=old-value", "ANOTHER_ONE=BUT_I_HAVE_VALUE", "LITERAL='quoted'=$HOME\nsecond line", "ANOTHER_ONE=old-value", "ANOTHER_ONE=BUT_I_HAVE_VALUE", "LITERAL='quoted'=$HOME\nsecond line",
}}}}, nil) }}}}, nil).Once()
env := map[string]string{ env := map[string]string{
"PATH": "/custom/bin", "PATH": "/custom/bin",
"RANDOM_VAR": "WITH_VALUE", "RANDOM_VAR": "WITH_VALUE",
"ANOTHER_VAR": "", "ANOTHER_VAR": "",
"CONFLICT_VAR": "step-value", "CONFLICT_VAR": "step-value",
} }
require.NoError(t, (&containerReference{cli: client, id: "amd64-job"}).UpdateFromImageEnv(&env)(t.Context())) cr := &containerReference{cli: client, id: "amd64-job"}
require.NoError(t, cr.UpdateFromImageEnv(&env)(t.Context()))
assert.Equal(t, map[string]string{ assert.Equal(t, map[string]string{
"PATH": "/custom/bin:/opt/node/x64/bin:/usr/bin:/bin", "PATH": "/custom/bin:/opt/node/x64/bin:/usr/bin:/bin",
"RANDOM_VAR": "WITH_VALUE", "RANDOM_VAR": "WITH_VALUE",
@@ -62,6 +65,10 @@ func TestDockerEnvironmentUsesContainerPath(t *testing.T) {
"CONFLICT_VAR": "step-value", "CONFLICT_VAR": "step-value",
"LITERAL": "'quoted'=$HOME\nsecond line", "LITERAL": "'quoted'=$HOME\nsecond line",
}, env) }, env)
pathEnv := map[string]string{}
require.NoError(t, cr.UpdateFromImageEnv(&pathEnv)(t.Context()))
assert.Equal(t, "/opt/node/x64/bin:/usr/bin:/bin", pathEnv["PATH"])
client.AssertExpectations(t)
} }
type mockDockerClient struct { type mockDockerClient struct {
@@ -260,28 +267,6 @@ func TestDockerExecFailure(t *testing.T) {
assert.Equal(t, ExitCodeError(1), exitErr) assert.Equal(t, ExitCodeError(1), exitErr)
assert.Equal(t, "Process completed with exit code 1.", err.Error()) assert.Equal(t, "Process completed with exit code 1.", err.Error())
client.On("ContainerInspect", ctx, "123", mobyclient.ContainerInspectOptions{}).
Return(mobyclient.ContainerInspectResult{}, nil)
client.On("ExecCreate", mock.Anything, "123", mobyclient.ExecCreateOptions{
Cmd: []string{"printf", `a\b`}, AttachStdout: true, AttachStderr: true,
}).Return(mobyclient.ExecCreateResult{ID: "output"}, nil)
client.On("ExecAttach", mock.Anything, "output", mobyclient.ExecAttachOptions{}).
Return(mobyclient.ExecAttachResult{
Conn: &mockConn{},
Reader: bufio.NewReader(bytes.NewReader(append(stdcopyFrame(stdcopy.Stdout, "a\x00b"), stdcopyFrame(stdcopy.Stderr, " failed \n")...))),
}, nil)
client.On("ExecInspect", mock.Anything, "output", mobyclient.ExecInspectOptions{}).
Return(mobyclient.ExecInspectResult{ExitCode: 3}, nil)
output, err := cr.ExecOutput(ctx, []string{"printf", `a\b`})
require.NoError(t, err)
content, err := io.ReadAll(output)
require.ErrorAs(t, err, &exitErr)
assert.Equal(t, ExitCodeError(3), exitErr)
assert.Equal(t, "Process completed with exit code 3.: failed", err.Error())
assert.Equal(t, "a\x00b", string(content))
require.ErrorAs(t, output.Close(), &exitErr)
assert.Equal(t, ExitCodeError(3), exitErr)
client.AssertExpectations(t) client.AssertExpectations(t)
} }
@@ -378,6 +363,21 @@ func TestDockerAttachStreamClosesWithItsContext(t *testing.T) {
client.AssertExpectations(t) client.AssertExpectations(t)
} }
func TestDockerReadIDStreamClosesWithItsContext(t *testing.T) {
conn, peer := net.Pipe()
t.Cleanup(func() { _ = peer.Close() })
client := &mockDockerClient{}
client.On("ExecCreate", mock.Anything, "123", mock.AnythingOfType("client.ExecCreateOptions")).
Return(mobyclient.ExecCreateResult{ID: "id"}, nil)
client.On("ExecAttach", mock.Anything, "id", mobyclient.ExecAttachOptions{}).
Return(mobyclient.ExecAttachResult{HijackedResponse: mobyclient.NewHijackedResponse(conn, "")}, nil)
ctx, cancel := context.WithCancel(t.Context())
cancel()
require.NoError(t, (&containerReference{id: "123", cli: client}).tryReadID("-u", func(int) { t.Error("read an ID after cancellation") })(ctx))
client.AssertExpectations(t)
}
func TestDockerWaitFailure(t *testing.T) { func TestDockerWaitFailure(t *testing.T) {
ctx := t.Context() ctx := t.Context()
statusCh := make(chan container.WaitResponse, 1) statusCh := make(chan container.WaitResponse, 1)
@@ -555,8 +555,6 @@ func TestRejectsMissingContainer(t *testing.T) {
check("exec", cr.exec([]string{"echo"}, nil, "", "")(ctx)) check("exec", cr.exec([]string{"echo"}, nil, "", "")(ctx))
_, err := cr.GetContainerArchive(ctx, "/var/run/act/x") _, err := cr.GetContainerArchive(ctx, "/var/run/act/x")
check("GetContainerArchive", err) check("GetContainerArchive", err)
_, err = cr.ExecOutput(ctx, []string{"true"})
check("ExecOutput", err)
_, err = cr.Inspect(ctx) _, err = cr.Inspect(ctx)
check("Inspect", err) check("Inspect", err)
@@ -568,46 +566,6 @@ func TestRejectsMissingContainer(t *testing.T) {
check("Inspect after removal", err) check("Inspect after removal", err)
} }
func TestCopyTarStreamOwnsMissingParentsAndRejectsEscapes(t *testing.T) {
ctx := t.Context()
client := &mockDockerClient{}
client.On("ContainerInspect", ctx, "job", mobyclient.ContainerInspectOptions{}).
Return(mobyclient.ContainerInspectResult{Container: container.InspectResponse{ID: "job", Name: "/job"}}, nil)
stat := func(p string, err error) {
client.On("ContainerStatPath", ctx, "job", mobyclient.ContainerStatPathOptions{Path: p}).
Return(mobyclient.ContainerStatPathResult{}, err).Once()
}
stat("/w/out/a", cerrdefs.ErrNotFound)
stat("/w/out", cerrdefs.ErrNotFound)
stat("/w", nil)
var entries []string
client.On("CopyToContainer", ctx, "job", mock.Anything).Run(func(args mock.Arguments) {
opts := args.Get(2).(mobyclient.CopyToContainerOptions)
assert.Equal(t, "/", opts.DestinationPath)
reader := tar.NewReader(opts.Content)
for {
header, err := reader.Next()
if errors.Is(err, io.EOF) {
return
}
require.NoError(t, err)
assert.Equal(t, []any{1001, 1002, ""}, []any{header.Uid, header.Gid, header.Uname}, header.Name)
entries = append(entries, header.Name)
}
}).Return(mobyclient.CopyToContainerResult{}, nil).Once()
cr := &containerReference{id: "job", cli: client, input: &NewContainerInput{Name: "job"}, UID: 1001, GID: 1002}
require.NoError(t, cr.CopyTarStream(ctx, "/w/out/a/", func(tw *TarWriter) error {
return tw.WriteHeader(&tar.Header{Typeflag: tar.TypeReg, Name: "dir/f.txt", Mode: 0o644, Uname: "nobody"})
}))
assert.Equal(t, []string{"w/out/", "w/out/a/", "w/out/a/dir/", "w/out/a/dir/f.txt"}, entries)
client.AssertExpectations(t)
require.ErrorContains(t, writeTarStream(io.Discard, 0, 0, "w/out/a", nil, func(tw *TarWriter) error {
return tw.WriteHeader(&tar.Header{Typeflag: tar.TypeReg, Name: "../../../etc/passwd"})
}), "escapes")
}
func TestPublicCopyPipelineHandlesStaleID(t *testing.T) { func TestPublicCopyPipelineHandlesStaleID(t *testing.T) {
source := t.TempDir() source := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(source, "x"), nil, 0o644)) require.NoError(t, os.WriteFile(filepath.Join(source, "x"), nil, 0o644))
+10 -5
View File
@@ -16,8 +16,13 @@ import (
"gitea.com/gitea/runner/act/common" "gitea.com/gitea/runner/act/common"
"github.com/moby/moby/api/types/system" "github.com/moby/moby/api/types/system"
"github.com/moby/moby/client"
) )
func GetDockerClient(context.Context) (client.APIClient, error) {
return nil, errors.ErrUnsupported
}
func IsolatedCacheContainer(context.Context, netip.Addr, string) (string, error) { func IsolatedCacheContainer(context.Context, netip.Addr, string) (string, error) {
return "", nil return "", nil
} }
@@ -25,13 +30,13 @@ func IsolatedCacheContainer(context.Context, netip.Addr, string) (string, error)
// ImageExistsLocally returns a boolean indicating if an image with the // ImageExistsLocally returns a boolean indicating if an image with the
// requested name, tag and architecture exists in the local docker image store // requested name, tag and architecture exists in the local docker image store
func ImageExistsLocally(ctx context.Context, imageName, platform string) (bool, error) { func ImageExistsLocally(ctx context.Context, imageName, platform string) (bool, error) {
return false, errors.New("Unsupported Operation") return false, errors.ErrUnsupported
} }
// RemoveImage removes image from local store, the function is used to run different // RemoveImage removes image from local store, the function is used to run different
// container image architectures // container image architectures
func RemoveImage(ctx context.Context, imageName string, force, pruneChildren bool) (bool, error) { func RemoveImage(ctx context.Context, imageName string, force, pruneChildren bool) (bool, error) {
return false, errors.New("Unsupported Operation") return false, errors.ErrUnsupported
} }
func RemoveDockerJobResources(_ context.Context, _ string) error { func RemoveDockerJobResources(_ context.Context, _ string) error {
@@ -43,20 +48,20 @@ func NewDockerProxy(_ context.Context, _ string) *DockerProxy {
} }
func StartDockerProxy(daemonSocket, dir, job string) (*DockerProxy, error) { func StartDockerProxy(daemonSocket, dir, job string) (*DockerProxy, error) {
return nil, errors.New("Unsupported Operation") return nil, errors.ErrUnsupported
} }
// NewDockerBuildExecutor function to create a run executor for the container // NewDockerBuildExecutor function to create a run executor for the container
func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor { func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
return errors.New("Unsupported Operation") return errors.ErrUnsupported
} }
} }
// NewDockerPullExecutor function to create a run executor for the container // NewDockerPullExecutor function to create a run executor for the container
func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor { func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
return errors.New("Unsupported Operation") return errors.ErrUnsupported
} }
} }
+2
View File
@@ -1,6 +1,8 @@
// Copyright 2026 The Gitea Authors. All rights reserved. // Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
package container package container
import ( import (
+6 -85
View File
@@ -16,7 +16,6 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"slices"
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
@@ -36,9 +35,6 @@ type HostEnvironment struct {
TmpDir string TmpDir string
ToolCache string ToolCache string
Workdir string Workdir string
// CleanWorkdir means teardown owns Workdir and may delete it. Leave false
// when Workdir points at a caller-owned checkout (e.g. `act` local mode).
CleanWorkdir bool
ActPath string ActPath string
Root string Root string
TrackingID string // RUNNER_TRACKING_ID of the job, a step with another value keeps its leftovers TrackingID string // RUNNER_TRACKING_ID of the job, a step with another value keeps its leftovers
@@ -116,20 +112,6 @@ func (e *HostEnvironment) Inspect(_ context.Context) (*Info, error) {
return &Info{Health: HealthNone, Ports: map[string]string{}}, nil return &Info{Health: HealthNone, Ports: map[string]string{}}, nil
} }
func (e *HostEnvironment) ExecOutput(ctx context.Context, command []string) (io.ReadCloser, error) {
return streamOutput(ctx, func(ctx context.Context, stdout, stderr io.Writer) error {
cmd := exec.CommandContext(ctx, command[0], command[1:]...)
cmd.Dir, cmd.Stdout, cmd.Stderr = e.Workdir, stdout, stderr
if err := cmd.Run(); err != nil {
if exit, ok := errors.AsType[*exec.ExitError](err); ok {
return ExitCodeError(exit.ExitCode())
}
return err
}
return nil
}), nil
}
func (e *HostEnvironment) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) { func (e *HostEnvironment) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) {
srcPath = filepath.Clean(srcPath) srcPath = filepath.Clean(srcPath)
fi, err := os.Lstat(srcPath) fi, err := os.Lstat(srcPath)
@@ -177,58 +159,6 @@ func writeHostArchive(ctx context.Context, tc *filecollector.TarCollector, srcPa
return tc.WriteFile(fi.Name(), fi, linkname, f) return tc.WriteFile(fi.Name(), fi, linkname, f)
} }
func (e *HostEnvironment) CopyTarStream(ctx context.Context, destPath string, write func(*TarWriter) error) error {
if err := os.MkdirAll(destPath, 0o777); err != nil {
return err
}
root, err := os.OpenRoot(destPath)
if err != nil {
return err
}
defer root.Close()
content := pipeTar(0, 0, "", nil, write)
defer content.Close()
tr := tar.NewReader(content)
var dirs []*tar.Header
for {
if err := ctx.Err(); err != nil {
return err
}
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
break
} else if err != nil {
return err
}
hdr.Name = filepath.FromSlash(strings.TrimSuffix(hdr.Name, "/"))
if hdr.Typeflag == tar.TypeDir {
err = root.MkdirAll(hdr.Name, 0o777) // modes apply after the contents, so read-only directories can be filled
dirs = append(dirs, hdr)
} else {
err = writeRootFile(root, hdr.Name, hdr.FileInfo().Mode().Perm(), tr)
}
if err != nil {
return err
}
}
for _, dir := range slices.Backward(dirs) {
if err := root.Chmod(dir.Name, dir.FileInfo().Mode().Perm()); err != nil {
return err
}
}
return nil
}
func writeRootFile(root *os.Root, name string, mode fs.FileMode, body io.Reader) error {
_ = root.Remove(name) // replaces read-only files and applies mode, as the daemon and tar do
file, err := root.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode)
if err != nil {
return err
}
_, err = io.Copy(file, body)
return errors.Join(err, file.Close())
}
func (e *HostEnvironment) Pull(_ bool) common.Executor { func (e *HostEnvironment) Pull(_ bool) common.Executor {
return common.NewPipelineExecutor() return common.NewPipelineExecutor()
} }
@@ -350,6 +280,7 @@ func (e *HostEnvironment) exec(ctx context.Context, command []string, cmdline st
// wait, so an orphan holding cmd's stdout pipe cannot hang cmd.Wait(). // wait, so an orphan holding cmd's stdout pipe cannot hang cmd.Wait().
treeKill := process.NewTreeKill(cmd) treeKill := process.NewTreeKill(cmd)
treeKill.KeepLeftovers = !tracked treeKill.KeepLeftovers = !tracked
treeKill.GracefulCancel = true
var ppty *os.File var ppty *os.File
var tty *os.File var tty *os.File
@@ -502,24 +433,14 @@ func (e *HostEnvironment) Remove() common.Executor {
rmCtx, rmCancel := context.WithTimeout(context.Background(), hostCleanupTimeout) rmCtx, rmCancel := context.WithTimeout(context.Background(), hostCleanupTimeout)
defer rmCancel() defer rmCancel()
var errs []error err := removePathWithRetry(rmCtx, cmp.Or(e.Root, e.Path))
if err := removePathWithRetry(rmCtx, cmp.Or(e.Root, e.Path)); err != nil { if err != nil {
logger.Warnf("failed to remove host misc state %s: %v", cmp.Or(e.Root, e.Path), err) logger.Warnf("failed to remove host misc state %s: %v", cmp.Or(e.Root, e.Path), err)
errs = append(errs, err)
} }
if e.CleanWorkdir { if errors.Is(err, context.DeadlineExceeded) {
if err := removePathWithRetry(rmCtx, e.Workdir); err != nil { return nil // a stalled delete must not fail job completion
logger.Warnf("failed to remove host workspace %s: %v", e.Workdir, err)
errs = append(errs, err)
} }
} return err
for _, err := range errs {
if !errors.Is(err, context.DeadlineExceeded) {
return errors.Join(errs...)
}
}
// Teardown timed out; warned above. Do not fail job completion over it.
return nil
} }
} }
+2 -76
View File
@@ -8,7 +8,6 @@ import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"context" "context"
"fmt"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
@@ -84,69 +83,11 @@ func TestGetContainerArchive(t *testing.T) {
assert.ErrorIs(t, err, os.ErrNotExist) assert.ErrorIs(t, err, os.ErrNotExist)
} }
func TestHostCopyTarStream(t *testing.T) {
dest := filepath.Join(t.TempDir(), "out")
write := func(name string, mode int64, body string) func(*TarWriter) error {
return func(tw *TarWriter) error {
if err := tw.WriteHeader(&tar.Header{Typeflag: tar.TypeReg, Name: name, Mode: mode, Size: int64(len(body))}); err != nil {
return err
}
_, err := tw.Write([]byte(body))
return err
}
}
e := &HostEnvironment{}
require.NoError(t, e.CopyTarStream(t.Context(), dest, write("dir/run.sh", 0o755, "#!/bin/sh\n")))
content, err := os.ReadFile(filepath.Join(dest, "dir", "run.sh"))
require.NoError(t, err)
assert.Equal(t, "#!/bin/sh\n", string(content))
if runtime.GOOS != "windows" {
require.NoError(t, os.Chmod(filepath.Join(dest, "dir", "run.sh"), 0o444))
require.NoError(t, e.CopyTarStream(t.Context(), dest, func(tw *TarWriter) error {
if err := tw.WriteHeader(&tar.Header{Typeflag: tar.TypeDir, Name: "dir/", Mode: 0o555}); err != nil {
return err
}
return write("dir/run.sh", 0o755, "")(tw)
}))
t.Cleanup(func() { require.NoError(t, os.Chmod(filepath.Join(dest, "dir"), 0o755)) })
for name, mode := range map[string]os.FileMode{"dir": 0o555, filepath.Join("dir", "run.sh"): 0o755} {
info, err := os.Stat(filepath.Join(dest, name))
require.NoError(t, err)
assert.Equal(t, mode, info.Mode().Perm(), name)
}
require.NoError(t, os.Symlink(t.TempDir(), filepath.Join(dest, "link")))
require.ErrorContains(t, e.CopyTarStream(t.Context(), dest, write("link/x", 0o644, "x")), "escapes")
}
require.ErrorContains(t, e.CopyTarStream(t.Context(), dest, write("../escape", 0o644, "x")), "escapes")
assert.NoFileExists(t, filepath.Join(filepath.Dir(dest), "escape"))
require.Error(t, e.CopyTarStream(t.Context(), dest, func(_tw *TarWriter) error { return fmt.Errorf("read body: %w", io.EOF) }))
canceled, cancel := context.WithCancel(t.Context())
cancel()
require.ErrorIs(t, e.CopyTarStream(canceled, dest, write("late", 0o644, "x")), context.Canceled)
assert.NoFileExists(t, filepath.Join(dest, "late"))
}
func TestHostEnvironmentExecExitCode(t *testing.T) { func TestHostEnvironmentExecExitCode(t *testing.T) {
t.Parallel() t.Parallel()
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
t.Skip("uses POSIX shell") t.Skip("uses POSIX shell")
} }
for _, read := range []bool{true, false} {
output, err := (&HostEnvironment{AllocatePTY: true}).ExecOutput(t.Context(), []string{"sh", "-c", `test ! -t 1; printf 'out\000'; printf ' failed \n' >&2; exit 3`})
require.NoError(t, err)
if read {
content, err := io.ReadAll(output)
var exit ExitCodeError
require.ErrorAs(t, err, &exit)
assert.Equal(t, ExitCodeError(3), exit)
assert.Equal(t, "out\x00", string(content))
assert.Equal(t, "Process completed with exit code 3.: failed", err.Error())
}
var exit ExitCodeError
require.ErrorAs(t, output.Close(), &exit)
assert.Equal(t, ExitCodeError(3), exit)
}
for name, allocatePTY := range map[string]bool{"without PTY": false, "with PTY": true} { for name, allocatePTY := range map[string]bool{"without PTY": false, "with PTY": true} {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
t.Parallel() t.Parallel()
@@ -217,27 +158,12 @@ func TestHostEnvironmentAllocatePTY(t *testing.T) {
} }
func TestHostEnvironmentRemoveWorkdir(t *testing.T) { func TestHostEnvironmentRemoveWorkdir(t *testing.T) {
for name, owned := range map[string]bool{"preserves caller workdir": false, "cleans owned workdir": true} {
t.Run(name, func(t *testing.T) {
miscRoot, workdir := t.TempDir(), t.TempDir() miscRoot, workdir := t.TempDir(), t.TempDir()
e := &HostEnvironment{ e := &HostEnvironment{Path: filepath.Join(miscRoot, "hostexecutor"), Workdir: workdir, Root: miscRoot}
Path: filepath.Join(miscRoot, "hostexecutor"),
Workdir: workdir,
CleanWorkdir: owned,
Root: miscRoot,
}
require.NoError(t, os.MkdirAll(e.Path, 0o700)) require.NoError(t, os.MkdirAll(e.Path, 0o700))
require.NoError(t, os.MkdirAll(filepath.Join(miscRoot, "tmp"), 0o700))
require.NoError(t, e.Remove()(t.Context())) require.NoError(t, e.Remove()(t.Context()))
assert.NoDirExists(t, miscRoot) assert.NoDirExists(t, miscRoot)
_, err := os.Stat(workdir) assert.DirExists(t, workdir)
if owned {
assert.ErrorIs(t, err, os.ErrNotExist)
} else {
require.NoError(t, err)
}
})
}
} }
func TestRemoveAllWithContextDoesNotHangOnStuckDelete(t *testing.T) { func TestRemoveAllWithContextDoesNotHangOnStuckDelete(t *testing.T) {
+16 -15
View File
@@ -50,6 +50,7 @@ type KubernetesPod struct {
job *kubernetesContainer job *kubernetesContainer
services []*kubernetesContainer services []*kubernetesContainer
arch, path string arch, path string
imageOS string
ips []net.IP ips []net.IP
transfer *transferServer transfer *transferServer
transferImage string transferImage string
@@ -432,11 +433,12 @@ func (c *kubernetesContainer) Start(_ bool) common.Executor {
if err != nil { if err != nil {
return err return err
} }
probed := strings.SplitN(output, "\n", 3) probed := strings.SplitN(output, "\x00", 5)
for len(probed) < 3 { for len(probed) < 5 {
probed = append(probed, "") probed = append(probed, "")
} }
c.pod.arch, c.gzip, c.pod.path = goArchToActionArch(probed[0]), probed[1] == "gzip", probed[2] c.pod.arch, c.gzip, c.pod.path = goArchToActionArch(probed[0]), probed[1] == "gzip", probed[2]
c.pod.imageOS = cmp.Or(probed[3], ImageOSFromOSRelease(probed[4]))
return nil return nil
} }
} }
@@ -447,7 +449,7 @@ func (p *KubernetesPod) probe(ctx context.Context, container string) (string, er
deadline := time.Now().Add(time.Minute) deadline := time.Now().Add(time.Minute)
for delay := 100 * time.Millisecond; ; delay = min(2*delay, 2*time.Second) { for delay := 100 * time.Millisecond; ; delay = min(2*delay, 2*time.Second) {
var stdout bytes.Buffer var stdout bytes.Buffer
err := p.client.exec(ctx, p.name, container, []string{"sh", "-c", `printf '%s\n%s\n%s' "$(uname -m)" "$(command -v gzip >/dev/null && echo gzip)" "$PATH"`}, nil, &stdout, io.Discard) err := p.client.exec(ctx, p.name, container, []string{"sh", "-c", `printf '%s\0%s\0%s\0%s\0%s' "$(uname -m)" "$(command -v gzip >/dev/null && echo gzip)" "$PATH" "${ImageOS-}" "$(cat /etc/os-release 2>/dev/null || cat /usr/lib/os-release 2>/dev/null)"`}, nil, &stdout, io.Discard)
var exitErr ExitCodeError var exitErr ExitCodeError
var apiErr *apiError var apiErr *apiError
if err == nil || ctx.Err() != nil || errors.As(err, &exitErr) || time.Now().After(deadline) || if err == nil || ctx.Err() != nil || errors.As(err, &exitErr) || time.Now().After(deadline) ||
@@ -553,10 +555,6 @@ func (c *kubernetesContainer) Copy(destPath string, files ...*FileEntry) common.
} }
} }
func (c *kubernetesContainer) CopyTarStream(ctx context.Context, destPath string, write func(*TarWriter) error) error {
return c.extract(ctx, destPath, true, func(writer io.Writer) error { return writeTarStream(writer, 0, 0, "", nil, write) }) // streams carry large content like artifacts
}
func (c *kubernetesContainer) CopyDir(destPath, srcPath string, useGitIgnore, skipGitDir bool) common.Executor { func (c *kubernetesContainer) CopyDir(destPath, srcPath string, useGitIgnore, skipGitDir bool) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
return c.extract(ctx, destPath, true, func(writer io.Writer) error { // directories are actions and workspaces, megabytes of compressible sources return c.extract(ctx, destPath, true, func(writer io.Writer) error { // directories are actions and workspaces, megabytes of compressible sources
@@ -565,17 +563,17 @@ func (c *kubernetesContainer) CopyDir(destPath, srcPath string, useGitIgnore, sk
} }
} }
func (c *kubernetesContainer) ExecOutput(ctx context.Context, command []string) (io.ReadCloser, error) { // GetContainerArchive streams the archive, checking the path first as tar writes an empty archive for a missing one.
return streamOutput(ctx, func(ctx context.Context, stdout, stderr io.Writer) error {
return c.pod.client.exec(ctx, c.pod.name, c.name, command, nil, stdout, stderr)
}), nil
}
func (c *kubernetesContainer) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) { func (c *kubernetesContainer) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) {
reader, err := c.ExecOutput(ctx, []string{"sh", "-c", `test -e "$1" -o -L "$1" && exec tar -cf - -C "$2" "$3"`, "sh", srcPath, path.Dir(srcPath), path.Base(srcPath)}) reader, writer := io.Pipe()
go func() {
var stderr bytes.Buffer
err := c.pod.client.exec(ctx, c.pod.name, c.name, []string{"sh", "-c", `test -e "$1" -o -L "$1" && exec tar -cf - -C "$2" "$3"`, "sh", srcPath, path.Dir(srcPath), path.Base(srcPath)}, nil, writer, &stderr)
if err != nil { if err != nil {
return nil, err err = fmt.Errorf("archive %s: %w: %s", srcPath, err, strings.TrimSpace(stderr.String()))
} }
writer.CloseWithError(err)
}()
return startedArchive(reader) return startedArchive(reader)
} }
@@ -586,6 +584,9 @@ func (c *kubernetesContainer) UpdateFromEnv(srcPath string, env *map[string]stri
func (c *kubernetesContainer) UpdateFromImageEnv(env *map[string]string) common.Executor { func (c *kubernetesContainer) UpdateFromImageEnv(env *map[string]string) common.Executor {
return func(context.Context) error { return func(context.Context) error {
(*env)["PATH"] = cmp.Or((*env)["PATH"], c.pod.path) (*env)["PATH"] = cmp.Or((*env)["PATH"], c.pod.path)
if c.pod.imageOS != "" {
(*env)["ImageOS"] = cmp.Or((*env)["ImageOS"], c.pod.imageOS)
}
return nil return nil
} }
} }
+5 -28
View File
@@ -193,7 +193,7 @@ func TestKubernetesPodRunsJobThroughAPI(t *testing.T) {
path := workdir + ":" + os.Getenv("PATH") path := workdir + ":" + os.Getenv("PATH")
kubeconfig, cluster := fakeKubernetes(t, `{"spec":{"containers":[{},{}]},"status":{"phase":"Running","containerStatuses":[ kubeconfig, cluster := fakeKubernetes(t, `{"spec":{"containers":[{},{}]},"status":{"phase":"Running","containerStatuses":[
{"name":"job","ready":true,"state":{"running":{}}}, {"name":"job","ready":true,"state":{"running":{}}},
{"name":"my-db","ready":true,"state":{"running":{}}}]}}`, "PATH="+path) {"name":"my-db","ready":true,"state":{"running":{}}}]}}`, "PATH="+path, "ImageOS=ubuntu24-arm64")
options := KubernetesOptions{Kubeconfig: kubeconfig, RunnerUUID: "runner-uuid", PodTemplates: []map[string]any{ options := KubernetesOptions{Kubeconfig: kubeconfig, RunnerUUID: "runner-uuid", PodTemplates: []map[string]any{
{"spec": map[string]any{ {"spec": map[string]any{
"automountServiceAccountToken": true, "automountServiceAccountToken": true,
@@ -273,17 +273,6 @@ func TestKubernetesPodRunsJobThroughAPI(t *testing.T) {
assert.Equal(t, "hunter2\nit's\nme\n5\n"+workdir+"\n", jobLog.String()) assert.Equal(t, "hunter2\nit's\nme\n5\n"+workdir+"\n", jobLog.String())
assert.Equal(t, ExitCodeError(3), job.Exec([]string{"sh", "-c", "echo failing >&2; exit 3"}, nil, "", "")(ctx)) assert.Equal(t, ExitCodeError(3), job.Exec([]string{"sh", "-c", "echo failing >&2; exit 3"}, nil, "", "")(ctx))
assert.Contains(t, jobLog.String(), "failing\n") assert.Contains(t, jobLog.String(), "failing\n")
output, err := job.ExecOutput(ctx, []string{"sh", "-c", `printf 'out\000'; printf ' failed \n' >&2; exit 3`})
require.NoError(t, err)
content, err := io.ReadAll(output)
var exit ExitCodeError
require.ErrorAs(t, err, &exit)
assert.Equal(t, ExitCodeError(3), exit)
assert.Contains(t, err.Error(), ": failed")
assert.Equal(t, "out\x00", string(content))
require.ErrorAs(t, output.Close(), &exit)
assert.Equal(t, ExitCodeError(3), exit)
for _, query := range cluster.requests["exec"] { for _, query := range cluster.requests["exec"] {
assert.NotContains(t, query, "hunter2") assert.NotContains(t, query, "hunter2")
} }
@@ -296,7 +285,7 @@ func TestKubernetesPodRunsJobThroughAPI(t *testing.T) {
reader := tar.NewReader(archive) reader := tar.NewReader(archive)
header, err := reader.Next() header, err := reader.Next()
require.NoError(t, err) require.NoError(t, err)
content, err = io.ReadAll(reader) content, err := io.ReadAll(reader)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "event.json", header.Name) assert.Equal(t, "event.json", header.Name)
assert.JSONEq(t, `{"ref":"main"}`, string(content)) assert.JSONEq(t, `{"ref":"main"}`, string(content))
@@ -320,21 +309,9 @@ func TestKubernetesPodRunsJobThroughAPI(t *testing.T) {
assert.Contains(t, lastExec(), "command="+url.QueryEscape(workdir+"/act/actions/sha/")) assert.Contains(t, lastExec(), "command="+url.QueryEscape(workdir+"/act/actions/sha/"))
assert.Contains(t, lastExec(), url.QueryEscape("gzip -dc |")) assert.Contains(t, lastExec(), url.QueryEscape("gzip -dc |"))
require.NoError(t, job.CopyTarStream(ctx, workdir+"/download/new", func(tw *TarWriter) error { imageEnv := map[string]string{}
if err := tw.WriteHeader(&tar.Header{Typeflag: tar.TypeReg, Name: "dir/data.txt", Mode: 0o644, Size: 7}); err != nil { require.NoError(t, job.UpdateFromImageEnv(&imageEnv)(ctx))
return err assert.Equal(t, map[string]string{"PATH": path, "ImageOS": "ubuntu24-arm64"}, imageEnv)
}
_, err := tw.Write([]byte("payload"))
return err
}))
downloaded, err := os.ReadFile(workdir + "/download/new/dir/data.txt")
require.NoError(t, err)
assert.Equal(t, "payload", string(downloaded))
assert.Contains(t, lastExec(), url.QueryEscape("gzip -dc |"))
pathEnv := map[string]string{}
require.NoError(t, job.UpdateFromImageEnv(&pathEnv)(ctx))
assert.Equal(t, path, pathEnv["PATH"])
info, err := service.Inspect(ctx) info, err := service.Inspect(ctx)
require.NoError(t, err) require.NoError(t, err)
@@ -108,3 +108,22 @@ func (*LinuxContainerEnvironmentExtensions) GetRunnerContext(ctx context.Context
func (*LinuxContainerEnvironmentExtensions) IsEnvironmentCaseInsensitive() bool { func (*LinuxContainerEnvironmentExtensions) IsEnvironmentCaseInsensitive() bool {
return false return false
} }
// ImageOSFromOSRelease derives ImageOS from an os-release file, empty for anything but Ubuntu, the only Linux GitHub names one.
func ImageOSFromOSRelease(osRelease string) string {
var id, major string
for line := range strings.Lines(osRelease) {
key, value, _ := strings.Cut(strings.TrimSpace(line), "=")
value = strings.Trim(value, `"'`)
switch key {
case "ID":
id = value
case "VERSION_ID":
major, _, _ = strings.Cut(value, ".")
}
}
if id != "ubuntu" || major == "" {
return ""
}
return id + major
}
+1 -70
View File
@@ -8,11 +8,7 @@ import (
"archive/tar" "archive/tar"
"bufio" "bufio"
"context" "context"
"errors"
"fmt"
"io" "io"
"io/fs"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -20,73 +16,8 @@ import (
"gitea.com/gitea/runner/act/filecollector" "gitea.com/gitea/runner/act/filecollector"
) )
// TarWriter takes directories and files named relative to the destination, owned by the job user.
type TarWriter struct {
writer *tar.Writer
uid, gid int
prefix string
dirs map[string]bool
}
func (w *TarWriter) Write(data []byte) (int, error) {
return w.writer.Write(data)
}
func (w *TarWriter) WriteHeader(hdr *tar.Header) error {
name := strings.TrimSuffix(hdr.Name, "/")
if !fs.ValidPath(name) {
return fmt.Errorf("tar entry %q escapes the destination", hdr.Name)
}
if hdr.Typeflag != tar.TypeDir && hdr.Typeflag != tar.TypeReg {
return fmt.Errorf("tar entry %q: unsupported type %q", hdr.Name, hdr.Typeflag)
}
for index := range len(name) {
if dir := name[:index]; name[index] == '/' && !w.dirs[dir] {
if err := w.write(&tar.Header{Typeflag: tar.TypeDir, Name: path.Join(w.prefix, dir), Mode: 0o755}); err != nil {
return err
}
w.dirs[dir] = true
}
}
if hdr.Typeflag == tar.TypeDir {
w.dirs[name] = true
}
entry := *hdr
entry.Name = path.Join(w.prefix, name)
return w.write(&entry)
}
func (w *TarWriter) write(hdr *tar.Header) error {
hdr.Uid, hdr.Gid, hdr.Uname, hdr.Gname = w.uid, w.gid, "", "" // tar running as root prefers names over ids
if hdr.Typeflag == tar.TypeDir {
hdr.Name += "/"
}
return w.writer.WriteHeader(hdr)
}
func writeTarStream(dst io.Writer, uid, gid int, prefix string, parents []string, write func(*TarWriter) error) error {
tw := &TarWriter{writer: tar.NewWriter(dst), uid: uid, gid: gid, prefix: prefix, dirs: map[string]bool{}}
for _, name := range parents {
if err := tw.write(&tar.Header{Typeflag: tar.TypeDir, Name: name, Mode: 0o755}); err != nil {
return err
}
}
if err := write(tw); errors.Is(err, io.EOF) {
return fmt.Errorf("tar stream: %v", err) // %v, as a wrapped io.EOF reads as the archive's end
} else if err != nil {
return err
}
return tw.writer.Close()
}
func pipeTar(uid, gid int, prefix string, parents []string, write func(*TarWriter) error) *io.PipeReader {
reader, writer := io.Pipe()
go func() { writer.CloseWithError(writeTarStream(writer, uid, gid, prefix, parents, write)) }()
return reader
}
// startedArchive returns reader once its first byte arrives, so failing to start archiving errors here, not on read. // startedArchive returns reader once its first byte arrives, so failing to start archiving errors here, not on read.
func startedArchive(reader io.ReadCloser) (io.ReadCloser, error) { func startedArchive(reader *io.PipeReader) (io.ReadCloser, error) {
buffered := bufio.NewReader(reader) buffered := bufio.NewReader(reader)
if _, err := buffered.Peek(1); err != nil { if _, err := buffered.Peek(1); err != nil {
reader.Close() reader.Close()
+5 -2
View File
@@ -346,8 +346,10 @@ func execAsDocker(ctx context.Context, step actionStep, actionName, actionDir, b
ImageTag: image, ImageTag: image,
Platform: rc.Config.ContainerArchitecture, Platform: rc.Config.ContainerArchitecture,
BuildArgs: rc.proxyBuildArgs(), BuildArgs: rc.proxyBuildArgs(),
Stdout: common.NewLineWriter(rawLogLine(ctx)),
} }
if localAction { if localAction {
input.Dockerignore, _ = readSingleFileFromContainerArchive(ctx, rc.JobContainer, contextDir+"/.dockerignore", 1<<20)
buildContext, err := rc.JobContainer.GetContainerArchive(ctx, contextDir+"/.") buildContext, err := rc.JobContainer.GetContainerArchive(ctx, contextDir+"/.")
if err != nil { if err != nil {
return err return err
@@ -472,7 +474,7 @@ func newStepContainer(ctx context.Context, step step, image string, cmd, entrypo
envList = append(envList, rc.runnerEnv(ctx)...) envList = append(envList, rc.runnerEnv(ctx)...)
binds, mounts := rc.GetBindsAndMounts(ctx) binds, mounts, _ := rc.GetBindsAndMounts(ctx)
networkMode := "container:" + rc.jobContainerName() networkMode := "container:" + rc.jobContainerName()
if rc.IsHostEnv() { if rc.IsHostEnv() {
networkMode = "default" networkMode = "default"
@@ -587,7 +589,8 @@ func shouldRunPreStep(step actionStep) common.Conditional {
func hasPreStep(step actionStep) common.Conditional { func hasPreStep(step actionStep) common.Conditional {
return func(ctx context.Context) bool { return func(ctx context.Context) bool {
action := step.getActionModel() action := step.getActionModel()
return action.Runs.Using.IsComposite() || // a pre stage evaluates `with` before earlier steps run, so only a composite nesting actions gets one
return (action.Runs.Using.IsComposite() && slices.ContainsFunc(action.Runs.Steps, func(compositeStep model.Step) bool { return compositeStep.Uses != "" })) ||
(action.Runs.Using.IsNode() && (action.Runs.Using.IsNode() &&
action.Runs.Pre != "") || action.Runs.Pre != "") ||
(action.Runs.Using.IsDocker() && (action.Runs.Using.IsDocker() &&
+2 -2
View File
@@ -217,11 +217,11 @@ func (rc *RunContext) compositeExecutor(action *model.Action) *compositeSteps {
steps = append(steps, newCompositeStepLogExecutor(rc.newCompositeCommandExecutor(step.main()), stepID)) steps = append(steps, newCompositeStepLogExecutor(rc.newCompositeCommandExecutor(step.main()), stepID))
// run the post executor in reverse order // run the post executor in reverse order
stepPost := rc.newCompositeCommandExecutor(step.post()) stepPost := newCompositeStepLogExecutor(rc.newCompositeCommandExecutor(step.post()), stepID)
if postExecutor != nil { if postExecutor != nil {
stepPost = stepPost.Finally(postExecutor) stepPost = stepPost.Finally(postExecutor)
} }
postExecutor = newCompositeStepLogExecutor(stepPost, stepID) postExecutor = stepPost
} }
steps = append(steps, common.JobError) steps = append(steps, common.JobError)
+13 -20
View File
@@ -11,8 +11,6 @@ import (
"gitea.com/gitea/runner/act/common/git" "gitea.com/gitea/runner/act/common/git"
"gitea.com/gitea/runner/act/common/logging" "gitea.com/gitea/runner/act/common/logging"
"gitea.com/gitea/runner/act/common/logging/logtest" "gitea.com/gitea/runner/act/common/logging/logtest"
"gitea.com/gitea/runner/act/container"
"gitea.com/gitea/runner/internal/pkg/action"
"gitea.dev/actionslib/pkg/model" "gitea.dev/actionslib/pkg/model"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -101,6 +99,19 @@ func TestCompositeActionParity(t *testing.T) {
require.ErrorIs(t, rc.compositeExecutor(&model.Action{Runs: model.ActionRuns{Using: "composite", Steps: []model.Step{{ID: "nested", Uses: "org/action@v1"}}}}).pre(t.Context()), assert.AnError) require.ErrorIs(t, rc.compositeExecutor(&model.Action{Runs: model.ActionRuns{Using: "composite", Steps: []model.Step{{ID: "nested", Uses: "org/action@v1"}}}}).pre(t.Context()), assert.AnError)
}) })
t.Run("post steps log under their own step ids", func(t *testing.T) {
hook := logtest.NewWithLevel(logging.LevelDebug)
rc := &RunContext{Config: &Config{}, JobContainer: &jobContainerMock{}}
steps := rc.compositeExecutor(&model.Action{Runs: model.ActionRuns{Using: "composite", Steps: []model.Step{{ID: "first", Uses: "./first"}, {ID: "second", Uses: "./second"}}}})
require.NoError(t, steps.post(common.WithLogger(t.Context(), logging.New(hook))))
var stepIDs []any
for _, record := range hook.AllRecords() {
ids, _ := record.Attr("stepID")
stepIDs = append(stepIDs, ids)
}
assert.Equal(t, []any{[]string{"second"}, []string{"first"}}, stepIDs)
})
} }
func TestAppendUniqueMasks(t *testing.T) { func TestAppendUniqueMasks(t *testing.T) {
@@ -184,21 +195,3 @@ func newTestCompositeRunContext(t *testing.T, parent *RunContext) *RunContext {
require.NoError(t, err) require.NoError(t, err)
return composite return composite
} }
func TestBuiltinActionGetsLowercaseInputsAndTheJobTokenInComposites(t *testing.T) {
job := makeTestRC(t, "runs-on: ubuntu-latest")
job.Config.Secrets = map[string]string{"ACTIONS_RUNTIME_TOKEN": "daemon-token"}
job.JobContainer = &container.HostEnvironment{Path: t.TempDir(), ActPath: t.TempDir(), Workdir: t.TempDir()}
composite := newTestCompositeRunContext(t, job)
composite.JobContainer = job.JobContainer
for _, rc := range []*RunContext{job, composite} {
var got *action.Context
sab := &stepActionBuiltin{Step: &model.Step{ID: "x", With: map[string]string{"Name": "x"}}, RunContext: rc, run: func(_ctx context.Context, c *action.Context) error {
got = c
return nil
}}
require.NoError(t, sab.main()(t.Context()))
assert.Equal(t, "daemon-token", got.RuntimeToken)
assert.Equal(t, map[string]string{"name": "x"}, got.Inputs)
}
}
+4 -1
View File
@@ -751,12 +751,15 @@ func TestExecAsDockerStageEntrypoint(t *testing.T) {
} }
} }
func TestDockerActionHasPreAndPostStep(t *testing.T) { func TestActionHasPreAndPostStep(t *testing.T) {
newStep := func(runs model.ActionRuns) actionStep { newStep := func(runs model.ActionRuns) actionStep {
return &stepActionRemote{action: &model.Action{Runs: runs}} return &stepActionRemote{action: &model.Action{Runs: runs}}
} }
ctx := t.Context() ctx := t.Context()
assert.False(t, hasPreStep(newStep(model.ActionRuns{Using: "composite", Steps: []model.Step{{Run: "true"}}}))(ctx))
assert.True(t, hasPreStep(newStep(model.ActionRuns{Using: "composite", Steps: []model.Step{{Run: "true"}, {Uses: "actions/cache@v4"}}}))(ctx))
assert.False(t, hasPreStep(newStep(model.ActionRuns{Using: "docker", Image: "Dockerfile"}))(ctx)) assert.False(t, hasPreStep(newStep(model.ActionRuns{Using: "docker", Image: "Dockerfile"}))(ctx))
assert.False(t, hasPostStep(newStep(model.ActionRuns{Using: "docker", Image: "Dockerfile"}))(ctx)) assert.False(t, hasPostStep(newStep(model.ActionRuns{Using: "docker", Image: "Dockerfile"}))(ctx))
+7 -4
View File
@@ -101,10 +101,10 @@ func TestMainStepsExecutorRunsAlwaysStepsAfterInterruption(t *testing.T) {
assert.Equal(t, []string{"step1", "always-step"}, ran) assert.Equal(t, []string{"step1", "always-step"}, ran)
require.NoError(t, laterStepCtxErr) require.NoError(t, laterStepCtxErr)
assert.Equal(t, wantError == context.Canceled, rc.jobCancelled) assert.Equal(t, wantError == context.Canceled, rc.jobCancelled)
assert.Equal(t, "cancelled", rc.getJobContext().Status)
setJobResult(t.Context(), rc, rc, true) setJobResult(t.Context(), rc, rc, true)
if wantError == context.DeadlineExceeded { if wantError == context.DeadlineExceeded {
assert.True(t, rc.jobFailed) assert.True(t, rc.jobFailed)
assert.Equal(t, "failure", rc.getJobContext().Status)
assert.Equal(t, "failure", rc.Run.Job().Result) assert.Equal(t, "failure", rc.Run.Job().Result)
} else { } else {
assert.Equal(t, "cancelled", rc.Run.Job().Result) assert.Equal(t, "cancelled", rc.Run.Job().Result)
@@ -259,8 +259,11 @@ func TestReportStepErrorTreatsCancelAsInterruption(t *testing.T) {
assert.True(t, rc.jobCancelled) assert.True(t, rc.jobCancelled)
// a real error still fails the job // a real error still fails the job
for _, stepErr := range []error{assert.AnError, context.DeadlineExceeded} {
rc := &RunContext{}
failed := common.WithJobErrorContainer(t.Context()) failed := common.WithJobErrorContainer(t.Context())
reportStepError(failed, rc, assert.AnError) reportStepError(failed, rc, stepErr)
require.ErrorIs(t, common.JobError(failed), assert.AnError) require.ErrorIs(t, common.JobError(failed), stepErr)
assert.True(t, rc.jobFailed) assert.Equal(t, "failure", rc.getJobContext().Status)
}
} }
+4
View File
@@ -118,8 +118,12 @@ func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
rawLogger.Infof("%s", formatAnnotation(command, kvPairs, arg)) rawLogger.Infof("%s", formatAnnotation(command, kvPairs, arg))
return false return false
case "group", "endgroup": case "group", "endgroup":
if strings.HasPrefix(line, "::"+command+"::") || strings.HasPrefix(line, "##["+command+"]") {
return true return true
} }
rawLogger.Infof("::%s::%s", command, EscapeCommandData(arg))
return false
}
return echoed return echoed
} }
} }
+15 -2
View File
@@ -240,10 +240,23 @@ func TestCommandLogWriter(t *testing.T) {
"::notice::title: m", "::error::x: m", "::error::x:1: m", "::notice::std::vector", "::error::x;y: m]", "::notice::title: m", "::error::x: m", "::error::x:1: m", "::notice::std::vector", "::error::x;y: m]",
}, },
}, },
{
name: "groups normalize unsupported prefixes and preserve recognized prefixes",
steps: [][]string{{
"::group::a%3Bb%5Dc%250A", "::endgroup::", "##[group]a%3Bb%5Dc%250A", "##[endgroup]",
"::GrOuP::a%25b%0Ac", "::EnDgRoUp::", " \t::group::indented", " \t::endgroup::",
"prefix ##[GrOuP]a%3Bb%5Dc%253B%0A", "prefix ##[EnDgRoUp]",
}},
log: []string{
"::group::a%3Bb%5Dc%250A", "::endgroup::", "##[group]a%3Bb%5Dc%250A", "##[endgroup]",
"::group::a%25b%0Ac", "::endgroup::", "::group::indented", "::endgroup::",
"::group::a;b]c%253B%0A", "::endgroup::",
},
},
{ {
name: "stop-commands keeps lines verbatim until resumed", name: "stop-commands keeps lines verbatim until resumed",
steps: [][]string{{"::stop-commands::resume-token", "::add-mask::kept", "::set-output name=a::b", "::RESUME-TOKEN::", "::add-mask::masked"}}, steps: [][]string{{"::stop-commands::resume-token", "::add-mask::kept", "::set-output name=a::b", " \t::GrOuP::kept%3B", "prefix ##[EnDgRoUp]", "::RESUME-TOKEN::", "::add-mask::masked"}},
log: []string{"::stop-commands::resume-token", "::add-mask::kept", "::set-output name=a::b", "::RESUME-TOKEN::"}, log: []string{"::stop-commands::resume-token", "::add-mask::kept", "::set-output name=a::b", " \t::GrOuP::kept%3B", "prefix ##[EnDgRoUp]", "::RESUME-TOKEN::"},
masks: []string{"resume-token", "masked"}, masks: []string{"resume-token", "masked"},
}, },
{ {
+9 -9
View File
@@ -54,6 +54,10 @@ func (cm *containerMock) UpdateFromEnv(srcPath string, env *map[string]string) c
return cm.Called(srcPath, env).Get(0).(func(context.Context) error) return cm.Called(srcPath, env).Get(0).(func(context.Context) error)
} }
func (cm *containerMock) UpdateFromImageEnv(_env *map[string]string) common.Executor {
return noopExecutor
}
func (cm *containerMock) Copy(destPath string, files ...*container.FileEntry) common.Executor { func (cm *containerMock) Copy(destPath string, files ...*container.FileEntry) common.Executor {
return cm.Called(destPath, files).Get(0).(func(context.Context) error) return cm.Called(destPath, files).Get(0).(func(context.Context) error)
} }
@@ -66,16 +70,11 @@ func (cm *containerMock) Exec(command []string, env map[string]string, user, wor
return cm.Called(command, env, user, workdir).Get(0).(func(context.Context) error) return cm.Called(command, env, user, workdir).Get(0).(func(context.Context) error)
} }
func (cm *containerMock) ExecOutput(ctx context.Context, command []string) (io.ReadCloser, error) {
args := cm.Called(ctx, command)
output, _ := args.Get(0).(io.ReadCloser)
return output, args.Error(1)
}
func (cm *containerMock) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) { func (cm *containerMock) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) {
args := cm.Called(ctx, srcPath) args := cm.Called(ctx, srcPath)
reader, _ := args.Get(0).(io.ReadCloser)
err, _ := args.Get(1).(error) err, _ := args.Get(1).(error)
return args.Get(0).(io.ReadCloser), err return reader, err
} }
func (cm *containerMock) DumpLogs(ctx context.Context) error { func (cm *containerMock) DumpLogs(ctx context.Context) error {
@@ -89,6 +88,7 @@ func (cm *containerMock) Inspect(ctx context.Context) (*container.Info, error) {
return info, err return info, err
} }
func (cm *containerMock) CopyTarStream(ctx context.Context, destPath string, write func(*container.TarWriter) error) error { func (cm *containerMock) ReplaceLogWriter(stdout, stderr io.Writer) (io.Writer, io.Writer) {
return cm.Called(ctx, destPath, write).Error(0) args := cm.Called(stdout, stderr)
return args.Get(0).(io.Writer), args.Get(1).(io.Writer)
} }
+7 -1
View File
@@ -136,7 +136,7 @@ func getHashFilesFunction(ctx context.Context, rc *RunContext) func(v []reflect.
followSymlink := false followSymlink := false
for i, p := range v { for i, p := range v {
s := p.String() s := exprparser.CoerceToString(p)
if i == 0 && strings.HasPrefix(s, "--") { if i == 0 && strings.HasPrefix(s, "--") {
if strings.EqualFold(s, "--follow-symbolic-links") { if strings.EqualFold(s, "--follow-symbolic-links") {
followSymlink = true followSymlink = true
@@ -324,6 +324,12 @@ func (rc *RunContext) resolveWorkflowCall(ctx context.Context) error {
if rc.workflowCallSecrets, err = callerEval.EvaluateCallerSecrets(secrets); err != nil { if rc.workflowCallSecrets, err = callerEval.EvaluateCallerSecrets(secrets); err != nil {
return fmt.Errorf("unable to interpolate %w", err) return fmt.Errorf("unable to interpolate %w", err)
} }
for _, name := range []string{"GITHUB_TOKEN", "GITEA_TOKEN"} {
token, ok := rc.Config.Secrets[name]
if _, mapped := common.LookupFold(rc.workflowCallSecrets, name, true); ok && !mapped {
rc.workflowCallSecrets[name] = token
}
}
return nil return nil
} }
+17 -8
View File
@@ -178,7 +178,7 @@ func (c *hashFilesContainer) ReplaceLogWriter(stdout, stderr io.Writer) (io.Writ
} }
func TestGetHashFilesFunction(t *testing.T) { func TestGetHashFilesFunction(t *testing.T) {
const failureMessage = "hashFiles('dir''file, *.sum') failed. Fail to hash files under directory '/workspace'" const failureMessage = "hashFiles('dir''file, *.sum, 123, true, ') failed. Fail to hash files under directory '/workspace'"
for _, test := range []struct { for _, test := range []struct {
name string name string
output string output string
@@ -192,7 +192,7 @@ func TestGetHashFilesFunction(t *testing.T) {
{name: "success", output: "patterns __OUTPUT__wrong__OUTPUT__ echoed\n__OUTPUT__digest__OUTPUT__", hash: "digest"}, {name: "success", output: "patterns __OUTPUT__wrong__OUTPUT__ echoed\n__OUTPUT__digest__OUTPUT__", hash: "digest"},
{name: "no matches", output: "__OUTPUT____OUTPUT__"}, {name: "no matches", output: "__OUTPUT____OUTPUT__"},
{name: "script failure", output: "Cannot find: node in PATH\n__OUTPUT__digest__OUTPUT__", execErr: container.ExitCodeError(1), err: failureMessage}, {name: "script failure", output: "Cannot find: node in PATH\n__OUTPUT__digest__OUTPUT__", execErr: container.ExitCodeError(1), err: failureMessage},
{name: "timeout", execErr: context.DeadlineExceeded, err: "hashFiles('dir''file, *.sum') couldn't finish within 120 seconds"}, {name: "timeout", execErr: context.DeadlineExceeded, err: "hashFiles('dir''file, *.sum, 123, true, ') couldn't finish within 120 seconds"},
{name: "job deadline", execErr: context.DeadlineExceeded, expired: true, err: context.DeadlineExceeded.Error()}, {name: "job deadline", execErr: context.DeadlineExceeded, expired: true, err: context.DeadlineExceeded.Error()},
{name: "node missing", execErr: fmt.Errorf("wrapped: %w", container.ExitCodeError(127)), warning: true}, {name: "node missing", execErr: fmt.Errorf("wrapped: %w", container.ExitCodeError(127)), warning: true},
{name: "node not executable", execErr: container.ExitCodeError(126), warning: true}, {name: "node not executable", execErr: container.ExitCodeError(126), warning: true},
@@ -205,7 +205,7 @@ func TestGetHashFilesFunction(t *testing.T) {
jobContainer := &hashFilesContainer{stdout: stdout, stderr: stderr, copyErr: test.copyErr} jobContainer := &hashFilesContainer{stdout: stdout, stderr: stderr, copyErr: test.copyErr}
jobContainer.execute = func(command []string, env map[string]string, user, workdir string) common.Executor { jobContainer.execute = func(command []string, env map[string]string, user, workdir string) common.Executor {
assert.Equal(t, []string{"node", "/var/run/act/workflow/hashfiles/index.js"}, command) assert.Equal(t, []string{"node", "/var/run/act/workflow/hashfiles/index.js"}, command)
assert.Equal(t, map[string]string{"patterns": "dir'file\n*.sum", "followSymbolicLinks": "true"}, env) assert.Equal(t, map[string]string{"patterns": "dir'file\n*.sum\n123\ntrue\n", "followSymbolicLinks": "true"}, env)
assert.Empty(t, user) assert.Empty(t, user)
assert.Empty(t, workdir) assert.Empty(t, workdir)
return func(_ctx context.Context) error { return func(_ctx context.Context) error {
@@ -223,7 +223,7 @@ func TestGetHashFilesFunction(t *testing.T) {
result, err := getHashFilesFunction(ctx, &RunContext{ result, err := getHashFilesFunction(ctx, &RunContext{
Config: &Config{Workdir: "/workspace"}, Config: &Config{Workdir: "/workspace"},
JobContainer: jobContainer, JobContainer: jobContainer,
})([]reflect.Value{reflect.ValueOf("--follow-symbolic-links"), reflect.ValueOf("dir'file"), reflect.ValueOf("*.sum")}) })([]reflect.Value{reflect.ValueOf("--follow-symbolic-links"), reflect.ValueOf("dir'file"), reflect.ValueOf("*.sum"), reflect.ValueOf(float64(123)), reflect.ValueOf(true), {}})
if test.err == "" { if test.err == "" {
require.NoError(t, err) require.NoError(t, err)
} else { } else {
@@ -503,7 +503,7 @@ jobs:
assert.Equal(t, "workflow", env["INPUT_FALLBACK"]) assert.Equal(t, "workflow", env["INPUT_FALLBACK"])
} }
func TestResolveWorkflowCallToleratesMismatchesAndPassesInheritedSecretsAndRuntimeToken(t *testing.T) { func TestResolveWorkflowCallToleratesMismatchesAndPassesSecretsAndTokens(t *testing.T) {
callerWorkflow, err := model.ReadWorkflow(strings.NewReader(` callerWorkflow, err := model.ReadWorkflow(strings.NewReader(`
jobs: jobs:
call: call:
@@ -513,6 +513,9 @@ jobs:
inherit: inherit:
uses: ./reuse.yml uses: ./reuse.yml
secrets: inherit secrets: inherit
override:
uses: ./reuse.yml
secrets: {github_token: "${{ secrets.token }}", GITEA_TOKEN: ""}
`)) `))
require.NoError(t, err) require.NoError(t, err)
callee, err := model.ReadWorkflow(strings.NewReader(` callee, err := model.ReadWorkflow(strings.NewReader(`
@@ -527,7 +530,7 @@ jobs:
notCallable, err := model.ReadWorkflow(strings.NewReader("on: push\njobs:\n test: {}\n")) notCallable, err := model.ReadWorkflow(strings.NewReader("on: push\njobs:\n test: {}\n"))
require.NoError(t, err) require.NoError(t, err)
config := &Config{ config := &Config{
Secrets: map[string]string{"token": "${{ github.token }}"}, Secrets: map[string]string{"token": "${{ github.token }}", "GITHUB_TOKEN": "github-token", "GITEA_TOKEN": "gitea-token"},
PresetGitHubContext: &model.GithubContext{}, PresetGitHubContext: &model.GithubContext{},
RuntimeTokens: map[*model.Workflow]string{callerWorkflow: "caller-run"}, RuntimeTokens: map[*model.Workflow]string{callerWorkflow: "caller-run"},
} }
@@ -541,11 +544,17 @@ jobs:
called := resolve("call", callee) called := resolve("call", callee)
assert.Equal(t, map[string]any{"flag": true}, called.workflowCallInputs) assert.Equal(t, map[string]any{"flag": true}, called.workflowCallInputs)
assert.Equal(t, map[string]string{"undeclared": "${{ github.token }}"}, called.workflowCallSecrets) assert.Equal(t, map[string]string{"undeclared": "${{ github.token }}", "GITHUB_TOKEN": "github-token", "GITEA_TOKEN": "gitea-token"}, called.workflowCallSecrets)
assert.Equal(t, "caller-run", called.GetEnv()["ACTIONS_RUNTIME_TOKEN"]) assert.Equal(t, "caller-run", called.GetEnv()["ACTIONS_RUNTIME_TOKEN"])
inherited := resolve("inherit", notCallable) inherited := resolve("inherit", notCallable)
assert.Empty(t, inherited.workflowCallInputs) assert.Empty(t, inherited.workflowCallInputs)
assert.Equal(t, map[string]string{"token": "${{ github.token }}", "ACTIONS_RUNTIME_TOKEN": "caller-run"}, inherited.workflowCallSecrets) assert.Equal(t, map[string]string{"token": "${{ github.token }}", "GITHUB_TOKEN": "github-token", "GITEA_TOKEN": "gitea-token", "ACTIONS_RUNTIME_TOKEN": "caller-run"}, inherited.workflowCallSecrets)
assert.Equal(t, "${{ github.token }}:", resolve("override", callee).ExprEval.InterpolateName(t.Context(), "${{ secrets.GITHUB_TOKEN }}:${{ secrets.GITEA_TOKEN }}"))
middle, err := model.ReadWorkflow(strings.NewReader("on: workflow_call\njobs:\n test: {uses: ./reuse.yml}\n"))
require.NoError(t, err)
nested, err := (&runnerImpl{config: config, caller: &caller{runContext: resolve("override", middle)}}).newRunContext(t.Context(), &model.Run{Workflow: callee, JobID: "test"}, nil)
require.NoError(t, err)
assert.Equal(t, "github-token:gitea-token", nested.ExprEval.InterpolateName(t.Context(), "${{ secrets.GITHUB_TOKEN }}:${{ secrets.GITEA_TOKEN }}"))
} }
func TestJobNameMasksSecrets(t *testing.T) { func TestJobNameMasksSecrets(t *testing.T) {
+10 -8
View File
@@ -44,7 +44,11 @@ func (rc *RunContext) runJobHook(ctx context.Context, hookPath, name string) err
rc.CurrentStep = "" rc.CurrentStep = ""
defer func() { rc.CurrentStep = previousStep }() defer func() { rc.CurrentStep = previousStep }()
cmd, shell := hookCommand(hookPath) env := rc.mergeEnv(rc.defaultEnv, rc.containerSpec.Env, rc.GetEnv())
rc.withGithubEnv(ctx, rc.getGithubContext(ctx), env)
rc.ApplyExtraPath(ctx, &env)
cmd, shell := hookCommand(hookPath, func(preferred, fallback string) string { return rc.shellOrFallback(ctx, env, preferred, fallback) })
rawLogger := common.Logger(ctx).With(rawOutputField, true) rawLogger := common.Logger(ctx).With(rawOutputField, true)
rawLogger.Infof("A %s hook has been configured by the runner administrator", name) rawLogger.Infof("A %s hook has been configured by the runner administrator", name)
rawLogger.Infof("::group::Run '%s'", EscapeCommandData(hookPath)) rawLogger.Infof("::group::Run '%s'", EscapeCommandData(hookPath))
@@ -53,10 +57,6 @@ func (rc *RunContext) runJobHook(ctx context.Context, hookPath, name string) err
} }
rawLogger.Infof("::endgroup::") rawLogger.Infof("::endgroup::")
env := rc.mergeEnv(rc.caEnv, rc.containerSpec.Env, rc.GetEnv())
rc.withGithubEnv(ctx, rc.getGithubContext(ctx), env)
rc.ApplyExtraPath(ctx, &env)
err := rc.setupHookFileCommands(ctx, env) err := rc.setupHookFileCommands(ctx, env)
if err == nil { if err == nil {
err = rc.runWithCommands(ctx, env, func(ctx context.Context) error { err = rc.runWithCommands(ctx, env, func(ctx context.Context) error {
@@ -104,12 +104,14 @@ func (rc *RunContext) processHookFileCommands(ctx context.Context) error {
// gives `run:` steps — a hook sets its own. See docs/adrs/1751-runner-job-hooks.md there. // gives `run:` steps — a hook sets its own. See docs/adrs/1751-runner-job-hooks.md there.
// The second return value is how the invocation is shown in the log, empty when the file is // The second return value is how the invocation is shown in the log, empty when the file is
// executed directly. // executed directly.
func hookCommand(hookPath string) (cmd []string, shell string) { func hookCommand(hookPath string, shellOrFallback func(preferred, fallback string) string) (cmd []string, shell string) {
switch strings.ToLower(path.Ext(hookPath)) { switch strings.ToLower(path.Ext(hookPath)) {
case ".sh": case ".sh":
return []string{"bash", "-e", hookPath}, "bash -e {0}" shellName := shellOrFallback("bash", "sh")
return []string{shellName, "-e", hookPath}, shellName + " -e {0}"
case ".ps1": case ".ps1":
return []string{"pwsh", "-command", ". '" + expressionStringEscape(hookPath) + "'"}, `pwsh -command ". '{0}'"` shellName := shellOrFallback("pwsh", "powershell")
return []string{shellName, "-command", ". '" + expressionStringEscape(hookPath) + "'"}, shellName + ` -command ". '{0}'"`
default: default:
return []string{hookPath}, "" return []string{hookPath}, ""
} }
+18 -14
View File
@@ -71,11 +71,6 @@ func (c *hookContainer) UpdateFromEnv(_ string, env *map[string]string) common.E
} }
} }
func (c *hookContainer) ExecOutput(_ctx context.Context, command []string) (io.ReadCloser, error) {
c.cmd = command
return io.NopCloser(bytes.NewBufferString(c.output)), c.err
}
func (c *hookContainer) GetContainerArchive(context.Context, string) (io.ReadCloser, error) { func (c *hookContainer) GetContainerArchive(context.Context, string) (io.ReadCloser, error) {
return io.NopCloser(bytes.NewReader(c.pathTar)), nil return io.NopCloser(bytes.NewReader(c.pathTar)), nil
} }
@@ -230,7 +225,7 @@ func TestRunJobHook(t *testing.T) {
rc, ctx := newHookRunContext(jobContainer, &Config{JobStartedHook: "/hooks/started.sh"}) rc, ctx := newHookRunContext(jobContainer, &Config{JobStartedHook: "/hooks/started.sh"})
require.ErrorContains(t, rc.runJobStartedHook(ctx), "boom") require.ErrorContains(t, rc.runJobStartedHook(ctx), "boom")
assert.Nil(t, jobContainer.cmd) assert.NotContains(t, jobContainer.cmd, "/hooks/started.sh")
assert.NotContains(t, rc.Env, "STALE") assert.NotContains(t, rc.Env, "STALE")
}) })
@@ -247,17 +242,26 @@ func TestRunJobHook(t *testing.T) {
// actions/runner deliberately runs a hook without the flags it gives `run:` steps, and an // actions/runner deliberately runs a hook without the flags it gives `run:` steps, and an
// executable without a known extension speaks for itself through its shebang. // executable without a known extension speaks for itself through its shebang.
func TestHookCommand(t *testing.T) { func TestHookCommand(t *testing.T) {
for hookPath, want := range map[string]struct { for _, tc := range []struct {
hookPath string
hasShell bool
cmd []string cmd []string
shell string shell string
}{ }{
"/hooks/started.sh": {[]string{"bash", "-e", "/hooks/started.sh"}, "bash -e {0}"}, {"/hooks/started.sh", true, []string{"bash", "-e", "/hooks/started.sh"}, "bash -e {0}"},
"/hooks/started.PS1": {[]string{"pwsh", "-command", ". '/hooks/started.PS1'"}, `pwsh -command ". '{0}'"`}, {"/hooks/started.sh", false, []string{"sh", "-e", "/hooks/started.sh"}, "sh -e {0}"},
"/hooks/started": {[]string{"/hooks/started"}, ""}, {"/hooks/started.PS1", true, []string{"pwsh", "-command", ". '/hooks/started.PS1'"}, `pwsh -command ". '{0}'"`},
`C:\hooks\O'Brien\started.ps1`: {[]string{"pwsh", "-command", `. 'C:\hooks\O''Brien\started.ps1'`}, `pwsh -command ". '{0}'"`}, {"/hooks/started.PS1", false, []string{"powershell", "-command", ". '/hooks/started.PS1'"}, `powershell -command ". '{0}'"`},
{"/hooks/started", false, []string{"/hooks/started"}, ""},
{`C:\hooks\O'Brien\started.ps1`, true, []string{"pwsh", "-command", `. 'C:\hooks\O''Brien\started.ps1'`}, `pwsh -command ". '{0}'"`},
} { } {
cmd, shell := hookCommand(hookPath) cmd, shell := hookCommand(tc.hookPath, func(preferred, fallback string) string {
assert.Equal(t, want.cmd, cmd, hookPath) if tc.hasShell {
assert.Equal(t, want.shell, shell, hookPath) return preferred
}
return fallback
})
assert.Equal(t, tc.cmd, cmd, tc.hookPath)
assert.Equal(t, tc.shell, shell, tc.hookPath)
} }
} }
+8 -3
View File
@@ -165,6 +165,10 @@ func setReusedWorkflowCallerResult(rc *RunContext, runner *runnerImpl) common.Ex
hasFailure = true hasFailure = true
} }
} }
if err := setJobOutputs(ctx, rc); err != nil { // a bad output fails this job, as for ordinary jobs
common.Logger(ctx).Errorf("##[error]%s", EscapeCommandData(err.Error()))
hasFailure = true
}
reusedWorkflowJobResult := "success" reusedWorkflowJobResult := "success"
reusedWorkflowJobResultMessage := "succeeded" reusedWorkflowJobResultMessage := "succeeded"
@@ -173,14 +177,15 @@ func setReusedWorkflowCallerResult(rc *RunContext, runner *runnerImpl) common.Ex
reusedWorkflowJobResultMessage = "failed" reusedWorkflowJobResultMessage = "failed"
} }
if rc.caller != nil {
rc.caller.setReusedWorkflowJobResult(rc.Run.JobID, reusedWorkflowJobResult)
} else {
// Serialize this shared Job.Result write against the other matrix combos // Serialize this shared Job.Result write against the other matrix combos
// and setJobResult (same lockJob key). // and setJobResult (same lockJob key).
unlock := lockJob(rc.Run.Job()) unlock := lockJob(rc.Run.Job())
rc.result(reusedWorkflowJobResult) rc.result(reusedWorkflowJobResult)
unlock() unlock()
if rc.caller != nil {
rc.caller.setReusedWorkflowJobResult(rc.Run.JobID, reusedWorkflowJobResult)
} else {
common.Logger(ctx).With("jobResult", reusedWorkflowJobResult).Infof("Job %s", reusedWorkflowJobResultMessage) common.Logger(ctx).With("jobResult", reusedWorkflowJobResult).Infof("Job %s", reusedWorkflowJobResultMessage)
} }
Loaded 50 of 135 files, more files were not shown because too many files have changed in this diff. Show more