mirror of
https://gitea.com/gitea/act_runner
synced 2026-11-03 10:57:22 +01:00
Adds a weekly and on-demand workflow that runs the cross-compiled tests on Windows Server 2025 Core in a [dockur/windows](https://github.com/dockur/windows) QEMU VM, and fixes the Windows bugs it found in host and UNC paths, env handling, shell quoting, post-task scripts, health checks, checkout, action symlinks, step summaries, Git client certificates and docker mode from a Windows host. Host-mode steps now emit UTF-8, `bash` falls back to Git's bash instead of the WSL launcher, the runner can run as a native Windows service, steps can keep background helpers with `RUNNER_TRACKING_ID`, and Windows arm64 binaries are released. Fixes: https://gitea.com/gitea/runner/issues/1339 Fixes: https://gitea.com/gitea/runner/issues/637 Fixes: https://gitea.com/gitea/runner/issues/1172 Fixes: https://gitea.com/gitea/runner/issues/347 Reviewed-on: https://gitea.com/gitea/runner/pulls/1348 Reviewed-by: bircni <bircni@icloud.com>
102 lines
2.5 KiB
Go
102 lines
2.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package run
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"maps"
|
|
"os"
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"gitea.com/gitea/runner/act/common"
|
|
"gitea.com/gitea/runner/internal/pkg/process"
|
|
)
|
|
|
|
func (r *Runner) checkConfiguredHealth(ctx context.Context) (bool, string) {
|
|
script := r.cfg.HealthCheck.Script
|
|
if script == "" {
|
|
return true, "ok"
|
|
}
|
|
|
|
now := time.Now()
|
|
if r.now != nil {
|
|
now = r.now()
|
|
}
|
|
if !r.healthCheckLast.IsZero() && now.Sub(r.healthCheckLast) < r.cfg.HealthCheck.Interval {
|
|
return r.healthCheckReady, r.healthCheckReason
|
|
}
|
|
|
|
env := processEnvironment()
|
|
maps.Copy(env, r.envs)
|
|
env["GITEA_RUNNER_HEALTH_CHECK"] = "true"
|
|
env["GITEA_RUNNER_NAME"] = r.name
|
|
if r.client != nil {
|
|
env["GITEA_INSTANCE_URL"] = r.client.Address()
|
|
}
|
|
env["GITEA_RUNNER_RUNNING_JOBS"] = strconv.FormatInt(r.RunningCount(), 10)
|
|
|
|
runner := r.runHealthCheck
|
|
if runner == nil {
|
|
runner = executeHealthCheck
|
|
}
|
|
err := runner(ctx, script, r.cfg.HealthCheck.Timeout, env)
|
|
r.healthCheckLast = now
|
|
r.healthCheckReady = err == nil
|
|
if err != nil {
|
|
r.healthCheckReason = "runner health check failed: " + err.Error()
|
|
} else {
|
|
r.healthCheckReason = "ok"
|
|
}
|
|
return r.healthCheckReady, r.healthCheckReason
|
|
}
|
|
|
|
func executeHealthCheck(ctx context.Context, script string, timeout time.Duration, env map[string]string) error {
|
|
checkCtx, cancel := context.WithTimeout(ctx, timeout)
|
|
defer cancel()
|
|
cmd := scriptCommand(checkCtx, script)
|
|
cmd.Env = envListFromMap(env)
|
|
writer := common.NewLineWriter(func(line string) bool {
|
|
line = strings.TrimRight(line, "\r\n")
|
|
if line != "" {
|
|
common.Logger(ctx).Infof("health check: %s", line)
|
|
}
|
|
return true
|
|
})
|
|
cmd.Stdout = writer
|
|
cmd.Stderr = writer
|
|
|
|
treeKill := process.NewTreeKill(cmd)
|
|
if err := cmd.Start(); err != nil {
|
|
return fmt.Errorf("start: %w", err)
|
|
}
|
|
if killer, err := treeKill.Capture(cmd.Process); err == nil {
|
|
defer killer.Close()
|
|
}
|
|
err := cmd.Wait()
|
|
common.FlushWriter(writer)
|
|
if errors.Is(checkCtx.Err(), context.DeadlineExceeded) {
|
|
return fmt.Errorf("timed out after %s", timeout)
|
|
}
|
|
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
|
|
return fmt.Errorf("exited with code %d", exitErr.ExitCode())
|
|
}
|
|
return err
|
|
}
|
|
|
|
func processEnvironment() map[string]string {
|
|
environ := os.Environ()
|
|
env := make(map[string]string, len(environ))
|
|
for _, value := range environ {
|
|
if key, item, ok := strings.Cut(value, "="); ok {
|
|
env[key] = item
|
|
}
|
|
}
|
|
return env
|
|
}
|