mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-13 22:41:54 +02:00
Gitea needs the workflow model and the expression evaluator to parse workflows and to build the task payload this runner consumes, so today it depends on `gitea.com/gitea/runner` just for `act/model` and `act/exprparser`. Both packages now live in `gitea.dev/actionslib` (`pkg/model`, `pkg/exprparser`), the module both sides already share, and this repository consumes them from there. ### Changes - `act/model` and `act/exprparser` are deleted, all imports point at `gitea.dev/actionslib/pkg/...`. - New `act/ghcontext` package: the `GithubContext` helpers that need a git checkout on disk (`SetRef`, `SetSha`, `SetRepositoryAndOwner`) are runner only and would drag a git client plus the act context logger into the shared module, so they stay here as functions, with their tests. Only caller is `RunContext.getGithubContext`. - `act/common.CartesianProduct` moved to the shared model package, `act/model` was its only user. - `act/model/testdata/container-volumes` moved to `act/runner/testdata/container-volumes`, its only user is `runner_test.go`. - `internal/pkg/client.UUIDHeader` / `TokenHeader` now alias `pkg/protocol`, so the header names cannot drift apart from Gitea. ### Notes - No behaviour change intended: the moved files are unchanged apart from the import paths and the split described above. - `go.mod` depends on the released `gitea.dev/actionslib v0.7.0`, which carries both https://gitea.com/gitea/actionslib/pulls/11 and the `model.UsesHash` port in https://gitea.com/gitea/actionslib/pulls/14 that `main` needs after https://gitea.com/gitea/runner/pulls/1150. - Verified with `go build ./...`, `go vet ./...` and `go test ./act/... ./internal/...`; the docker based `act/runner` integration tests (`TestRunEvent`, `TestRunMatrixWithUserDefinedInclusions`) fail identically with and without this change in my environment. Assisted-by: Codet:GPT-5.1-Codex Reviewed-on: https://gitea.com/gitea/runner/pulls/1143 Reviewed-by: silverwind <[email protected]>
86 lines
2.1 KiB
Go
86 lines
2.1 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package client
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"gitea.com/gitea/runner/internal/pkg/ver"
|
|
|
|
"connectrpc.com/connect"
|
|
"gitea.dev/actionslib/ping/v1/pingv1connect"
|
|
"gitea.dev/actionslib/runner/v1/runnerv1connect"
|
|
)
|
|
|
|
func getHTTPClient(endpoint string, insecure bool) *http.Client {
|
|
transport := &http.Transport{
|
|
Proxy: http.ProxyFromEnvironment,
|
|
MaxIdleConns: 10,
|
|
MaxIdleConnsPerHost: 10, // All requests go to one host; default is 2 which causes frequent reconnects.
|
|
IdleConnTimeout: 90 * time.Second,
|
|
}
|
|
if strings.HasPrefix(endpoint, "https://") && insecure {
|
|
transport.TLSClientConfig = &tls.Config{
|
|
InsecureSkipVerify: true,
|
|
}
|
|
}
|
|
return &http.Client{Transport: transport}
|
|
}
|
|
|
|
// New returns a new runner client.
|
|
func New(endpoint string, insecure bool, uuid, token string, opts ...connect.ClientOption) *HTTPClient {
|
|
baseURL := strings.TrimRight(endpoint, "/") + "/api/actions"
|
|
|
|
opts = append(opts, connect.WithInterceptors(connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
|
|
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
|
|
req.Header().Set("User-Agent", "gitea-runner/"+ver.Version())
|
|
if uuid != "" {
|
|
req.Header().Set(UUIDHeader, uuid)
|
|
}
|
|
if token != "" {
|
|
req.Header().Set(TokenHeader, token)
|
|
}
|
|
return next(ctx, req)
|
|
}
|
|
})))
|
|
|
|
httpClient := getHTTPClient(endpoint, insecure)
|
|
return &HTTPClient{
|
|
PingServiceClient: pingv1connect.NewPingServiceClient(
|
|
httpClient,
|
|
baseURL,
|
|
opts...,
|
|
),
|
|
RunnerServiceClient: runnerv1connect.NewRunnerServiceClient(
|
|
httpClient,
|
|
baseURL,
|
|
opts...,
|
|
),
|
|
endpoint: endpoint,
|
|
insecure: insecure,
|
|
}
|
|
}
|
|
|
|
func (c *HTTPClient) Address() string {
|
|
return c.endpoint
|
|
}
|
|
|
|
func (c *HTTPClient) Insecure() bool {
|
|
return c.insecure
|
|
}
|
|
|
|
var _ Client = (*HTTPClient)(nil)
|
|
|
|
// An HTTPClient manages communication with the runner API.
|
|
type HTTPClient struct {
|
|
pingv1connect.PingServiceClient
|
|
runnerv1connect.RunnerServiceClient
|
|
endpoint string
|
|
insecure bool
|
|
}
|