mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-17 13:23:43 +00:00
Compare commits
23
Commits
bb6d793cb9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e4c8b6b78 | ||
|
|
1f2ea1b83a | ||
|
|
891f3fde38 | ||
|
|
4f59e3e418 | ||
|
|
c2046d597c | ||
|
|
645b17de72 | ||
|
|
0dfec377d2 | ||
|
|
b5305c6785 | ||
|
|
a021d3139d | ||
|
|
84c0fcd1fa | ||
|
|
c59caa9689 | ||
|
|
85d007c47f | ||
|
|
d34e4cf11a | ||
|
|
8e999cd039 | ||
|
|
cd748053b0 | ||
|
|
9bb72bbe5c | ||
|
|
79faf5e55d | ||
|
|
993389d428 | ||
|
|
db76fd5159 | ||
|
|
c8b16f4792 | ||
|
|
02446620df | ||
|
|
8c8950d9ef | ||
|
|
b88d111cc5 |
No files matched your search
@@ -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 }}
|
||||||
|
|||||||
@@ -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 }}
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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.*")
|
||||||
|
|||||||
@@ -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` checks out a repository without downloading `actions/checkout` or needing 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.
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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/*")
|
||||||
|
|||||||
@@ -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()})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"}}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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"},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -14,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"
|
||||||
|
|
||||||
@@ -23,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
|
||||||
|
|
||||||
@@ -148,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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,7 +38,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})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -95,15 +95,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)
|
||||||
}
|
}
|
||||||
+27
-20
@@ -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 {
|
||||||
@@ -191,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,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" {
|
||||||
@@ -373,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -861,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 {
|
||||||
@@ -906,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")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -938,10 +941,7 @@ func (cr *containerReference) copyDir(dstPath, srcPath string, useGitIgnore, ski
|
|||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
extractionRoot := "/"
|
extractionRoot := cr.extractionRoot(dstPath)
|
||||||
if actPath := cr.GetActPath(); strings.HasPrefix(dstPath+"/", actPath+"/") {
|
|
||||||
extractionRoot = actPath // keeps tar entries from crossing the image's /var/run symlink
|
|
||||||
}
|
|
||||||
if err := writeDirTar(ctx, tarFile, path.Join("/", strings.TrimPrefix(dstPath, extractionRoot)), srcPath, useGitIgnore, skipGitDir, cr.UID, cr.GID, cr.markExecutable(ctx)); err != nil {
|
if err := writeDirTar(ctx, tarFile, path.Join("/", strings.TrimPrefix(dstPath, extractionRoot)), srcPath, useGitIgnore, skipGitDir, cr.UID, cr.GID, cr.markExecutable(ctx)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -954,6 +954,13 @@ func (cr *containerReference) copyDir(dstPath, srcPath string, useGitIgnore, ski
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cr *containerReference) extractionRoot(dstPath string) string {
|
||||||
|
if actPath := cr.GetActPath(); strings.HasPrefix(dstPath+"/", actPath+"/") {
|
||||||
|
return actPath // keeps tar entries from crossing the image's /var/run symlink
|
||||||
|
}
|
||||||
|
return "/"
|
||||||
|
}
|
||||||
|
|
||||||
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 == "" {
|
||||||
@@ -1046,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
|
||||||
|
|||||||
@@ -45,14 +45,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 +63,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 {
|
||||||
@@ -122,6 +127,11 @@ func (m *mockDockerClient) CopyToContainer(ctx context.Context, id string, optio
|
|||||||
return args.Get(0).(mobyclient.CopyToContainerResult), args.Error(1)
|
return args.Get(0).(mobyclient.CopyToContainerResult), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockDockerClient) ContainerStatPath(ctx context.Context, id string, options mobyclient.ContainerStatPathOptions) (mobyclient.ContainerStatPathResult, error) {
|
||||||
|
args := m.Called(ctx, id, options)
|
||||||
|
return args.Get(0).(mobyclient.ContainerStatPathResult), args.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mockDockerClient) ContainerInspect(ctx context.Context, id string, opts mobyclient.ContainerInspectOptions) (mobyclient.ContainerInspectResult, error) {
|
func (m *mockDockerClient) ContainerInspect(ctx context.Context, id string, opts mobyclient.ContainerInspectOptions) (mobyclient.ContainerInspectResult, error) {
|
||||||
args := m.Called(ctx, id, opts)
|
args := m.Called(ctx, id, opts)
|
||||||
return args.Get(0).(mobyclient.ContainerInspectResult), args.Error(1)
|
return args.Get(0).(mobyclient.ContainerInspectResult), args.Error(1)
|
||||||
@@ -351,6 +361,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)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ package container
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
|
||||||
"cmp"
|
"cmp"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -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
|
||||||
@@ -117,17 +113,24 @@ func (e *HostEnvironment) Inspect(_ context.Context) (*Info, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *HostEnvironment) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) {
|
func (e *HostEnvironment) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) {
|
||||||
buf := &bytes.Buffer{}
|
|
||||||
tw := tar.NewWriter(buf)
|
|
||||||
defer tw.Close()
|
|
||||||
srcPath = filepath.Clean(srcPath)
|
srcPath = filepath.Clean(srcPath)
|
||||||
fi, err := os.Lstat(srcPath)
|
fi, err := os.Lstat(srcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
tc := &filecollector.TarCollector{
|
reader, writer := io.Pipe()
|
||||||
TarWriter: tw,
|
go func() {
|
||||||
|
tw := tar.NewWriter(writer)
|
||||||
|
err := writeHostArchive(ctx, &filecollector.TarCollector{TarWriter: tw}, srcPath, fi)
|
||||||
|
if err == nil {
|
||||||
|
err = tw.Close()
|
||||||
}
|
}
|
||||||
|
writer.CloseWithError(err)
|
||||||
|
}()
|
||||||
|
return startedArchive(reader)
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeHostArchive(ctx context.Context, tc *filecollector.TarCollector, srcPath string, fi fs.FileInfo) error {
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
srcPrefix := srcPath
|
srcPrefix := srcPath
|
||||||
if !strings.HasSuffix(srcPrefix, string(filepath.Separator)) {
|
if !strings.HasSuffix(srcPrefix, string(filepath.Separator)) {
|
||||||
@@ -138,31 +141,22 @@ func (e *HostEnvironment) GetContainerArchive(ctx context.Context, srcPath strin
|
|||||||
SrcPrefix: srcPrefix,
|
SrcPrefix: srcPrefix,
|
||||||
Handler: tc,
|
Handler: tc,
|
||||||
}
|
}
|
||||||
err = filepath.Walk(srcPath, fc.CollectFiles(ctx))
|
return filepath.Walk(srcPath, fc.CollectFiles(ctx))
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
var f io.ReadCloser
|
var f io.ReadCloser
|
||||||
var linkname string
|
var linkname string
|
||||||
|
var err error
|
||||||
if fi.Mode()&fs.ModeSymlink != 0 {
|
if fi.Mode()&fs.ModeSymlink != 0 {
|
||||||
linkname, err = os.Readlink(srcPath)
|
if linkname, err = os.Readlink(srcPath); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
f, err = os.Open(srcPath)
|
if f, err = os.Open(srcPath); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
}
|
}
|
||||||
err := tc.WriteFile(fi.Name(), fi, linkname, f)
|
return tc.WriteFile(fi.Name(), fi, linkname, f)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return io.NopCloser(buf), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *HostEnvironment) Pull(_ bool) common.Executor {
|
func (e *HostEnvironment) Pull(_ bool) common.Executor {
|
||||||
@@ -286,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
|
||||||
@@ -438,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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,11 @@ func TestGetContainerArchive(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, expectedContent, content)
|
assert.Equal(t, expectedContent, content)
|
||||||
_, err = reader.Next()
|
_, err = reader.Next()
|
||||||
assert.ErrorIs(t, err, io.EOF)
|
require.ErrorIs(t, err, io.EOF)
|
||||||
|
require.NoError(t, archive.Close())
|
||||||
|
|
||||||
|
_, err = e.GetContainerArchive(ctx, filepath.Join(e.Path, "missing"))
|
||||||
|
assert.ErrorIs(t, err, os.ErrNotExist)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHostEnvironmentExecExitCode(t *testing.T) {
|
func TestHostEnvironmentExecExitCode(t *testing.T) {
|
||||||
@@ -154,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) {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"cmp"
|
"cmp"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
@@ -51,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
|
||||||
@@ -433,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -448,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) ||
|
||||||
@@ -573,15 +574,7 @@ func (c *kubernetesContainer) GetContainerArchive(ctx context.Context, srcPath s
|
|||||||
}
|
}
|
||||||
writer.CloseWithError(err)
|
writer.CloseWithError(err)
|
||||||
}()
|
}()
|
||||||
buffered := bufio.NewReader(reader)
|
return startedArchive(reader)
|
||||||
if _, err := buffered.Peek(1); err != nil {
|
|
||||||
reader.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return struct {
|
|
||||||
io.Reader
|
|
||||||
io.Closer
|
|
||||||
}{buffered, reader}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *kubernetesContainer) UpdateFromEnv(srcPath string, env *map[string]string) common.Executor {
|
func (c *kubernetesContainer) UpdateFromEnv(srcPath string, env *map[string]string) common.Executor {
|
||||||
@@ -591,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -309,9 +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 |"))
|
||||||
|
|
||||||
pathEnv := map[string]string{}
|
imageEnv := map[string]string{}
|
||||||
require.NoError(t, job.UpdateFromImageEnv(&pathEnv)(ctx))
|
require.NoError(t, job.UpdateFromImageEnv(&imageEnv)(ctx))
|
||||||
assert.Equal(t, path, pathEnv["PATH"])
|
assert.Equal(t, map[string]string{"PATH": path, "ImageOS": "ubuntu24-arm64"}, imageEnv)
|
||||||
|
|
||||||
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
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ package container
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -15,6 +16,19 @@ import (
|
|||||||
"gitea.com/gitea/runner/act/filecollector"
|
"gitea.com/gitea/runner/act/filecollector"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// startedArchive returns reader once its first byte arrives, so failing to start archiving errors here, not on read.
|
||||||
|
func startedArchive(reader *io.PipeReader) (io.ReadCloser, error) {
|
||||||
|
buffered := bufio.NewReader(reader)
|
||||||
|
if _, err := buffered.Peek(1); err != nil {
|
||||||
|
reader.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return struct {
|
||||||
|
io.Reader
|
||||||
|
io.Closer
|
||||||
|
}{buffered, reader}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func writeFilesTar(ctx context.Context, w io.Writer, uid, gid int, files ...*FileEntry) error {
|
func writeFilesTar(ctx context.Context, w io.Writer, uid, gid int, files ...*FileEntry) error {
|
||||||
tw := tar.NewWriter(w)
|
tw := tar.NewWriter(w)
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
|||||||
@@ -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() &&
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -99,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) {
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
@@ -68,8 +72,9 @@ func (cm *containerMock) Exec(command []string, env map[string]string, user, wor
|
|||||||
|
|
||||||
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 {
|
||||||
@@ -82,3 +87,8 @@ func (cm *containerMock) Inspect(ctx context.Context) (*container.Info, error) {
|
|||||||
err, _ := args.Get(1).(error)
|
err, _ := args.Get(1).(error)
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cm *containerMock) ReplaceLogWriter(stdout, stderr io.Writer) (io.Writer, io.Writer) {
|
||||||
|
args := cm.Called(stdout, stderr)
|
||||||
|
return args.Get(0).(io.Writer), args.Get(1).(io.Writer)
|
||||||
|
}
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -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}, ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,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")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -242,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -213,3 +214,17 @@ func gitMust(t *testing.T, dir string, args ...string) {
|
|||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
require.NoError(t, err, "git %v: %s", args, string(out))
|
require.NoError(t, err, "git %v: %s", args, string(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetReusedWorkflowCallerResultFailsOnBadOutputs(t *testing.T) {
|
||||||
|
callerWorkflow, err := model.ReadWorkflow(strings.NewReader("jobs:\n call: {uses: ./reuse.yml}\n"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
called, err := model.ReadWorkflow(strings.NewReader("on:\n workflow_call:\n outputs:\n bad: {value: \"${{ fromJSON('not-json') }}\"}\njobs:\n inner: {uses: ./leaf.yml}\n"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
config := &Config{PresetGitHubContext: &model.GithubContext{}}
|
||||||
|
parent, err := (&runnerImpl{config: config}).newRunContext(t.Context(), &model.Run{Workflow: callerWorkflow, JobID: "call"}, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
rc, err := (&runnerImpl{config: config, caller: &caller{runContext: parent, reusedWorkflowJobResults: map[string]string{}}}).newRunContext(t.Context(), &model.Run{Workflow: called, JobID: "inner"}, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, setReusedWorkflowCallerResult(rc, &runnerImpl{caller: &caller{reusedWorkflowJobResults: map[string]string{"leaf": "success"}}})(t.Context()))
|
||||||
|
require.Equal(t, "failure", rc.Run.Job().Result)
|
||||||
|
}
|
||||||
+108
-26
@@ -30,6 +30,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/common"
|
"gitea.com/gitea/runner/act/common"
|
||||||
|
"gitea.com/gitea/runner/act/common/logging"
|
||||||
"gitea.com/gitea/runner/act/container"
|
"gitea.com/gitea/runner/act/container"
|
||||||
"gitea.com/gitea/runner/act/ghcontext"
|
"gitea.com/gitea/runner/act/ghcontext"
|
||||||
"gitea.com/gitea/runner/internal/pkg/lock"
|
"gitea.com/gitea/runner/internal/pkg/lock"
|
||||||
@@ -68,13 +69,14 @@ type RunContext struct {
|
|||||||
kubernetes bool
|
kubernetes bool
|
||||||
containerSpec model.ContainerSpec // container:, resolved once with platformImage
|
containerSpec model.ContainerSpec // container:, resolved once with platformImage
|
||||||
containerEnv yaml.Node // container.env of the kept containerSpec, decoded once the job env resolves
|
containerEnv yaml.Node // container.env of the kept containerSpec, decoded once the job env resolves
|
||||||
caEnv map[string]string // NODE_EXTRA_CA_CERTS for the runner CA, beneath any env the job and its image set
|
defaultEnv map[string]string // ImageOS and the runner CA's NODE_EXTRA_CA_CERTS, beneath any env the job sets
|
||||||
JobName string
|
JobName string
|
||||||
ActionPath string
|
ActionPath string
|
||||||
Parent *RunContext
|
Parent *RunContext
|
||||||
actionInputs map[string]any // inputs of the composite action this runs, nil for a job
|
actionInputs map[string]any // inputs of the composite action this runs, nil for a job
|
||||||
Masks []string
|
Masks []string
|
||||||
cleanUpJobContainer common.Executor
|
cleanUpJobContainer common.Executor
|
||||||
|
taskWorkspace string
|
||||||
deferVolumeCleanup func(common.Executor)
|
deferVolumeCleanup func(common.Executor)
|
||||||
caller *caller // job calling this RunContext (reusable workflows)
|
caller *caller // job calling this RunContext (reusable workflows)
|
||||||
workflowCallInputs map[string]any // the caller's with:, resolved once by resolveWorkflowCall
|
workflowCallInputs map[string]any // the caller's with:, resolved once by resolveWorkflowCall
|
||||||
@@ -101,6 +103,7 @@ type RunContext struct {
|
|||||||
// getJobContext report the "cancelled" status so cancelled()/always() evaluate the way
|
// getJobContext report the "cancelled" status so cancelled()/always() evaluate the way
|
||||||
// GitHub Actions does, letting cleanup and always() steps run while normal steps skip.
|
// GitHub Actions does, letting cleanup and always() steps run while normal steps skip.
|
||||||
jobCancelled bool
|
jobCancelled bool
|
||||||
|
jobTimedOut bool
|
||||||
// jobFailed records failures outside normal main-step results, such as action pre-step
|
// jobFailed records failures outside normal main-step results, such as action pre-step
|
||||||
// failures. Those failures must still make success() false and failure() true for later
|
// failures. Those failures must still make success() false and failure() true for later
|
||||||
// main-step if evaluation.
|
// main-step if evaluation.
|
||||||
@@ -158,12 +161,13 @@ func (rc *RunContext) markFailed() {
|
|||||||
// markInterrupted records the job's interruption status from a context error so later step `if` evaluations and the job result observe it,
|
// markInterrupted records the job's interruption status from a context error so later step `if` evaluations and the job result observe it,
|
||||||
// keeping the timeout path symmetric with the cancel path:
|
// keeping the timeout path symmetric with the cancel path:
|
||||||
// - context.Canceled (server cancel) marks the job cancelled, matching GitHub's "only always()/cancelled() run on cancel".
|
// - context.Canceled (server cancel) marks the job cancelled, matching GitHub's "only always()/cancelled() run on cancel".
|
||||||
// - context.DeadlineExceeded (job timeout-minutes) marks the job failed, matching the "Timeout -> FAILURE" reporting semantics.
|
// - context.DeadlineExceeded (job timeout-minutes) evaluates later steps as cancelled like GitHub, but reports the job failed.
|
||||||
func (rc *RunContext) markInterrupted(err error) {
|
func (rc *RunContext) markInterrupted(err error) {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, context.Canceled):
|
case errors.Is(err, context.Canceled):
|
||||||
rc.markCancelled()
|
rc.markCancelled()
|
||||||
case errors.Is(err, context.DeadlineExceeded):
|
case errors.Is(err, context.DeadlineExceeded):
|
||||||
|
rc.jobTimedOut = true
|
||||||
rc.markFailed()
|
rc.markFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,7 +275,7 @@ func (rc *RunContext) validVolumes() []string {
|
|||||||
volumes = append(volumes, hostEnv.Path, hostEnv.GetActPath())
|
volumes = append(volumes, hostEnv.Path, hostEnv.GetActPath())
|
||||||
}
|
}
|
||||||
if rc.Config.SharedToolCache {
|
if rc.Config.SharedToolCache {
|
||||||
volumes = append(volumes, sharedToolCacheVolume)
|
volumes = append(volumes, rc.toolCacheVolume())
|
||||||
}
|
}
|
||||||
if rc.Config.BindWorkdir {
|
if rc.Config.BindWorkdir {
|
||||||
volumes = append(volumes, rc.Config.Workdir, rc.workdirMountRoot())
|
volumes = append(volumes, rc.Config.Workdir, rc.workdirMountRoot())
|
||||||
@@ -331,6 +335,13 @@ func (rc *RunContext) startDockerProxy(ctx context.Context) {
|
|||||||
rc.dockerProxy = container.NewDockerProxy(ctx, rc.jobContainerName())
|
rc.dockerProxy = container.NewDockerProxy(ctx, rc.jobContainerName())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *RunContext) toolCacheVolume() string {
|
||||||
|
if rc.Config.ToolCacheSlot == "" {
|
||||||
|
return sharedToolCacheVolume
|
||||||
|
}
|
||||||
|
return sharedToolCacheVolume + "-" + rc.Config.ToolCacheSlot
|
||||||
|
}
|
||||||
|
|
||||||
// toolCache returns the tool cache path the job sees, relocatable through RUNNER_TOOL_CACHE.
|
// toolCache returns the tool cache path the job sees, relocatable through RUNNER_TOOL_CACHE.
|
||||||
func (rc *RunContext) toolCache(fallback string) string {
|
func (rc *RunContext) toolCache(fallback string) string {
|
||||||
return cmp.Or(rc.GetEnv()["RUNNER_TOOL_CACHE"], fallback)
|
return cmp.Or(rc.GetEnv()["RUNNER_TOOL_CACHE"], fallback)
|
||||||
@@ -378,8 +389,8 @@ func splitVolumes(specs []string) ([]string, map[string]string, map[string]bool)
|
|||||||
return binds, mounts, targets
|
return binds, mounts, targets
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the binds and mounts for the container, resolving paths as appopriate
|
// Returns the container's binds, mounts and bound task workspace, resolving paths as appropriate
|
||||||
func (rc *RunContext) GetBindsAndMounts(ctx context.Context) ([]string, map[string]string) {
|
func (rc *RunContext) GetBindsAndMounts(ctx context.Context) ([]string, map[string]string, string) {
|
||||||
name := rc.jobContainerName()
|
name := rc.jobContainerName()
|
||||||
ext := container.LinuxContainerEnvironmentExtensions{}
|
ext := container.LinuxContainerEnvironmentExtensions{}
|
||||||
|
|
||||||
@@ -391,7 +402,7 @@ func (rc *RunContext) GetBindsAndMounts(ctx context.Context) ([]string, map[stri
|
|||||||
}
|
}
|
||||||
if rc.Config.SharedToolCache {
|
if rc.Config.SharedToolCache {
|
||||||
if toolCache := rc.toolCache(container.DefaultToolCache); !claimed[toolCache] {
|
if toolCache := rc.toolCache(container.DefaultToolCache); !claimed[toolCache] {
|
||||||
mounts[sharedToolCacheVolume] = toolCache
|
mounts[rc.toolCacheVolume()] = toolCache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if hostEnv, ok := rc.JobContainer.(*container.HostEnvironment); ok {
|
if hostEnv, ok := rc.JobContainer.(*container.HostEnvironment); ok {
|
||||||
@@ -399,12 +410,16 @@ func (rc *RunContext) GetBindsAndMounts(ctx context.Context) ([]string, map[stri
|
|||||||
}
|
}
|
||||||
mounts[name+"-env"] = ext.GetActPath() // runner-internal, never overridable
|
mounts[name+"-env"] = ext.GetActPath() // runner-internal, never overridable
|
||||||
|
|
||||||
|
taskWorkspace := ""
|
||||||
if workdir := ext.ToContainerPath(rc.Config.Workdir); !claimed[workdir] {
|
if workdir := ext.ToContainerPath(rc.Config.Workdir); !claimed[workdir] {
|
||||||
source := rc.workdirMountRoot()
|
source := rc.workdirMountRoot()
|
||||||
target := ext.ToContainerPath(source)
|
target := ext.ToContainerPath(source)
|
||||||
if claimed[target] {
|
if claimed[target] {
|
||||||
source, target = rc.Config.Workdir, workdir
|
source, target = rc.Config.Workdir, workdir
|
||||||
}
|
}
|
||||||
|
if rc.Config.BindWorkdir && rc.Config.PresetGitHubContext != nil {
|
||||||
|
taskWorkspace = target
|
||||||
|
}
|
||||||
if rc.Config.BindWorkdir {
|
if rc.Config.BindWorkdir {
|
||||||
bindModifiers := ""
|
bindModifiers := ""
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
@@ -419,7 +434,7 @@ func (rc *RunContext) GetBindsAndMounts(ctx context.Context) ([]string, map[stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return binds, mounts
|
return binds, mounts, taskWorkspace
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RunContext) startHostEnvironment() common.Executor {
|
func (rc *RunContext) startHostEnvironment() common.Executor {
|
||||||
@@ -447,6 +462,10 @@ func (rc *RunContext) startHostEnvironment() common.Executor {
|
|||||||
toolCacheParent = cacheDir
|
toolCacheParent = cacheDir
|
||||||
}
|
}
|
||||||
toolCache := rc.toolCache(filepath.Join(toolCacheParent, "tool_cache"))
|
toolCache := rc.toolCache(filepath.Join(toolCacheParent, "tool_cache"))
|
||||||
|
if rc.Config.ToolCacheSlot != "" {
|
||||||
|
toolCache = filepath.Join(toolCache, rc.Config.ToolCacheSlot)
|
||||||
|
rc.Env["RUNNER_TOOL_CACHE"] = toolCache // overrides a RUNNER_TOOL_CACHE the slots would otherwise share
|
||||||
|
}
|
||||||
if err := os.MkdirAll(toolCache, 0o777); err != nil {
|
if err := os.MkdirAll(toolCache, 0o777); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -455,7 +474,6 @@ func (rc *RunContext) startHostEnvironment() common.Executor {
|
|||||||
TmpDir: runnerTmp,
|
TmpDir: runnerTmp,
|
||||||
ToolCache: toolCache,
|
ToolCache: toolCache,
|
||||||
Workdir: rc.Config.Workdir,
|
Workdir: rc.Config.Workdir,
|
||||||
CleanWorkdir: rc.Config.CleanWorkdir,
|
|
||||||
ActPath: actPath,
|
ActPath: actPath,
|
||||||
Root: miscpath,
|
Root: miscpath,
|
||||||
TrackingID: rc.runnerTrackingID(),
|
TrackingID: rc.runnerTrackingID(),
|
||||||
@@ -638,6 +656,11 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||||||
rc.serviceContainers = append(rc.serviceContainers, &serviceContainer{name: serviceID, image: input.Image, container: newContainer(input)})
|
rc.serviceContainers = append(rc.serviceContainers, &serviceContainer{name: serviceID, image: input.Image, container: newContainer(input)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exposedPorts, portBindings, err := nat.ParsePortSpecs(rc.containerSpec.Ports)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse container ports: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
ext := container.LinuxContainerEnvironmentExtensions{}
|
ext := container.LinuxContainerEnvironmentExtensions{}
|
||||||
containerInput := &container.NewContainerInput{
|
containerInput := &container.NewContainerInput{
|
||||||
Entrypoint: []string{"sleep", strconv.FormatInt(int64(rc.Config.ContainerMaxLifetime.Round(time.Second).Seconds()), 10)},
|
Entrypoint: []string{"sleep", strconv.FormatInt(int64(rc.Config.ContainerMaxLifetime.Round(time.Second).Seconds()), 10)},
|
||||||
@@ -649,6 +672,8 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||||||
Env: envList,
|
Env: envList,
|
||||||
NetworkMode: networkName,
|
NetworkMode: networkName,
|
||||||
NetworkAliases: []string{rc.Name},
|
NetworkAliases: []string{rc.Name},
|
||||||
|
ExposedPorts: exposedPorts,
|
||||||
|
PortBindings: portBindings,
|
||||||
Stdout: logWriter,
|
Stdout: logWriter,
|
||||||
Stderr: logWriter,
|
Stderr: logWriter,
|
||||||
Privileged: rc.Config.Privileged,
|
Privileged: rc.Config.Privileged,
|
||||||
@@ -672,7 +697,8 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rc.startDockerProxy(ctx)
|
rc.startDockerProxy(ctx)
|
||||||
containerInput.Binds, containerInput.Mounts = rc.GetBindsAndMounts(ctx)
|
var taskWorkspace string
|
||||||
|
containerInput.Binds, containerInput.Mounts, taskWorkspace = rc.GetBindsAndMounts(ctx)
|
||||||
containerInput.ValidVolumes = rc.validVolumes()
|
containerInput.ValidVolumes = rc.validVolumes()
|
||||||
|
|
||||||
rc.jobNetworkName = networkName
|
rc.jobNetworkName = networkName
|
||||||
@@ -687,6 +713,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||||||
func(ctx context.Context) error { return rc.createJobVolumes(ctx, containerInput.Mounts) },
|
func(ctx context.Context) error { return rc.createJobVolumes(ctx, containerInput.Mounts) },
|
||||||
rc.JobContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop),
|
rc.JobContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop),
|
||||||
rc.JobContainer.Start(false),
|
rc.JobContainer.Start(false),
|
||||||
|
func(context.Context) error { rc.taskWorkspace = taskWorkspace; return nil },
|
||||||
rc.captureJobContainerInfo(),
|
rc.captureJobContainerInfo(),
|
||||||
rc.copyWorkflowFiles(),
|
rc.copyWorkflowFiles(),
|
||||||
rc.waitForServiceContainers(),
|
rc.waitForServiceContainers(),
|
||||||
@@ -801,7 +828,10 @@ func (rc *RunContext) cleanupJobResources(networkName string, createAndDeleteNet
|
|||||||
errs := []error{rc.closeDockerProxy(ctx)}
|
errs := []error{rc.closeDockerProxy(ctx)}
|
||||||
var containers []common.Executor
|
var containers []common.Executor
|
||||||
if rc.JobContainer != nil {
|
if rc.JobContainer != nil {
|
||||||
containers = append(containers, rc.JobContainer.Remove())
|
containers = append(containers, func(ctx context.Context) error {
|
||||||
|
rc.emptyTaskWorkspace(ctx)
|
||||||
|
return rc.JobContainer.Remove()(ctx)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if len(rc.serviceContainers) > 0 {
|
if len(rc.serviceContainers) > 0 {
|
||||||
logger.Infof("Cleaning up services for job %s", rc.JobName)
|
logger.Infof("Cleaning up services for job %s", rc.JobName)
|
||||||
@@ -831,6 +861,42 @@ func (rc *RunContext) cleanupJobResources(networkName string, createAndDeleteNet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// exits 3 unless workspace $1 is safe to empty per mountinfo $2
|
||||||
|
const emptyTaskWorkspaceScript = `case "$1" in /?*/?*) ;; *) exit 3 ;; esac
|
||||||
|
mounted=
|
||||||
|
while read -r _ _ _ _ point _; do
|
||||||
|
case "$point" in "$1") mounted=1 ;; "$1"/*) exit 3 ;; esac
|
||||||
|
done <"$2"
|
||||||
|
[ "$mounted" ] || exit 3
|
||||||
|
rm -rf "$1"/* "$1"/.[!.]* "$1"/..?*`
|
||||||
|
|
||||||
|
var runnerCanRemoveJobFiles = runtime.GOOS != "linux" || os.Geteuid() == 0 // root, or a desktop VM mapping file ownership, replaced in tests
|
||||||
|
|
||||||
|
// runs as root with root-owned PATH dirs only, skipped for called workflows sharing the workspace
|
||||||
|
func (rc *RunContext) emptyTaskWorkspace(ctx context.Context) {
|
||||||
|
if rc.taskWorkspace == "" || rc.caller != nil || runnerCanRemoveJobFiles {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
budget := 30 * time.Second
|
||||||
|
if deadline, ok := ctx.Deadline(); ok {
|
||||||
|
budget = min(budget, time.Until(deadline)/2-container.DrainGracePeriod)
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, budget)
|
||||||
|
defer cancel()
|
||||||
|
stdout, stderr := rc.JobContainer.ReplaceLogWriter(io.Discard, io.Discard)
|
||||||
|
defer rc.JobContainer.ReplaceLogWriter(stdout, stderr)
|
||||||
|
err := rc.JobContainer.Exec(
|
||||||
|
[]string{"sh", "-c", emptyTaskWorkspaceScript, "sh", rc.taskWorkspace, "/proc/self/mountinfo"},
|
||||||
|
map[string]string{"PATH": "/usr/sbin:/usr/bin:/sbin:/bin"}, "0", "/",
|
||||||
|
)(common.WithLogger(ctx, logging.New(logging.DiscardHandler)))
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, container.ExitCodeError(3)):
|
||||||
|
logging.Infof("not emptying workspace %s of %s: under two levels deep, not a mountpoint as given, or a mount below it", rc.taskWorkspace, rc.jobContainerName())
|
||||||
|
case err != nil:
|
||||||
|
logging.Infof("could not empty workspace %s of %s: %v", rc.taskWorkspace, rc.jobContainerName(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func runAll(ctx context.Context, executors []common.Executor) error {
|
func runAll(ctx context.Context, executors []common.Executor) error {
|
||||||
errs := make([]error, len(executors))
|
errs := make([]error, len(executors))
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
@@ -1152,6 +1218,24 @@ func (svc *serviceContainer) healthOutputSuffix() string {
|
|||||||
|
|
||||||
func (rc *RunContext) copyWorkflowFiles() common.Executor {
|
func (rc *RunContext) copyWorkflowFiles() common.Executor {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
|
imageEnv := map[string]string{}
|
||||||
|
imageEnvErr := rc.JobContainer.UpdateFromImageEnv(&imageEnv)(ctx)
|
||||||
|
rc.defaultEnv = map[string]string{}
|
||||||
|
imageOS, set := imageEnv["ImageOS"]
|
||||||
|
if !set {
|
||||||
|
if !rc.kubernetes { // a pod reports its release through its startup probe
|
||||||
|
for _, osReleasePath := range []string{"/usr/lib/os-release", "/etc/os-release"} { // the archive skips symlinks, as /etc's is on Ubuntu
|
||||||
|
if osRelease, ok := readSingleFileFromContainerArchive(ctx, rc.JobContainer, osReleasePath, 64<<10); ok {
|
||||||
|
imageOS = container.ImageOSFromOSRelease(string(osRelease))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageOS = cmp.Or(imageOS, rc.imageOS(ctx))
|
||||||
|
}
|
||||||
|
if set || imageOS != "" {
|
||||||
|
rc.defaultEnv["ImageOS"] = imageOS
|
||||||
|
}
|
||||||
files := []*container.FileEntry{
|
files := []*container.FileEntry{
|
||||||
{Name: "workflow/event.json", Mode: 0o644, Body: rc.EventJSON},
|
{Name: "workflow/event.json", Mode: 0o644, Body: rc.EventJSON},
|
||||||
{Name: "workflow/envs.txt", Mode: 0o666},
|
{Name: "workflow/envs.txt", Mode: 0o666},
|
||||||
@@ -1162,12 +1246,11 @@ func (rc *RunContext) copyWorkflowFiles() common.Executor {
|
|||||||
return fmt.Errorf("read runner CA file: %w", err)
|
return fmt.Errorf("read runner CA file: %w", err)
|
||||||
}
|
}
|
||||||
files = append(files, &container.FileEntry{Name: "ca.crt", Mode: 0o644, Body: string(ca)})
|
files = append(files, &container.FileEntry{Name: "ca.crt", Mode: 0o644, Body: string(ca)})
|
||||||
imageEnv := map[string]string{}
|
if imageEnvErr != nil {
|
||||||
if err = rc.JobContainer.UpdateFromImageEnv(&imageEnv)(ctx); err != nil {
|
return imageEnvErr
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if _, set := imageEnv["NODE_EXTRA_CA_CERTS"]; !set {
|
if _, set := imageEnv["NODE_EXTRA_CA_CERTS"]; !set {
|
||||||
rc.caEnv = map[string]string{"NODE_EXTRA_CA_CERTS": rc.jobCAFile()}
|
rc.defaultEnv["NODE_EXTRA_CA_CERTS"] = rc.jobCAFile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rc.JobContainer.Copy(rc.JobContainer.GetActPath()+"/", files...)(ctx)
|
return rc.JobContainer.Copy(rc.JobContainer.GetActPath()+"/", files...)(ctx)
|
||||||
@@ -1540,7 +1623,7 @@ func (rc *RunContext) getJobContext() *model.JobContext {
|
|||||||
// A cancelled run takes precedence over success/failure so cancelled() is true and
|
// A cancelled run takes precedence over success/failure so cancelled() is true and
|
||||||
// success()/failure() are false, matching GitHub Actions: on cancellation only
|
// success()/failure() are false, matching GitHub Actions: on cancellation only
|
||||||
// always() and cancelled() steps run.
|
// always() and cancelled() steps run.
|
||||||
if job.jobCancelled {
|
if job.jobCancelled || job.jobTimedOut {
|
||||||
jobStatus = "cancelled"
|
jobStatus = "cancelled"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1577,7 +1660,7 @@ func (rc *RunContext) getRunnerContext(ctx context.Context) map[string]any {
|
|||||||
runnerContext["name"] = rc.Config.RunnerName
|
runnerContext["name"] = rc.Config.RunnerName
|
||||||
runnerContext["environment"] = "self-hosted"
|
runnerContext["environment"] = "self-hosted"
|
||||||
runnerContext["workspace"] = parentDir(rc.githubWorkspace())
|
runnerContext["workspace"] = parentDir(rc.githubWorkspace())
|
||||||
if rc.Config.RunnerDebug() {
|
if rc.topLevelRunContext().Config.RunnerDebug() { // a composite's config has no secrets
|
||||||
runnerContext["debug"] = "1"
|
runnerContext["debug"] = "1"
|
||||||
}
|
}
|
||||||
return runnerContext
|
return runnerContext
|
||||||
@@ -1621,7 +1704,9 @@ func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext
|
|||||||
Workspace: rc.githubWorkspace(),
|
Workspace: rc.githubWorkspace(),
|
||||||
}
|
}
|
||||||
if rc.JobContainer != nil {
|
if rc.JobContainer != nil {
|
||||||
ghc.EventPath = rc.JobContainer.GetActPath() + "/workflow/event.json"
|
actPath := rc.JobContainer.GetActPath()
|
||||||
|
ghc.EventPath = actPath + "/workflow/event.json"
|
||||||
|
ghc.Env, ghc.Path = container.JoinPath(actPath, envFileCommand), container.JoinPath(actPath, pathFileCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
ghc.RunnerTrackingID = rc.runnerTrackingID()
|
ghc.RunnerTrackingID = rc.runnerTrackingID()
|
||||||
@@ -1629,6 +1714,7 @@ func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext
|
|||||||
if preset := rc.Config.PresetGitHubContext; preset != nil {
|
if preset := rc.Config.PresetGitHubContext; preset != nil {
|
||||||
merged := *preset
|
merged := *preset
|
||||||
merged.Workflow, merged.Job, merged.Workspace, merged.EventPath = ghc.Workflow, ghc.Job, ghc.Workspace, ghc.EventPath
|
merged.Workflow, merged.Job, merged.Workspace, merged.EventPath = ghc.Workflow, ghc.Job, ghc.Workspace, ghc.EventPath
|
||||||
|
merged.Env, merged.Path = ghc.Env, ghc.Path
|
||||||
merged.Action, merged.ActionPath, merged.ActionRepository, merged.ActionRef = ghc.Action, ghc.ActionPath, ghc.ActionRepository, ghc.ActionRef
|
merged.Action, merged.ActionPath, merged.ActionRepository, merged.ActionRef = ghc.Action, ghc.ActionPath, ghc.ActionRepository, ghc.ActionRef
|
||||||
merged.RunnerPerflog, merged.RunnerTrackingID = ghc.RunnerPerflog, ghc.RunnerTrackingID
|
merged.RunnerPerflog, merged.RunnerTrackingID = ghc.RunnerPerflog, ghc.RunnerTrackingID
|
||||||
*ghc = merged
|
*ghc = merged
|
||||||
@@ -1722,7 +1808,7 @@ func aliasGiteaEnv(env map[string]string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubContext, env map[string]string) {
|
func (rc *RunContext) withGithubEnv(_ctx context.Context, github *model.GithubContext, env map[string]string) {
|
||||||
if _, ok := env["CI"]; !ok {
|
if _, ok := env["CI"]; !ok {
|
||||||
env["CI"] = "true"
|
env["CI"] = "true"
|
||||||
}
|
}
|
||||||
@@ -1783,7 +1869,7 @@ func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubCon
|
|||||||
if workspace := parentDir(github.Workspace); workspace != "" {
|
if workspace := parentDir(github.Workspace); workspace != "" {
|
||||||
env["RUNNER_WORKSPACE"] = workspace
|
env["RUNNER_WORKSPACE"] = workspace
|
||||||
}
|
}
|
||||||
if rc.Config.RunnerDebug() {
|
if rc.topLevelRunContext().Config.RunnerDebug() {
|
||||||
env["RUNNER_DEBUG"] = "1"
|
env["RUNNER_DEBUG"] = "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1791,10 +1877,6 @@ func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubCon
|
|||||||
env["ACTIONS_RUNTIME_URL"] = cmp.Or(os.Getenv("ACTIONS_RUNTIME_URL"), "http://"+net.JoinHostPort(rc.Config.ArtifactServerAddr, rc.Config.ArtifactServerPort)+"/")
|
env["ACTIONS_RUNTIME_URL"] = cmp.Or(os.Getenv("ACTIONS_RUNTIME_URL"), "http://"+net.JoinHostPort(rc.Config.ArtifactServerAddr, rc.Config.ArtifactServerPort)+"/")
|
||||||
env["ACTIONS_RUNTIME_TOKEN"] = cmp.Or(rc.runtimeToken, os.Getenv("ACTIONS_RUNTIME_TOKEN"), "token")
|
env["ACTIONS_RUNTIME_TOKEN"] = cmp.Or(rc.runtimeToken, os.Getenv("ACTIONS_RUNTIME_TOKEN"), "token")
|
||||||
}
|
}
|
||||||
|
|
||||||
if imageOS := rc.imageOS(ctx); imageOS != "" {
|
|
||||||
env["ImageOS"] = imageOS
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parentDir returns the directory containing p, or "" when p names no parent. Both
|
// parentDir returns the directory containing p, or "" when p names no parent. Both
|
||||||
@@ -1811,7 +1893,7 @@ func parentDir(p string) string {
|
|||||||
// from another. The resolved image tag is preferred over the runs-on label because it
|
// from another. The resolved image tag is preferred over the runs-on label because it
|
||||||
// still names a release when the label is a rolling one such as ubuntu-latest.
|
// still names a release when the label is a rolling one such as ubuntu-latest.
|
||||||
func (rc *RunContext) imageOS(ctx context.Context) string {
|
func (rc *RunContext) imageOS(ctx context.Context) string {
|
||||||
if rc.Run.Job().RunsOn() == nil {
|
if job := rc.Run.Job(); job == nil || job.RunsOn() == nil {
|
||||||
return "" // a composite action runs on a synthetic job without runs-on
|
return "" // a composite action runs on a synthetic job without runs-on
|
||||||
}
|
}
|
||||||
if imageOS := imageOSFromImage(rc.platformImage); imageOS != "" {
|
if imageOS := imageOSFromImage(rc.platformImage); imageOS != "" {
|
||||||
@@ -1820,8 +1902,8 @@ func (rc *RunContext) imageOS(ctx context.Context) string {
|
|||||||
|
|
||||||
for _, platformName := range slices.Backward(rc.runsOnPlatformNames(ctx)) {
|
for _, platformName := range slices.Backward(rc.runsOnPlatformNames(ctx)) {
|
||||||
if platformName == "ubuntu-latest" {
|
if platformName == "ubuntu-latest" {
|
||||||
// Rolling label whose image names no release either, so keep the historical value.
|
// Rolling label whose image names no release either, so report GitHub's current ubuntu-latest.
|
||||||
return "ubuntu20"
|
return "ubuntu24"
|
||||||
} else if platformName != "" {
|
} else if platformName != "" {
|
||||||
return strings.SplitN(strings.Replace(platformName, `-`, ``, 1), `.`, 2)[0]
|
return strings.SplitN(strings.Replace(platformName, `-`, ``, 1), `.`, 2)[0]
|
||||||
}
|
}
|
||||||
|
|||||||
+210
-16
@@ -16,6 +16,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"slices"
|
"slices"
|
||||||
@@ -167,6 +168,14 @@ func (fakeContainer) Copy(string, ...*container.FileEntry) common.Executor {
|
|||||||
return func(context.Context) error { return nil }
|
return func(context.Context) error { return nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fakeContainer) UpdateFromImageEnv(_env *map[string]string) common.Executor {
|
||||||
|
return noopExecutor
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fakeContainer) GetContainerArchive(_ctx context.Context, _srcPath string) (io.ReadCloser, error) {
|
||||||
|
return nil, os.ErrNotExist
|
||||||
|
}
|
||||||
|
|
||||||
func (fakeContainer) Inspect(context.Context) (*container.Info, error) {
|
func (fakeContainer) Inspect(context.Context) (*container.Info, error) {
|
||||||
return &container.Info{ID: "fake", State: "running", Health: container.HealthNone}, nil
|
return &container.Info{ID: "fake", State: "running", Health: container.HealthNone}, nil
|
||||||
}
|
}
|
||||||
@@ -341,6 +350,7 @@ jobs:
|
|||||||
container:
|
container:
|
||||||
image: node:20
|
image: node:20
|
||||||
credentials: {username: "${{ env.REG_USER }}", password: pass}
|
credentials: {username: "${{ env.REG_USER }}", password: pass}
|
||||||
|
ports: ["8080:80"]
|
||||||
services:
|
services:
|
||||||
redis:
|
redis:
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
@@ -350,6 +360,7 @@ jobs:
|
|||||||
`, &Config{Vars: map[string]string{"REG_USER": "user", "TEXT": "${{ 'literal' }}"}})
|
`, &Config{Vars: map[string]string{"REG_USER": "user", "TEXT": "${{ 'literal' }}"}})
|
||||||
redis, job = inputs[0], inputs[1]
|
redis, job = inputs[0], inputs[1]
|
||||||
require.Equal(t, "user", job.Username)
|
require.Equal(t, "user", job.Username)
|
||||||
|
require.Equal(t, "8080", job.PortBindings["80/tcp"][0].HostPort)
|
||||||
require.Equal(t, "user", redis.Username)
|
require.Equal(t, "user", redis.Username)
|
||||||
require.Equal(t, []string{"TEXT=${{ 'literal' }}"}, redis.Env)
|
require.Equal(t, []string{"TEXT=${{ 'literal' }}"}, redis.Env)
|
||||||
require.Equal(t, "--volumes-from "+job.Name, redis.WorkflowOptions)
|
require.Equal(t, "--volumes-from "+job.Name, redis.WorkflowOptions)
|
||||||
@@ -455,7 +466,7 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
|
|||||||
t.Run(testcase.name+testBindSuffix, func(t *testing.T) {
|
t.Run(testcase.name+testBindSuffix, func(t *testing.T) {
|
||||||
rctemplate.Config.Workdir = testcase.name
|
rctemplate.Config.Workdir = testcase.name
|
||||||
rctemplate.Config.BindWorkdir = bindWorkDir
|
rctemplate.Config.BindWorkdir = bindWorkDir
|
||||||
gotbind, gotmount := rctemplate.GetBindsAndMounts(t.Context())
|
gotbind, gotmount, _ := rctemplate.GetBindsAndMounts(t.Context())
|
||||||
|
|
||||||
if bindWorkDir {
|
if bindWorkDir {
|
||||||
fullBind := testcase.name + ":" + testcase.want
|
fullBind := testcase.name + ":" + testcase.want
|
||||||
@@ -507,7 +518,7 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
|
|||||||
rc.ExprEval = rc.NewExpressionEvaluator(t.Context())
|
rc.ExprEval = rc.NewExpressionEvaluator(t.Context())
|
||||||
require.NoError(t, rc.resolvePlatformImage(t.Context()))
|
require.NoError(t, rc.resolvePlatformImage(t.Context()))
|
||||||
|
|
||||||
gotbind, gotmount := rc.GetBindsAndMounts(t.Context())
|
gotbind, gotmount, _ := rc.GetBindsAndMounts(t.Context())
|
||||||
assert.Contains(t, gotbind, "/host/mame/roms:/root/.mame/roms:ro")
|
assert.Contains(t, gotbind, "/host/mame/roms:/root/.mame/roms:ro")
|
||||||
assert.NotContains(t, gotbind, "${{ secrets.MAME }}")
|
assert.NotContains(t, gotbind, "${{ secrets.MAME }}")
|
||||||
assert.NotContains(t, gotmount, "${{ secrets.MAME }}")
|
assert.NotContains(t, gotmount, "${{ secrets.MAME }}")
|
||||||
@@ -522,7 +533,7 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
|
|||||||
rc.containerSpec.Volumes = testcase.volumes
|
rc.containerSpec.Volumes = testcase.volumes
|
||||||
rc.Run.JobID = "job1"
|
rc.Run.JobID = "job1"
|
||||||
|
|
||||||
gotbind, gotmount := rc.GetBindsAndMounts(t.Context())
|
gotbind, gotmount, _ := rc.GetBindsAndMounts(t.Context())
|
||||||
|
|
||||||
if len(testcase.wantbind) > 0 {
|
if len(testcase.wantbind) > 0 {
|
||||||
assert.Contains(t, gotbind, testcase.wantbind)
|
assert.Contains(t, gotbind, testcase.wantbind)
|
||||||
@@ -551,13 +562,19 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
|
|||||||
t.Run("ToolCacheMount", func(t *testing.T) {
|
t.Run("ToolCacheMount", func(t *testing.T) {
|
||||||
rc := newRunContext(&Config{})
|
rc := newRunContext(&Config{})
|
||||||
|
|
||||||
_, gotmount := rc.GetBindsAndMounts(t.Context())
|
_, gotmount, _ := rc.GetBindsAndMounts(t.Context())
|
||||||
assert.NotContains(t, gotmount, sharedToolCacheVolume)
|
assert.NotContains(t, gotmount, sharedToolCacheVolume)
|
||||||
|
|
||||||
rc.Config.SharedToolCache = true
|
rc.Config.SharedToolCache = true
|
||||||
rc.containerSpec.Volumes = []string{"/unapproved:" + container.DefaultToolCache}
|
rc.containerSpec.Volumes = []string{"/unapproved:" + container.DefaultToolCache}
|
||||||
_, gotmount = rc.GetBindsAndMounts(t.Context())
|
_, gotmount, _ = rc.GetBindsAndMounts(t.Context())
|
||||||
assert.Equal(t, container.DefaultToolCache, gotmount[sharedToolCacheVolume])
|
assert.Equal(t, container.DefaultToolCache, gotmount[sharedToolCacheVolume])
|
||||||
|
|
||||||
|
rc.Config.ToolCacheSlot = "1"
|
||||||
|
_, gotmount, _ = rc.GetBindsAndMounts(t.Context())
|
||||||
|
assert.Equal(t, container.DefaultToolCache, gotmount[sharedToolCacheVolume+"-1"])
|
||||||
|
assert.NotContains(t, gotmount, sharedToolCacheVolume)
|
||||||
|
assert.Contains(t, rc.validVolumes(), sharedToolCacheVolume+"-1")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("DaemonMountsAboveOwnerRepo", func(t *testing.T) {
|
t.Run("DaemonMountsAboveOwnerRepo", func(t *testing.T) {
|
||||||
@@ -569,16 +586,26 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
|
|||||||
Config: &Config{BindWorkdir: true, Workdir: "/workspace/1/owner/repo", PresetGitHubContext: &model.GithubContext{}, ValidVolumes: []string{"claimed"}},
|
Config: &Config{BindWorkdir: true, Workdir: "/workspace/1/owner/repo", PresetGitHubContext: &model.GithubContext{}, ValidVolumes: []string{"claimed"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
gotbind, _ := rc.GetBindsAndMounts(t.Context())
|
gotbind, _, workspace := rc.GetBindsAndMounts(t.Context())
|
||||||
assert.True(t, slices.ContainsFunc(gotbind, func(bind string) bool { return strings.HasPrefix(bind, "/workspace/1:/workspace/1") }), gotbind)
|
assert.True(t, slices.ContainsFunc(gotbind, func(bind string) bool { return strings.HasPrefix(bind, "/workspace/1:/workspace/1") }), gotbind)
|
||||||
|
assert.Equal(t, "/workspace/1", workspace)
|
||||||
|
|
||||||
rc.Config.BindWorkdir = false
|
rc.Config.BindWorkdir = false
|
||||||
_, gotmount := rc.GetBindsAndMounts(t.Context())
|
_, gotmount, workspace := rc.GetBindsAndMounts(t.Context())
|
||||||
assert.Equal(t, "/workspace/1", gotmount[rc.jobContainerName()])
|
assert.Equal(t, "/workspace/1", gotmount[rc.jobContainerName()])
|
||||||
|
assert.Empty(t, workspace)
|
||||||
|
|
||||||
rc.containerSpec.Volumes = []string{"claimed:/workspace/1"}
|
rc.containerSpec.Volumes = []string{"claimed:/workspace/1"}
|
||||||
_, gotmount = rc.GetBindsAndMounts(t.Context())
|
_, gotmount, _ = rc.GetBindsAndMounts(t.Context())
|
||||||
assert.Equal(t, "/workspace/1/owner/repo", gotmount[rc.jobContainerName()])
|
assert.Equal(t, "/workspace/1/owner/repo", gotmount[rc.jobContainerName()])
|
||||||
|
rc.Config.BindWorkdir = true
|
||||||
|
_, _, workspace = rc.GetBindsAndMounts(t.Context())
|
||||||
|
assert.Equal(t, "/workspace/1/owner/repo", workspace)
|
||||||
|
|
||||||
|
rc.containerSpec.Volumes = nil
|
||||||
|
rc.Config.PresetGitHubContext = nil
|
||||||
|
_, _, workspace = rc.GetBindsAndMounts(t.Context())
|
||||||
|
assert.Empty(t, workspace)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,7 +638,7 @@ func TestRunContextValidVolumes(t *testing.T) {
|
|||||||
rc.JobContainer = hostEnv
|
rc.JobContainer = hostEnv
|
||||||
rc.Config.BindWorkdir = false
|
rc.Config.BindWorkdir = false
|
||||||
rc.Config.SharedToolCache = true
|
rc.Config.SharedToolCache = true
|
||||||
binds, mounts := rc.GetBindsAndMounts(t.Context())
|
binds, mounts, _ := rc.GetBindsAndMounts(t.Context())
|
||||||
assert.Subset(t, binds, []string{hostEnv.Path + ":" + hostEnv.Path, hostEnv.GetActPath() + ":" + hostEnv.GetActPath()})
|
assert.Subset(t, binds, []string{hostEnv.Path + ":" + hostEnv.Path, hostEnv.GetActPath() + ":" + hostEnv.GetActPath()})
|
||||||
assert.Contains(t, mounts, sharedToolCacheVolume)
|
assert.Contains(t, mounts, sharedToolCacheVolume)
|
||||||
assert.Equal(t, binds, container.SanitizeBinds(t.Context(), rc.validVolumes(), binds))
|
assert.Equal(t, binds, container.SanitizeBinds(t.Context(), rc.validVolumes(), binds))
|
||||||
@@ -683,6 +710,110 @@ func TestCleanupJobVolumesReapsAbandonedDeferredCleanup(t *testing.T) {
|
|||||||
assert.ElementsMatch(t, []string{"became-active", "remove-failed", "foreign", "fresh", "unknown-age"}, slices.Collect(maps.Keys(volumes)))
|
assert.ElementsMatch(t, []string{"became-active", "remove-failed", "foreign", "fresh", "unknown-age"}, slices.Collect(maps.Keys(volumes)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCleanupJobResourcesEmptiesTaskWorkspace(t *testing.T) {
|
||||||
|
defer func(previous bool) { runnerCanRemoveJobFiles = previous }(runnerCanRemoveJobFiles)
|
||||||
|
for _, tt := range []struct {
|
||||||
|
name, workspace string
|
||||||
|
caller *caller
|
||||||
|
runnerCanRemove bool
|
||||||
|
execErr error
|
||||||
|
log string
|
||||||
|
}{
|
||||||
|
{name: "refusal is logged", workspace: "/workspace/1", execErr: container.ExitCodeError(3), log: "not emptying workspace /workspace/1"},
|
||||||
|
{name: "failure does not fail the job", workspace: "/workspace/1", execErr: errors.New("no rm"), log: "could not empty workspace /workspace/1"},
|
||||||
|
{name: "no runner bind"},
|
||||||
|
{name: "called workflow shares it", workspace: "/workspace/1", caller: &caller{}},
|
||||||
|
{name: "runner removes it itself", workspace: "/workspace/1", runnerCanRemove: true},
|
||||||
|
} {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
runnerCanRemoveJobFiles = tt.runnerCanRemove
|
||||||
|
processLog := logtest.SetDefault(t)
|
||||||
|
var jobLog bytes.Buffer
|
||||||
|
var calls []string
|
||||||
|
job := &containerMock{}
|
||||||
|
if tt.log != "" {
|
||||||
|
job.On("ReplaceLogWriter", io.Discard, io.Discard).Return(&jobLog, &jobLog).Once()
|
||||||
|
job.On("ReplaceLogWriter", &jobLog, &jobLog).Return(io.Discard, io.Discard).Once()
|
||||||
|
job.On("Exec", mock.MatchedBy(func(command []string) bool { return command[4] == tt.workspace }), map[string]string{"PATH": "/usr/sbin:/usr/bin:/sbin:/bin"}, "0", "/").Return(func(ctx context.Context) error {
|
||||||
|
calls = append(calls, "exec")
|
||||||
|
deadline, ok := ctx.Deadline()
|
||||||
|
assert.True(t, ok)
|
||||||
|
assert.LessOrEqual(t, time.Until(deadline), 10*time.Second-container.DrainGracePeriod)
|
||||||
|
common.Logger(ctx).Infof("workspace script output")
|
||||||
|
return tt.execErr
|
||||||
|
})
|
||||||
|
}
|
||||||
|
job.On("Remove").Return(func(context.Context) error {
|
||||||
|
calls = append(calls, "remove")
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
rc := &RunContext{
|
||||||
|
Config: &Config{},
|
||||||
|
Run: &model.Run{Workflow: &model.Workflow{Name: "workflow"}, JobID: "job"},
|
||||||
|
JobContainer: job,
|
||||||
|
taskWorkspace: tt.workspace,
|
||||||
|
caller: tt.caller,
|
||||||
|
deferVolumeCleanup: func(common.Executor) {},
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(t.Context(), 20*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
ctx = common.WithLogger(ctx, logging.New(logging.NewLevelHandler(newJobLogHandler(&jobLog, cyan), logging.LevelInfo)))
|
||||||
|
require.NoError(t, rc.cleanupJobResources("", false, false)(ctx))
|
||||||
|
job.AssertExpectations(t)
|
||||||
|
assert.NotContains(t, jobLog.String(), "workspace")
|
||||||
|
if tt.log == "" {
|
||||||
|
assert.Equal(t, []string{"remove"}, calls)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert.Equal(t, []string{"exec", "remove"}, calls)
|
||||||
|
assert.True(t, slices.ContainsFunc(processLog.AllRecords(), func(record logging.Record) bool {
|
||||||
|
return strings.HasPrefix(record.Message, tt.log)
|
||||||
|
}), processLog.AllRecords())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEmptyTaskWorkspaceScript(t *testing.T) {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
t.Skip("the script runs in the linux job container")
|
||||||
|
}
|
||||||
|
run := func(t *testing.T, workspace string, mountpoints ...string) error {
|
||||||
|
t.Helper()
|
||||||
|
var mountinfo strings.Builder
|
||||||
|
for _, mountpoint := range mountpoints {
|
||||||
|
fmt.Fprintf(&mountinfo, "36 35 98:0 /src %s rw - ext4 /dev/sda1 rw\n", mountpoint)
|
||||||
|
}
|
||||||
|
info := filepath.Join(t.TempDir(), "mountinfo")
|
||||||
|
require.NoError(t, os.WriteFile(info, []byte(mountinfo.String()), 0o600))
|
||||||
|
return exec.Command("sh", "-c", emptyTaskWorkspaceScript, "sh", workspace, info).Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
workspace := t.TempDir()
|
||||||
|
for _, file := range []string{"owner/repo/file", ".hidden", "..odd"} {
|
||||||
|
require.NoError(t, os.MkdirAll(filepath.Dir(filepath.Join(workspace, file)), 0o755))
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(workspace, file), nil, 0o600))
|
||||||
|
}
|
||||||
|
require.NoError(t, run(t, workspace, workspace))
|
||||||
|
entries, err := os.ReadDir(workspace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Empty(t, entries)
|
||||||
|
|
||||||
|
for _, tt := range []struct {
|
||||||
|
name, workspace string
|
||||||
|
mountpoints []string
|
||||||
|
}{
|
||||||
|
{"a mount below it", "/nonexistent/1", []string{"/nonexistent/1", "/nonexistent/1/owner/repo/cache"}},
|
||||||
|
{"a workspace that is not a mountpoint", "/nonexistent/1", []string{"/nonexistent/2"}},
|
||||||
|
{"a top-level directory", "/nonexistent", []string{"/nonexistent"}},
|
||||||
|
} {
|
||||||
|
t.Run("refuses "+tt.name, func(t *testing.T) {
|
||||||
|
var exitErr *exec.ExitError
|
||||||
|
require.ErrorAs(t, run(t, tt.workspace, tt.mountpoints...), &exitErr)
|
||||||
|
assert.Equal(t, 3, exitErr.ExitCode())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRemoveDockerActionImagesByTag(t *testing.T) {
|
func TestRemoveDockerActionImagesByTag(t *testing.T) {
|
||||||
var removed []string
|
var removed []string
|
||||||
fakeDockerDaemon(t, func(writer http.ResponseWriter, request *http.Request) {
|
fakeDockerDaemon(t, func(writer http.ResponseWriter, request *http.Request) {
|
||||||
@@ -1181,6 +1312,26 @@ func TestPrintStartJobContainerGroupGolden(t *testing.T) {
|
|||||||
assert.Equal(t, want, buf.String())
|
assert.Equal(t, want, buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStartHostEnvironmentToolCacheSlotIsSubdirOfSharedCache(t *testing.T) {
|
||||||
|
cacheDir := t.TempDir()
|
||||||
|
override := filepath.Join(cacheDir, "override")
|
||||||
|
for sharedCache, env := range map[string]map[string]string{
|
||||||
|
filepath.Join(cacheDir, "tool_cache"): {},
|
||||||
|
override: {"RUNNER_TOOL_CACHE": override},
|
||||||
|
} {
|
||||||
|
rc := &RunContext{
|
||||||
|
Config: &Config{ActionCacheDir: cacheDir, SharedToolCache: true, ToolCacheSlot: "1"},
|
||||||
|
Env: env,
|
||||||
|
Run: &model.Run{Workflow: &model.Workflow{Name: "wf"}},
|
||||||
|
}
|
||||||
|
require.NoError(t, rc.startHostEnvironment()(t.Context()))
|
||||||
|
t.Cleanup(func() { require.NoError(t, rc.cleanUpJobContainer(context.Background())) })
|
||||||
|
want := filepath.Join(sharedCache, "1")
|
||||||
|
assert.Equal(t, want, rc.JobContainer.(*container.HostEnvironment).ToolCache)
|
||||||
|
assert.Equal(t, want, rc.Env["RUNNER_TOOL_CACHE"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRunContext_cleanupFailedStart(t *testing.T) {
|
func TestRunContext_cleanupFailedStart(t *testing.T) {
|
||||||
type ctxKey string
|
type ctxKey string
|
||||||
const sentinel = ctxKey("sentinel")
|
const sentinel = ctxKey("sentinel")
|
||||||
@@ -1252,6 +1403,7 @@ func TestRunContext_cleanupFailedStart(t *testing.T) {
|
|||||||
instance.On("Close").Return(record(name+".Close", nil))
|
instance.On("Close").Return(record(name+".Close", nil))
|
||||||
}
|
}
|
||||||
job.On("Copy", mock.Anything, mock.Anything).Return(record("job.Copy", nil))
|
job.On("Copy", mock.Anything, mock.Anything).Return(record("job.Copy", nil))
|
||||||
|
job.On("GetContainerArchive", mock.Anything, mock.Anything).Return(nil, os.ErrNotExist)
|
||||||
job.On("Inspect", mock.Anything).Return(&container.Info{ID: "job-id"}, nil).
|
job.On("Inspect", mock.Anything).Return(&container.Info{ID: "job-id"}, nil).
|
||||||
Run(func(mock.Arguments) { operations = append(operations, "job.Inspect") })
|
Run(func(mock.Arguments) { operations = append(operations, "job.Inspect") })
|
||||||
for _, health := range []string{container.HealthStarting, testcase.health} {
|
for _, health := range []string{container.HealthStarting, testcase.health} {
|
||||||
@@ -1466,12 +1618,20 @@ func TestGetJobContextReportsContainers(t *testing.T) {
|
|||||||
type imageEnvContainer struct {
|
type imageEnvContainer struct {
|
||||||
*container.HostEnvironment
|
*container.HostEnvironment
|
||||||
imageEnv map[string]string
|
imageEnv map[string]string
|
||||||
|
osRelease []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c imageEnvContainer) UpdateFromImageEnv(env *map[string]string) common.Executor {
|
func (c imageEnvContainer) UpdateFromImageEnv(env *map[string]string) common.Executor {
|
||||||
return func(_ctx context.Context) error { maps.Copy(*env, c.imageEnv); return nil }
|
return func(_ctx context.Context) error { maps.Copy(*env, c.imageEnv); return nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c imageEnvContainer) GetContainerArchive(_ctx context.Context, srcPath string) (io.ReadCloser, error) {
|
||||||
|
if srcPath != "/usr/lib/os-release" || c.osRelease == nil {
|
||||||
|
return nil, os.ErrNotExist
|
||||||
|
}
|
||||||
|
return io.NopCloser(bytes.NewReader(c.osRelease)), nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestCopyWorkflowFilesHandsNodeTheRunnerCAUnlessTheJobOrImageSetsIt(t *testing.T) {
|
func TestCopyWorkflowFilesHandsNodeTheRunnerCAUnlessTheJobOrImageSetsIt(t *testing.T) {
|
||||||
caFile, actPath := filepath.Join(t.TempDir(), "ca.crt"), t.TempDir()
|
caFile, actPath := filepath.Join(t.TempDir(), "ca.crt"), t.TempDir()
|
||||||
require.NoError(t, os.WriteFile(caFile, []byte("PEM\n"), 0o600))
|
require.NoError(t, os.WriteFile(caFile, []byte("PEM\n"), 0o600))
|
||||||
@@ -1481,7 +1641,7 @@ func TestCopyWorkflowFilesHandsNodeTheRunnerCAUnlessTheJobOrImageSetsIt(t *testi
|
|||||||
Config: &Config{CAFile: caFile},
|
Config: &Config{CAFile: caFile},
|
||||||
Run: &model.Run{JobID: "job", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"job": {}}}},
|
Run: &model.Run{JobID: "job", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"job": {}}}},
|
||||||
Env: maps.Clone(jobEnv),
|
Env: maps.Clone(jobEnv),
|
||||||
JobContainer: imageEnvContainer{&container.HostEnvironment{Path: t.TempDir(), ActPath: actPath, StdOut: io.Discard}, imageEnv},
|
JobContainer: imageEnvContainer{&container.HostEnvironment{Path: t.TempDir(), ActPath: actPath, StdOut: io.Discard}, imageEnv, nil},
|
||||||
}
|
}
|
||||||
rc.containerSpec.Env = containerEnv
|
rc.containerSpec.Env = containerEnv
|
||||||
require.NoError(t, rc.copyWorkflowFiles()(t.Context()))
|
require.NoError(t, rc.copyWorkflowFiles()(t.Context()))
|
||||||
@@ -1598,6 +1758,30 @@ func TestRunContextContainerImageCannotSelectBackend(t *testing.T) {
|
|||||||
func TestRunContextImageOS(t *testing.T) {
|
func TestRunContextImageOS(t *testing.T) {
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
|
t.Run("keeps an ImageOS from the image, the job env or the job's Ubuntu release", func(t *testing.T) {
|
||||||
|
ubuntu := tarArchive(t, tarEntry{name: "os-release", body: "ID=ubuntu\nVERSION_ID=\"22.04\"\n"})
|
||||||
|
for _, tc := range []struct {
|
||||||
|
imageEnv map[string]string
|
||||||
|
jobEnv string
|
||||||
|
osRelease []byte
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{imageEnv: map[string]string{"ImageOS": "ubuntu24-arm64"}, osRelease: ubuntu, want: "ubuntu24-arm64"},
|
||||||
|
{imageEnv: map[string]string{"ImageOS": "ubuntu24-arm64"}, jobEnv: "ImageOS: ubuntu20", want: "ubuntu20"},
|
||||||
|
{osRelease: ubuntu, want: "ubuntu22"},
|
||||||
|
{osRelease: tarArchive(t, tarEntry{name: "os-release", body: "ID=debian\nVERSION_ID=\"12\"\n"}), want: "ubuntu24"},
|
||||||
|
} {
|
||||||
|
rc := createRunsOnRunContext(t, "ubuntu-latest\nenv: {"+tc.jobEnv+"}")
|
||||||
|
rc.platformImage = "docker.gitea.com/runner-images:ubuntu-latest"
|
||||||
|
rc.JobContainer = imageEnvContainer{&container.HostEnvironment{ActPath: t.TempDir()}, tc.imageEnv, tc.osRelease}
|
||||||
|
require.NoError(t, rc.copyWorkflowFiles()(ctx))
|
||||||
|
require.NoError(t, evaluateJobEnvAndDefaults(ctx, rc))
|
||||||
|
env := map[string]string{}
|
||||||
|
require.NoError(t, setupEnv(ctx, &stepRun{RunContext: rc, Step: &model.Step{}, env: env}))
|
||||||
|
assert.Equal(t, tc.want, env["ImageOS"])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("prefers the release in the resolved image tag", func(t *testing.T) {
|
t.Run("prefers the release in the resolved image tag", func(t *testing.T) {
|
||||||
rc := createRunsOnRunContext(t, "ubuntu-latest")
|
rc := createRunsOnRunContext(t, "ubuntu-latest")
|
||||||
rc.Config.PlatformPicker = func([]string) string { return "docker.gitea.com/runner-images:ubuntu-24.04" }
|
rc.Config.PlatformPicker = func([]string) string { return "docker.gitea.com/runner-images:ubuntu-24.04" }
|
||||||
@@ -1612,8 +1796,8 @@ func TestRunContextImageOS(t *testing.T) {
|
|||||||
assert.Equal(t, "ubuntu22", rc.imageOS(ctx))
|
assert.Equal(t, "ubuntu22", rc.imageOS(ctx))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("keeps the historical value for a rolling label with no release", func(t *testing.T) {
|
t.Run("reports the current release for the rolling ubuntu-latest label", func(t *testing.T) {
|
||||||
assert.Equal(t, "ubuntu20", createRunsOnRunContext(t, "ubuntu-latest").imageOS(ctx))
|
assert.Equal(t, "ubuntu24", createRunsOnRunContext(t, "ubuntu-latest").imageOS(ctx))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("is empty for the synthetic job of a composite action", func(t *testing.T) {
|
t.Run("is empty for the synthetic job of a composite action", func(t *testing.T) {
|
||||||
@@ -1640,23 +1824,33 @@ func TestRunContextGetRunnerContext(t *testing.T) {
|
|||||||
assert.NotContains(t, runnerContext, "debug")
|
assert.NotContains(t, runnerContext, "debug")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("reports debug when step debugging is on", func(t *testing.T) {
|
t.Run("reports debug from the secret, else the variable, also in composites", func(t *testing.T) {
|
||||||
rc := createRunsOnRunContext(t, "ubuntu-latest")
|
rc := createRunsOnRunContext(t, "ubuntu-latest")
|
||||||
rc.Config.Secrets = map[string]string{"ACTIONS_STEP_DEBUG": "true"}
|
rc.Config.Secrets = map[string]string{"ACTIONS_STEP_DEBUG": "true"}
|
||||||
|
|
||||||
assert.Equal(t, "1", rc.getRunnerContext(ctx)["debug"])
|
assert.Equal(t, "1", rc.getRunnerContext(ctx)["debug"])
|
||||||
|
assert.Equal(t, "1", (&RunContext{Parent: rc, Config: &Config{}}).getRunnerContext(ctx)["debug"])
|
||||||
|
|
||||||
|
rc.Config.Secrets = map[string]string{}
|
||||||
|
rc.Config.Vars = map[string]string{"ACTIONS_STEP_DEBUG": "true"}
|
||||||
|
assert.Equal(t, "1", rc.getRunnerContext(ctx)["debug"])
|
||||||
|
|
||||||
|
rc.Config.Secrets = map[string]string{"ACTIONS_STEP_DEBUG": "false"}
|
||||||
|
assert.NotContains(t, rc.getRunnerContext(ctx), "debug")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("keeps the execution environment values", func(t *testing.T) {
|
t.Run("keeps the execution environment values", func(t *testing.T) {
|
||||||
rc := createRunsOnRunContext(t, "ubuntu-latest")
|
rc := createRunsOnRunContext(t, "ubuntu-latest")
|
||||||
rc.Config.Workdir = "/host/work/owner/repo"
|
rc.Config.Workdir = "/host/work/owner/repo"
|
||||||
rc.JobContainer = &container.HostEnvironment{Workdir: rc.Config.Workdir, Path: "/container/work/owner/repo", TmpDir: "/tmp/act", ToolCache: "/tmp/tool_cache"}
|
rc.JobContainer = &container.HostEnvironment{Workdir: rc.Config.Workdir, Path: "/container/work/owner/repo", TmpDir: "/tmp/act", ToolCache: "/tmp/tool_cache", ActPath: "/tmp/act-files"}
|
||||||
|
|
||||||
runnerContext := rc.getRunnerContext(ctx)
|
runnerContext := rc.getRunnerContext(ctx)
|
||||||
assert.Equal(t, "/tmp/act", runnerContext["temp"])
|
assert.Equal(t, "/tmp/act", runnerContext["temp"])
|
||||||
assert.Equal(t, "/tmp/tool_cache", runnerContext["tool_cache"])
|
assert.Equal(t, "/tmp/tool_cache", runnerContext["tool_cache"])
|
||||||
assert.Equal(t, "/container/work/owner", runnerContext["workspace"])
|
assert.Equal(t, "/container/work/owner", runnerContext["workspace"])
|
||||||
assert.Equal(t, "/container/work/owner/repo", rc.getGithubContext(ctx).Workspace)
|
githubContext := rc.getGithubContext(ctx)
|
||||||
|
assert.Equal(t, "/container/work/owner/repo", githubContext.Workspace)
|
||||||
|
assert.Equal(t, "/tmp/act-files/workflow/envs.txt", githubContext.Env)
|
||||||
|
assert.Equal(t, "/tmp/act-files/workflow/pathcmd.txt", githubContext.Path)
|
||||||
assert.NotEmpty(t, runnerContext["os"])
|
assert.NotEmpty(t, runnerContext["os"])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ type Config struct {
|
|||||||
EventJSON string // the content of JSON file to use for event.json in containers, overrides EventPath
|
EventJSON string // the content of JSON file to use for event.json in containers, overrides EventPath
|
||||||
ContainerNamePrefix string // the prefix of container name
|
ContainerNamePrefix string // the prefix of container name
|
||||||
ContainerMaxLifetime time.Duration // the max lifetime of job containers
|
ContainerMaxLifetime time.Duration // the max lifetime of job containers
|
||||||
CleanWorkdir bool // remove host executor workdir on teardown
|
|
||||||
DefaultActionInstance string // the default actions web site
|
DefaultActionInstance string // the default actions web site
|
||||||
// DefaultActionInstanceIsSelfHosted reports whether DefaultActionInstance is this
|
// DefaultActionInstanceIsSelfHosted reports whether DefaultActionInstance is this
|
||||||
// self-hosted Gitea (DEFAULT_ACTIONS_URL=self). It gates token trust: only then may the
|
// self-hosted Gitea (DEFAULT_ACTIONS_URL=self). It gates token trust: only then may the
|
||||||
@@ -84,7 +83,8 @@ type Config struct {
|
|||||||
JobLoggerLevel *logging.Level // the level of job logger
|
JobLoggerLevel *logging.Level // the level of job logger
|
||||||
ValidVolumes []string // only volumes (and bind mounts) in this slice can be mounted on the job container or service containers
|
ValidVolumes []string // only volumes (and bind mounts) in this slice can be mounted on the job container or service containers
|
||||||
ContainerVolumes []string // mounted into every job, service and docker action container
|
ContainerVolumes []string // mounted into every job, service and docker action container
|
||||||
SharedToolCache bool // one tool cache for all jobs instead of one per job
|
SharedToolCache bool // keeps the tool cache across jobs instead of one per job
|
||||||
|
ToolCacheSlot string // keeps concurrent tasks' tool caches apart, empty for slot 0 and in exec
|
||||||
InsecureSkipTLS bool // whether to skip verifying TLS certificate of the Gitea instance
|
InsecureSkipTLS bool // whether to skip verifying TLS certificate of the Gitea instance
|
||||||
ClientCertFile, ClientKeyFile string // PEM client certificate for the Gitea instance
|
ClientCertFile, ClientKeyFile string // PEM client certificate for the Gitea instance
|
||||||
CAFile string // PEM CA certificates the Gitea instance's certificate chains to
|
CAFile string // PEM CA certificates the Gitea instance's certificate chains to
|
||||||
@@ -99,7 +99,11 @@ type Config struct {
|
|||||||
|
|
||||||
// RunnerDebug reports whether debug logging is on, exposed as `runner.debug` and RUNNER_DEBUG.
|
// RunnerDebug reports whether debug logging is on, exposed as `runner.debug` and RUNNER_DEBUG.
|
||||||
func (c Config) RunnerDebug() bool {
|
func (c Config) RunnerDebug() bool {
|
||||||
return c.Secrets["ACTIONS_STEP_DEBUG"] == "true" || c.Env["ACTIONS_STEP_DEBUG"] == "true"
|
stepDebug, ok := c.Secrets["ACTIONS_STEP_DEBUG"]
|
||||||
|
if !ok {
|
||||||
|
stepDebug = c.Vars["ACTIONS_STEP_DEBUG"]
|
||||||
|
}
|
||||||
|
return stepDebug == "true" || c.Env["ACTIONS_STEP_DEBUG"] == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetToken: Adapt to Gitea
|
// GetToken: Adapt to Gitea
|
||||||
|
|||||||
@@ -455,7 +455,6 @@ func TestRunEventHostEnvironment(t *testing.T) {
|
|||||||
{workdir, "nix-prepend-path", "push", "", platforms, secrets},
|
{workdir, "nix-prepend-path", "push", "", platforms, secrets},
|
||||||
{workdir, "uses-docker-url", "push", "", platforms, secrets},
|
{workdir, "uses-docker-url", "push", "", platforms, secrets},
|
||||||
{workdir, "local-action-dockerfile", "push", "", platforms, secrets},
|
{workdir, "local-action-dockerfile", "push", "", platforms, secrets},
|
||||||
{workdir, "builtin-checkout", "push", "", platforms, secrets},
|
|
||||||
{workdir, "inputs-via-env-context", "push", "", platforms, secrets},
|
{workdir, "inputs-via-env-context", "push", "", platforms, secrets},
|
||||||
{workdir, "do-not-leak-step-env-in-composite", "push", "", platforms, secrets},
|
{workdir, "do-not-leak-step-env-in-composite", "push", "", platforms, secrets},
|
||||||
{workdir, "set-env-step-env-override", "push", "", platforms, secrets},
|
{workdir, "set-env-step-env-override", "push", "", platforms, secrets},
|
||||||
|
|||||||
+6
-4
@@ -21,6 +21,11 @@ import (
|
|||||||
"gitea.dev/actionslib/pkg/model"
|
"gitea.dev/actionslib/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
pathFileCommand = "workflow/pathcmd.txt"
|
||||||
|
envFileCommand = "workflow/envs.txt"
|
||||||
|
)
|
||||||
|
|
||||||
type step interface {
|
type step interface {
|
||||||
pre() common.Executor
|
pre() common.Executor
|
||||||
main() common.Executor
|
main() common.Executor
|
||||||
@@ -149,10 +154,7 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo
|
|||||||
stateFileCommand := path.Join("workflow", "statecmd.txt")
|
stateFileCommand := path.Join("workflow", "statecmd.txt")
|
||||||
(*step.getEnv())["GITHUB_STATE"] = container.JoinPath(actPath, stateFileCommand)
|
(*step.getEnv())["GITHUB_STATE"] = container.JoinPath(actPath, stateFileCommand)
|
||||||
|
|
||||||
pathFileCommand := path.Join("workflow", "pathcmd.txt")
|
|
||||||
(*step.getEnv())["GITHUB_PATH"] = container.JoinPath(actPath, pathFileCommand)
|
(*step.getEnv())["GITHUB_PATH"] = container.JoinPath(actPath, pathFileCommand)
|
||||||
|
|
||||||
envFileCommand := path.Join("workflow", "envs.txt")
|
|
||||||
(*step.getEnv())["GITHUB_ENV"] = container.JoinPath(actPath, envFileCommand)
|
(*step.getEnv())["GITHUB_ENV"] = container.JoinPath(actPath, envFileCommand)
|
||||||
|
|
||||||
// Per-step summary file. Composite sub-steps share the outer job step's index
|
// Per-step summary file. Composite sub-steps share the outer job step's index
|
||||||
@@ -263,7 +265,7 @@ func setupEnv(ctx context.Context, step step) error {
|
|||||||
|
|
||||||
env := step.getEnv()
|
env := step.getEnv()
|
||||||
// container env is the image's baseline, which job env and $GITHUB_ENV override
|
// container env is the image's baseline, which job env and $GITHUB_ENV override
|
||||||
mergeIntoMap(step, env, rc.caEnv, rc.containerSpec.Env, rc.GetEnv())
|
mergeIntoMap(step, env, rc.defaultEnv, rc.containerSpec.Env, rc.GetEnv())
|
||||||
rc.withGithubEnv(ctx, getStepGithubContext(ctx, step), *env)
|
rc.withGithubEnv(ctx, getStepGithubContext(ctx, step), *env)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package runner
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/common"
|
|
||||||
"gitea.com/gitea/runner/internal/pkg/action"
|
|
||||||
"gitea.com/gitea/runner/internal/pkg/action/checkout"
|
|
||||||
|
|
||||||
"gitea.dev/actionslib/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
var builtinActions = map[string]func(context.Context, *action.Context) error{
|
|
||||||
"checkout": checkout.Main,
|
|
||||||
}
|
|
||||||
|
|
||||||
type stepActionBuiltin struct {
|
|
||||||
Step *model.Step
|
|
||||||
RunContext *RunContext
|
|
||||||
run func(context.Context, *action.Context) error
|
|
||||||
env map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sab *stepActionBuiltin) pre() common.Executor { return common.NewPipelineExecutor() }
|
|
||||||
|
|
||||||
func (sab *stepActionBuiltin) main() common.Executor {
|
|
||||||
sab.env = map[string]string{}
|
|
||||||
return runStepExecutor(sab, stepStageMain, func(ctx context.Context) error {
|
|
||||||
if common.Dryrun(ctx) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
printRunActionHeader(ctx, sab.Step, nil, sab.env, sab.RunContext)
|
|
||||||
|
|
||||||
rc := sab.RunContext
|
|
||||||
rc.ApplyExtraPath(ctx, &sab.env)
|
|
||||||
return sab.run(ctx, &action.Context{
|
|
||||||
Container: rc.JobContainer,
|
|
||||||
Github: getStepGithubContext(ctx, sab),
|
|
||||||
Inputs: sab.Step.With,
|
|
||||||
HostWorkdir: rc.Config.Workdir,
|
|
||||||
Workspace: rc.JobContainer.ToContainerPath(rc.Config.Workdir),
|
|
||||||
BindWorkdir: rc.Config.BindWorkdir,
|
|
||||||
NoSkipCheckout: rc.Config.NoSkipCheckout,
|
|
||||||
UseGitIgnore: rc.Config.UseGitIgnore,
|
|
||||||
InsecureSkipTLS: rc.Config.InsecureSkipTLS,
|
|
||||||
ClientCertFile: rc.Config.ClientCertFile,
|
|
||||||
ClientKeyFile: rc.Config.ClientKeyFile,
|
|
||||||
CAFile: rc.jobCAFile(),
|
|
||||||
Env: sab.env,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sab *stepActionBuiltin) post() common.Executor { return common.NewPipelineExecutor() }
|
|
||||||
|
|
||||||
func (sab *stepActionBuiltin) getRunContext() *RunContext { return sab.RunContext }
|
|
||||||
|
|
||||||
func (sab *stepActionBuiltin) getStepModel() *model.Step { return sab.Step }
|
|
||||||
|
|
||||||
func (sab *stepActionBuiltin) getEnv() *map[string]string { return &sab.env }
|
|
||||||
|
|
||||||
func (sab *stepActionBuiltin) getIfExpression(_ context.Context, _ stepStage) string {
|
|
||||||
return sab.Step.If.Value
|
|
||||||
}
|
|
||||||
@@ -6,9 +6,6 @@ package runner
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
|
||||||
"slices"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gitea.dev/actionslib/pkg/model"
|
"gitea.dev/actionslib/pkg/model"
|
||||||
)
|
)
|
||||||
@@ -36,18 +33,6 @@ func (sf *stepFactoryImpl) newStep(stepModel *model.Step, rc *RunContext) (step,
|
|||||||
runAction: runActionImpl,
|
runAction: runActionImpl,
|
||||||
}, nil
|
}, nil
|
||||||
case model.StepTypeUsesActionRemote:
|
case model.StepTypeUsesActionRemote:
|
||||||
if name, ok := strings.CutPrefix(stepModel.Uses, "builtin:"); ok {
|
|
||||||
run, ok := builtinActions[name]
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unknown built-in action %q (known: %v) for job:%s step:%+v",
|
|
||||||
name, slices.Sorted(maps.Keys(builtinActions)), rc.Name, stepModel)
|
|
||||||
}
|
|
||||||
return &stepActionBuiltin{
|
|
||||||
Step: stepModel,
|
|
||||||
RunContext: rc,
|
|
||||||
run: run,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
return &stepActionRemote{
|
return &stepActionRemote{
|
||||||
Step: stepModel,
|
Step: stepModel,
|
||||||
RunContext: rc,
|
RunContext: rc,
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ func TestStepFactoryNewStep(t *testing.T) {
|
|||||||
{"StepLocalAction", &model.Step{Uses: "./action@v1"}, &stepActionLocal{}},
|
{"StepLocalAction", &model.Step{Uses: "./action@v1"}, &stepActionLocal{}},
|
||||||
{"StepDocker", &model.Step{Uses: "docker://image:tag"}, &stepDocker{}},
|
{"StepDocker", &model.Step{Uses: "docker://image:tag"}, &stepDocker{}},
|
||||||
{"StepRun", &model.Step{Run: "cmd"}, &stepRun{}},
|
{"StepRun", &model.Step{Run: "cmd"}, &stepRun{}},
|
||||||
{"StepBuiltinAction", &model.Step{Uses: "builtin:checkout"}, &stepActionBuiltin{}},
|
|
||||||
} {
|
} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
step, err := (&stepFactoryImpl{}).newStep(test.model, &RunContext{})
|
step, err := (&stepFactoryImpl{}).newStep(test.model, &RunContext{})
|
||||||
@@ -35,7 +34,6 @@ func TestStepFactoryNewStep(t *testing.T) {
|
|||||||
func TestStepFactoryInvalidStep(t *testing.T) {
|
func TestStepFactoryInvalidStep(t *testing.T) {
|
||||||
for _, stepModel := range []*model.Step{
|
for _, stepModel := range []*model.Step{
|
||||||
{Uses: "remote/action@v1", Run: "cmd"},
|
{Uses: "remote/action@v1", Run: "cmd"},
|
||||||
{Uses: "builtin:unknown"},
|
|
||||||
} {
|
} {
|
||||||
_, err := (&stepFactoryImpl{}).newStep(stepModel, &RunContext{Name: "build"})
|
_, err := (&stepFactoryImpl{}).newStep(stepModel, &RunContext{Name: "build"})
|
||||||
assert.ErrorContains(t, err, "job:build ", stepModel.Uses)
|
assert.ErrorContains(t, err, "job:build ", stepModel.Uses)
|
||||||
|
|||||||
+17
-18
@@ -10,7 +10,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"maps"
|
"maps"
|
||||||
"runtime"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -358,29 +357,29 @@ func (sr *stepRun) setupShell(ctx context.Context, eval *expressionEvaluator) (b
|
|||||||
|
|
||||||
implicitShell := step.Shell == ""
|
implicitShell := step.Shell == ""
|
||||||
if implicitShell {
|
if implicitShell {
|
||||||
shellWithFallback := []string{"bash", "sh"}
|
preferred, fallback := "bash", "sh"
|
||||||
|
if rc.isWindowsHost() {
|
||||||
|
preferred, fallback = "pwsh", "powershell" // Don't use bash on windows by default, if not using a docker container
|
||||||
|
}
|
||||||
env := maps.Clone(sr.env)
|
env := maps.Clone(sr.env)
|
||||||
rc.ApplyExtraPath(ctx, &env)
|
rc.ApplyExtraPath(ctx, &env)
|
||||||
if _, ok := rc.JobContainer.(*container.HostEnvironment); ok {
|
step.Shell = rc.shellOrFallback(ctx, env, preferred, fallback)
|
||||||
// Don't use bash on windows by default, if not using a docker container
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
shellWithFallback = []string{"pwsh", "powershell"}
|
|
||||||
}
|
|
||||||
step.Shell = shellWithFallback[0]
|
|
||||||
_, err := lookpath.LookPath2(shellWithFallback[0], env)
|
|
||||||
if err != nil {
|
|
||||||
step.Shell = shellWithFallback[1]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
step.Shell = shellWithFallback[0]
|
|
||||||
if !rc.containerHasBash(ctx, env) {
|
|
||||||
step.Shell = shellWithFallback[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return implicitShell, nil
|
return implicitShell, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shellOrFallback probes a container only for bash.
|
||||||
|
func (rc *RunContext) shellOrFallback(ctx context.Context, env map[string]string, preferred, fallback string) string {
|
||||||
|
if _, ok := rc.JobContainer.(*container.HostEnvironment); ok {
|
||||||
|
if _, err := lookpath.LookPath2(preferred, env); err != nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
} else if preferred == "bash" && !rc.containerHasBash(ctx, env) {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return preferred
|
||||||
|
}
|
||||||
|
|
||||||
// containerHasBash probes once per job, else every implicit-shell step pays for an exec.
|
// containerHasBash probes once per job, else every implicit-shell step pays for an exec.
|
||||||
func (rc *RunContext) containerHasBash(ctx context.Context, env map[string]string) bool {
|
func (rc *RunContext) containerHasBash(ctx context.Context, env map[string]string) bool {
|
||||||
top := rc.topLevelRunContext()
|
top := rc.topLevelRunContext()
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
outputs:
|
||||||
|
output:
|
||||||
|
value: ${{ jobs.first.outputs.output }}
|
||||||
|
dependent:
|
||||||
|
value: ${{ jobs.dependent.outputs.output }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
first:
|
||||||
|
uses: ./.github/workflows/local-reusable-workflow.yml
|
||||||
|
with:
|
||||||
|
string_required: string
|
||||||
|
bool_required: true
|
||||||
|
number_required: 1
|
||||||
|
secrets: inherit
|
||||||
|
dependent:
|
||||||
|
needs: first
|
||||||
|
uses: ./.github/workflows/local-reusable-workflow.yml
|
||||||
|
with:
|
||||||
|
string_required: ${{ needs.first.result == 'success' && needs.first.outputs.output || 'failure' }}
|
||||||
|
bool_required: true
|
||||||
|
number_required: 1
|
||||||
|
secrets: inherit
|
||||||
Loaded 50 of 98 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user