mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-04 22:37:55 +00:00
Removes dead code and redundant logic and consolidates tests, so there is less to read and maintain. No behavior change. 1. **act/runner**: inline single-use wrappers, compile regexes once instead of per call, embed the trampoline as a string, drop the unused legacy result of `parseActionCommand` 2. **act/container**: `sanitizeConfig` and `mergeContainerConfigs` stop returning the configs they already mutate in place, drop never-set option fields and the unused `user` parameter of `ExecWithCmdLine` 3. **act/common and cache server**: drop the unused `Trace`/`Tracef` loggers and the short SHA of `FindGitRevision`, `RegisterJob` releases through `RevokeJob` 4. **daemon, poller and reporter**: one shutdown wait for both poll modes, drop an unreachable fetch timeout branch, guard the reporter's last report time with its existing lock instead of an atomic 5. **build**: drop unused Makefile and release workflow variables, collapse the goreleaser ignore list to the same build targets 6. **tests**: fold near-duplicate tests into tables with shared setup Throughout, hand-rolled logic gives way to `cmp.Or`, `strings.Cut`, `slices` and `min`/`max`. Reviewed-on: https://gitea.com/gitea/runner/pulls/1335 Reviewed-by: bircni <[email protected]> Co-authored-by: silverwind <[email protected]>
81 lines
2.4 KiB
Go
81 lines
2.4 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Copyright 2022 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package container
|
|
|
|
import (
|
|
"archive/tar"
|
|
"bufio"
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"gitea.com/gitea/runner/act/common"
|
|
|
|
"golang.org/x/text/encoding/unicode"
|
|
"golang.org/x/text/transform"
|
|
)
|
|
|
|
func parseEnvFile(e Container, srcPath string, env *map[string]string) common.Executor {
|
|
localEnv := *env
|
|
return func(ctx context.Context) error {
|
|
envTar, err := e.GetContainerArchive(ctx, srcPath)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
defer envTar.Close()
|
|
reader := tar.NewReader(envTar)
|
|
_, err = reader.Next()
|
|
if err != nil && err != io.EOF {
|
|
return err
|
|
}
|
|
// Decode by BOM: Windows PowerShell 5.1 redirection writes UTF-16, and some
|
|
// tools emit a UTF-8 BOM. Without a BOM the file is read as UTF-8, as before.
|
|
decoded := transform.NewReader(reader, unicode.BOMOverride(unicode.UTF8.NewDecoder()))
|
|
|
|
s := bufio.NewScanner(decoded)
|
|
// Default 64 KiB max token size is too small for realistic env-file lines; allow up to 16 MiB.
|
|
s.Buffer(make([]byte, 0, 64*1024), 16*1024*1024)
|
|
for s.Scan() {
|
|
line := s.Text()
|
|
// GitHub's runner ignores blank lines
|
|
if strings.TrimSpace(line) == "" {
|
|
continue
|
|
}
|
|
singleLineEnv := strings.Index(line, "=")
|
|
multiLineEnv := strings.Index(line, "<<")
|
|
switch {
|
|
case singleLineEnv != -1 && (multiLineEnv == -1 || singleLineEnv < multiLineEnv):
|
|
localEnv[line[:singleLineEnv]] = line[singleLineEnv+1:]
|
|
case multiLineEnv != -1:
|
|
var multiLineEnvContent []string
|
|
multiLineEnvDelimiter := line[multiLineEnv+2:]
|
|
delimiterFound := false
|
|
for s.Scan() {
|
|
content := s.Text()
|
|
if content == multiLineEnvDelimiter {
|
|
delimiterFound = true
|
|
break
|
|
}
|
|
multiLineEnvContent = append(multiLineEnvContent, content)
|
|
}
|
|
if err := s.Err(); err != nil {
|
|
return fmt.Errorf("reading env file: %w", err)
|
|
}
|
|
if !delimiterFound {
|
|
return fmt.Errorf("invalid format delimiter '%v' not found before end of file", multiLineEnvDelimiter)
|
|
}
|
|
localEnv[line[:multiLineEnv]] = strings.Join(multiLineEnvContent, "\n")
|
|
default:
|
|
return fmt.Errorf("invalid format '%v', expected a line with '=' or '<<'", line)
|
|
}
|
|
}
|
|
if err := s.Err(); err != nil {
|
|
return fmt.Errorf("reading env file: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
}
|