mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-06-22 09:44:24 +02:00
Compare commits
5 Commits
3815aad750
...
v1.0.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6023928876 | ||
|
|
014ce438c1 | ||
|
|
cf7e29c10d | ||
|
|
8a99506fed | ||
|
|
5873b8b054 |
@@ -71,6 +71,11 @@ jobs:
|
|||||||
- name: Echo the tag
|
- name: Echo the tag
|
||||||
run: echo "${{ env.DOCKER_ORG }}/runner:nightly${{ matrix.variant.tag_suffix }}"
|
run: echo "${{ env.DOCKER_ORG }}/runner:nightly${{ matrix.variant.tag_suffix }}"
|
||||||
|
|
||||||
|
- name: Get Meta
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
echo REPO_VERSION=$(git describe --tags --always | sed 's/-/+/' | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v7
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
@@ -83,3 +88,5 @@ jobs:
|
|||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ env.DOCKER_ORG }}/runner:nightly${{ matrix.variant.tag_suffix }}
|
${{ env.DOCKER_ORG }}/runner:nightly${{ matrix.variant.tag_suffix }}
|
||||||
|
build-args: |
|
||||||
|
VERSION=${{ steps.meta.outputs.REPO_VERSION }}
|
||||||
|
|||||||
@@ -96,3 +96,5 @@ jobs:
|
|||||||
linux/arm64
|
linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.docker_meta.outputs.tags }}
|
tags: ${{ steps.docker_meta.outputs.tags }}
|
||||||
|
build-args: |
|
||||||
|
VERSION=${{ steps.docker_meta.outputs.version }}
|
||||||
|
|||||||
16
Dockerfile
16
Dockerfile
@@ -19,6 +19,11 @@ RUN make clean && make build
|
|||||||
#
|
#
|
||||||
FROM docker:29-dind AS dind
|
FROM docker:29-dind AS dind
|
||||||
|
|
||||||
|
ARG VERSION=dev
|
||||||
|
|
||||||
|
LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
||||||
|
LABEL org.opencontainers.image.version="${VERSION}"
|
||||||
|
|
||||||
RUN apk add --no-cache s6 bash git tzdata
|
RUN apk add --no-cache s6 bash git tzdata
|
||||||
|
|
||||||
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
||||||
@@ -34,6 +39,11 @@ ENTRYPOINT ["s6-svscan","/etc/s6"]
|
|||||||
#
|
#
|
||||||
FROM docker:29-dind-rootless AS dind-rootless
|
FROM docker:29-dind-rootless AS dind-rootless
|
||||||
|
|
||||||
|
ARG VERSION=dev
|
||||||
|
|
||||||
|
LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
||||||
|
LABEL org.opencontainers.image.version="${VERSION}"
|
||||||
|
|
||||||
USER root
|
USER root
|
||||||
RUN apk add --no-cache s6 bash git tzdata
|
RUN apk add --no-cache s6 bash git tzdata
|
||||||
|
|
||||||
@@ -54,6 +64,12 @@ ENTRYPOINT ["s6-svscan","/etc/s6"]
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
FROM alpine AS basic
|
FROM alpine AS basic
|
||||||
|
|
||||||
|
ARG VERSION=dev
|
||||||
|
|
||||||
|
LABEL org.opencontainers.image.source="https://gitea.com/gitea/runner"
|
||||||
|
LABEL org.opencontainers.image.version="${VERSION}"
|
||||||
|
|
||||||
RUN apk add --no-cache tini bash git tzdata
|
RUN apk add --no-cache tini bash git tzdata
|
||||||
|
|
||||||
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
COPY --from=builder /opt/src/runner/gitea-runner /usr/local/bin/gitea-runner
|
||||||
|
|||||||
@@ -431,6 +431,7 @@ func (h *Handler) upload(w http.ResponseWriter, r *http.Request, params httprout
|
|||||||
}
|
}
|
||||||
if err := h.storage.Write(cache.ID, start, r.Body); err != nil {
|
if err := h.storage.Write(cache.ID, start, r.Body); err != nil {
|
||||||
h.responseJSON(w, r, 500, err)
|
h.responseJSON(w, r, 500, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
h.useCache(id)
|
h.useCache(id)
|
||||||
h.responseJSON(w, r, 200)
|
h.responseJSON(w, r, 200)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -338,6 +339,54 @@ func TestHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("upload write failure returns only error", func(t *testing.T) {
|
||||||
|
key := strings.ToLower(t.Name())
|
||||||
|
version := "c19da02a2bd7e77277f1ac29ab45c09b7d46a4ee758284e26bb3045ad11d9d20"
|
||||||
|
var id uint64
|
||||||
|
{
|
||||||
|
body, err := json.Marshal(&Request{
|
||||||
|
Key: key,
|
||||||
|
Version: version,
|
||||||
|
Size: 100,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
resp, err := testClient.Post(base+"/caches", "application/json", bytes.NewReader(body))
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
require.Equal(t, 200, resp.StatusCode)
|
||||||
|
|
||||||
|
got := struct {
|
||||||
|
CacheID uint64 `json:"cacheId"`
|
||||||
|
}{}
|
||||||
|
require.NoError(t, json.NewDecoder(resp.Body).Decode(&got))
|
||||||
|
id = got.CacheID
|
||||||
|
}
|
||||||
|
|
||||||
|
storageFile := filepath.Join(dir, "not-a-directory")
|
||||||
|
require.NoError(t, os.WriteFile(storageFile, []byte("blocked"), 0o600))
|
||||||
|
originalStorage := handler.storage
|
||||||
|
handler.storage = &Storage{rootDir: storageFile}
|
||||||
|
defer func() {
|
||||||
|
handler.storage = originalStorage
|
||||||
|
}()
|
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodPatch,
|
||||||
|
fmt.Sprintf("%s/caches/%d", base, id), bytes.NewReader(make([]byte, 100)))
|
||||||
|
require.NoError(t, err)
|
||||||
|
req.Header.Set("Content-Type", "application/octet-stream")
|
||||||
|
req.Header.Set("Content-Range", "bytes 0-99/*")
|
||||||
|
resp, err := testClient.Do(req)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
require.Equal(t, 500, resp.StatusCode)
|
||||||
|
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
var got map[string]string
|
||||||
|
require.NoError(t, json.Unmarshal(body, &got))
|
||||||
|
assert.NotEmpty(t, got["error"])
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("commit early", func(t *testing.T) {
|
t.Run("commit early", func(t *testing.T) {
|
||||||
key := strings.ToLower(t.Name())
|
key := strings.ToLower(t.Name())
|
||||||
version := "c19da02a2bd7e77277f1ac29ab45c09b7d46a4ee758284e26bb3045ad11d9d20"
|
version := "c19da02a2bd7e77277f1ac29ab45c09b7d46a4ee758284e26bb3045ad11d9d20"
|
||||||
|
|||||||
@@ -1,146 +0,0 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
||||||
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Style is a specific style
|
|
||||||
type Style int
|
|
||||||
|
|
||||||
// Styles
|
|
||||||
const (
|
|
||||||
StyleDoubleLine = iota
|
|
||||||
StyleSingleLine
|
|
||||||
StyleDashedLine
|
|
||||||
StyleNoLine
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewPen creates a new pen
|
|
||||||
func NewPen(style Style, color int) *Pen {
|
|
||||||
bgcolor := 49
|
|
||||||
if os.Getenv("CLICOLOR") == "0" {
|
|
||||||
color = 0
|
|
||||||
bgcolor = 0
|
|
||||||
}
|
|
||||||
return &Pen{
|
|
||||||
style: style,
|
|
||||||
color: color,
|
|
||||||
bgcolor: bgcolor,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type styleDef struct {
|
|
||||||
cornerTL string
|
|
||||||
cornerTR string
|
|
||||||
cornerBL string
|
|
||||||
cornerBR string
|
|
||||||
lineH string
|
|
||||||
lineV string
|
|
||||||
}
|
|
||||||
|
|
||||||
var styleDefs = []styleDef{
|
|
||||||
{"\u2554", "\u2557", "\u255a", "\u255d", "\u2550", "\u2551"},
|
|
||||||
{"\u256d", "\u256e", "\u2570", "\u256f", "\u2500", "\u2502"},
|
|
||||||
{"\u250c", "\u2510", "\u2514", "\u2518", "\u254c", "\u254e"},
|
|
||||||
{" ", " ", " ", " ", " ", " "},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pen struct
|
|
||||||
type Pen struct {
|
|
||||||
style Style
|
|
||||||
color int
|
|
||||||
bgcolor int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drawing struct
|
|
||||||
type Drawing struct {
|
|
||||||
buf *strings.Builder
|
|
||||||
width int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pen) drawTopBars(buf io.Writer, labels ...string) {
|
|
||||||
style := styleDefs[p.style]
|
|
||||||
for _, label := range labels {
|
|
||||||
bar := strings.Repeat(style.lineH, len(label)+2)
|
|
||||||
fmt.Fprintf(buf, " ")
|
|
||||||
fmt.Fprintf(buf, "\x1b[%d;%dm", p.color, p.bgcolor)
|
|
||||||
fmt.Fprintf(buf, "%s%s%s", style.cornerTL, bar, style.cornerTR)
|
|
||||||
fmt.Fprintf(buf, "\x1b[%dm", 0)
|
|
||||||
}
|
|
||||||
fmt.Fprintf(buf, "\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pen) drawBottomBars(buf io.Writer, labels ...string) {
|
|
||||||
style := styleDefs[p.style]
|
|
||||||
for _, label := range labels {
|
|
||||||
bar := strings.Repeat(style.lineH, len(label)+2)
|
|
||||||
fmt.Fprintf(buf, " ")
|
|
||||||
fmt.Fprintf(buf, "\x1b[%d;%dm", p.color, p.bgcolor)
|
|
||||||
fmt.Fprintf(buf, "%s%s%s", style.cornerBL, bar, style.cornerBR)
|
|
||||||
fmt.Fprintf(buf, "\x1b[%dm", 0)
|
|
||||||
}
|
|
||||||
fmt.Fprintf(buf, "\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pen) drawLabels(buf io.Writer, labels ...string) {
|
|
||||||
style := styleDefs[p.style]
|
|
||||||
for _, label := range labels {
|
|
||||||
fmt.Fprintf(buf, " ")
|
|
||||||
fmt.Fprintf(buf, "\x1b[%d;%dm", p.color, p.bgcolor)
|
|
||||||
fmt.Fprintf(buf, "%s %s %s", style.lineV, label, style.lineV)
|
|
||||||
fmt.Fprintf(buf, "\x1b[%dm", 0)
|
|
||||||
}
|
|
||||||
fmt.Fprintf(buf, "\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
// DrawArrow between boxes
|
|
||||||
func (p *Pen) DrawArrow() *Drawing {
|
|
||||||
drawing := &Drawing{
|
|
||||||
buf: new(strings.Builder),
|
|
||||||
width: 1,
|
|
||||||
}
|
|
||||||
fmt.Fprintf(drawing.buf, "\x1b[%dm", p.color)
|
|
||||||
fmt.Fprintf(drawing.buf, "\u2b07")
|
|
||||||
fmt.Fprintf(drawing.buf, "\x1b[%dm", 0)
|
|
||||||
return drawing
|
|
||||||
}
|
|
||||||
|
|
||||||
// DrawBoxes to draw boxes
|
|
||||||
func (p *Pen) DrawBoxes(labels ...string) *Drawing {
|
|
||||||
width := 0
|
|
||||||
for _, l := range labels {
|
|
||||||
width += len(l) + 2 + 2 + 1
|
|
||||||
}
|
|
||||||
drawing := &Drawing{
|
|
||||||
buf: new(strings.Builder),
|
|
||||||
width: width,
|
|
||||||
}
|
|
||||||
p.drawTopBars(drawing.buf, labels...)
|
|
||||||
p.drawLabels(drawing.buf, labels...)
|
|
||||||
p.drawBottomBars(drawing.buf, labels...)
|
|
||||||
|
|
||||||
return drawing
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw to writer
|
|
||||||
func (d *Drawing) Draw(writer io.Writer, centerOnWidth int) {
|
|
||||||
padSize := max((centerOnWidth-d.GetWidth())/2, 0)
|
|
||||||
for l := range strings.SplitSeq(d.buf.String(), "\n") {
|
|
||||||
if len(l) > 0 {
|
|
||||||
padding := strings.Repeat(" ", padSize)
|
|
||||||
fmt.Fprintf(writer, "%s%s\n", padding, l)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetWidth of drawing
|
|
||||||
func (d *Drawing) GetWidth() int {
|
|
||||||
return d.width
|
|
||||||
}
|
|
||||||
@@ -12,24 +12,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Warning that implements `error` but safe to ignore
|
|
||||||
type Warning struct {
|
|
||||||
Message string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error the contract for error
|
|
||||||
func (w Warning) Error() string {
|
|
||||||
return w.Message
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warningf create a warning
|
|
||||||
func Warningf(format string, args ...any) Warning {
|
|
||||||
w := Warning{
|
|
||||||
Message: fmt.Sprintf(format, args...),
|
|
||||||
}
|
|
||||||
return w
|
|
||||||
}
|
|
||||||
|
|
||||||
// Executor define contract for the steps of a workflow
|
// Executor define contract for the steps of a workflow
|
||||||
type Executor func(ctx context.Context) error
|
type Executor func(ctx context.Context) error
|
||||||
|
|
||||||
@@ -162,14 +144,8 @@ func NewParallelExecutor(parallel int, executors ...Executor) Executor {
|
|||||||
// Then runs another executor if this executor succeeds
|
// Then runs another executor if this executor succeeds
|
||||||
func (e Executor) Then(then Executor) Executor {
|
func (e Executor) Then(then Executor) Executor {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
err := e(ctx)
|
if err := e(ctx); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
switch err.(type) {
|
|
||||||
case Warning:
|
|
||||||
Logger(ctx).Warning(err.Error())
|
|
||||||
default:
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
||||||
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CopyFile copy file
|
|
||||||
func CopyFile(source, dest string) (err error) {
|
|
||||||
sourcefile, err := os.Open(source)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer sourcefile.Close()
|
|
||||||
|
|
||||||
destfile, err := os.Create(dest)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer destfile.Close()
|
|
||||||
|
|
||||||
_, err = io.Copy(destfile, sourcefile)
|
|
||||||
if err == nil {
|
|
||||||
sourceinfo, err := os.Stat(source)
|
|
||||||
if err != nil {
|
|
||||||
_ = os.Chmod(dest, sourceinfo.Mode())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// CopyDir recursive copy of directory
|
|
||||||
func CopyDir(source, dest string) (err error) {
|
|
||||||
// get properties of source dir
|
|
||||||
sourceinfo, err := os.Stat(source)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// create dest dir
|
|
||||||
|
|
||||||
err = os.MkdirAll(dest, sourceinfo.Mode())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
objects, err := os.ReadDir(source)
|
|
||||||
|
|
||||||
for _, obj := range objects {
|
|
||||||
sourcefilepointer := source + "/" + obj.Name()
|
|
||||||
|
|
||||||
destinationfilepointer := dest + "/" + obj.Name()
|
|
||||||
|
|
||||||
if obj.IsDir() {
|
|
||||||
// create sub-directories - recursively
|
|
||||||
err = CopyDir(sourcefilepointer, destinationfilepointer)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err) //nolint:forbidigo // pre-existing issue from nektos/act
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// perform copy
|
|
||||||
err = CopyFile(sourcefilepointer, destinationfilepointer)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err) //nolint:forbidigo // pre-existing issue from nektos/act
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -968,22 +969,7 @@ func (cr *containerReference) sanitizeConfig(ctx context.Context, config *contai
|
|||||||
logger := common.Logger(ctx)
|
logger := common.Logger(ctx)
|
||||||
|
|
||||||
if len(cr.input.ValidVolumes) > 0 {
|
if len(cr.input.ValidVolumes) > 0 {
|
||||||
globs := make([]glob.Glob, 0, len(cr.input.ValidVolumes))
|
matcher := newValidVolumeMatcher(ctx, cr.input.ValidVolumes)
|
||||||
for _, v := range cr.input.ValidVolumes {
|
|
||||||
if g, err := glob.Compile(v); err != nil {
|
|
||||||
logger.Errorf("create glob from %s error: %v", v, err)
|
|
||||||
} else {
|
|
||||||
globs = append(globs, g)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isValid := func(v string) bool {
|
|
||||||
for _, g := range globs {
|
|
||||||
if g.Match(v) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
// sanitize binds
|
// sanitize binds
|
||||||
sanitizedBinds := make([]string, 0, len(hostConfig.Binds))
|
sanitizedBinds := make([]string, 0, len(hostConfig.Binds))
|
||||||
for _, bind := range hostConfig.Binds {
|
for _, bind := range hostConfig.Binds {
|
||||||
@@ -997,7 +983,7 @@ func (cr *containerReference) sanitizeConfig(ctx context.Context, config *contai
|
|||||||
sanitizedBinds = append(sanitizedBinds, bind)
|
sanitizedBinds = append(sanitizedBinds, bind)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if isValid(parsed.Source) {
|
if matcher.isValid(parsed.Source, mount.Type(parsed.Type)) {
|
||||||
sanitizedBinds = append(sanitizedBinds, bind)
|
sanitizedBinds = append(sanitizedBinds, bind)
|
||||||
} else {
|
} else {
|
||||||
logger.Warnf("[%s] is not a valid volume, will be ignored", parsed.Source)
|
logger.Warnf("[%s] is not a valid volume, will be ignored", parsed.Source)
|
||||||
@@ -1007,7 +993,7 @@ func (cr *containerReference) sanitizeConfig(ctx context.Context, config *contai
|
|||||||
// sanitize mounts
|
// sanitize mounts
|
||||||
sanitizedMounts := make([]mount.Mount, 0, len(hostConfig.Mounts))
|
sanitizedMounts := make([]mount.Mount, 0, len(hostConfig.Mounts))
|
||||||
for _, mt := range hostConfig.Mounts {
|
for _, mt := range hostConfig.Mounts {
|
||||||
if isValid(mt.Source) {
|
if matcher.isValid(mt.Source, mt.Type) {
|
||||||
sanitizedMounts = append(sanitizedMounts, mt)
|
sanitizedMounts = append(sanitizedMounts, mt)
|
||||||
} else {
|
} else {
|
||||||
logger.Warnf("[%s] is not a valid volume, will be ignored", mt.Source)
|
logger.Warnf("[%s] is not a valid volume, will be ignored", mt.Source)
|
||||||
@@ -1021,3 +1007,129 @@ func (cr *containerReference) sanitizeConfig(ctx context.Context, config *contai
|
|||||||
|
|
||||||
return config, hostConfig
|
return config, hostConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type validVolumeMatcher struct {
|
||||||
|
allowAll bool
|
||||||
|
named []glob.Glob
|
||||||
|
host []glob.Glob
|
||||||
|
}
|
||||||
|
|
||||||
|
func newValidVolumeMatcher(ctx context.Context, validVolumes []string) validVolumeMatcher {
|
||||||
|
logger := common.Logger(ctx)
|
||||||
|
ret := validVolumeMatcher{
|
||||||
|
named: make([]glob.Glob, 0, len(validVolumes)),
|
||||||
|
host: make([]glob.Glob, 0, len(validVolumes)),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range validVolumes {
|
||||||
|
if v == "**" {
|
||||||
|
ret.allowAll = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !isHostVolumePattern(v) {
|
||||||
|
if g, err := glob.Compile(v); err != nil {
|
||||||
|
logger.Errorf("create glob from %s error: %v", v, err)
|
||||||
|
} else {
|
||||||
|
ret.named = append(ret.named, g)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
normalized, err := normalizeHostVolumePath(v)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("normalize volume pattern %s error: %v", v, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if g, err := glob.Compile(normalized); err != nil {
|
||||||
|
logger.Errorf("create glob from %s error: %v", normalized, err)
|
||||||
|
} else {
|
||||||
|
ret.host = append(ret.host, g)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m validVolumeMatcher) isValid(source string, sourceType mount.Type) bool {
|
||||||
|
if m.allowAll {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if isHostVolumeSource(source, sourceType) {
|
||||||
|
normalized, err := normalizeHostVolumePath(source)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, g := range m.host {
|
||||||
|
if g.Match(normalized) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, g := range m.named {
|
||||||
|
if g.Match(source) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isHostVolumePattern(pattern string) bool {
|
||||||
|
return filepath.IsAbs(pattern) ||
|
||||||
|
strings.HasPrefix(pattern, "."+string(filepath.Separator)) ||
|
||||||
|
strings.HasPrefix(pattern, ".."+string(filepath.Separator)) ||
|
||||||
|
strings.Contains(pattern, "/") ||
|
||||||
|
strings.Contains(pattern, `\`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isHostVolumeSource(source string, sourceType mount.Type) bool {
|
||||||
|
if sourceType == mount.TypeBind {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if sourceType == mount.TypeVolume {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return isHostVolumePattern(source)
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeHostVolumePath(path string) (string, error) {
|
||||||
|
abs, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return evalSymlinksExistingPrefix(abs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func evalSymlinksExistingPrefix(path string) (string, error) {
|
||||||
|
resolved, err := filepath.EvalSymlinks(path)
|
||||||
|
if err == nil {
|
||||||
|
return filepath.Clean(resolved), nil
|
||||||
|
}
|
||||||
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
current := path
|
||||||
|
var missing []string
|
||||||
|
for {
|
||||||
|
_, err := os.Lstat(current)
|
||||||
|
if err == nil {
|
||||||
|
resolved, err := filepath.EvalSymlinks(current)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
for _, name := range slices.Backward(missing) {
|
||||||
|
resolved = filepath.Join(resolved, name)
|
||||||
|
}
|
||||||
|
return filepath.Clean(resolved), nil
|
||||||
|
}
|
||||||
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
parent := filepath.Dir(current)
|
||||||
|
if parent == current {
|
||||||
|
return filepath.Clean(path), nil
|
||||||
|
}
|
||||||
|
missing = append(missing, filepath.Base(current))
|
||||||
|
current = parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -375,3 +377,40 @@ func TestCheckVolumes(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCheckVolumesRejectsEscapingHostPaths(t *testing.T) {
|
||||||
|
logger, _ := test.NewNullLogger()
|
||||||
|
ctx := common.WithLogger(context.Background(), logger)
|
||||||
|
|
||||||
|
base := t.TempDir()
|
||||||
|
allowed := filepath.Join(base, "allowed")
|
||||||
|
denied := filepath.Join(base, "denied")
|
||||||
|
require.NoError(t, os.MkdirAll(allowed, 0o700))
|
||||||
|
require.NoError(t, os.MkdirAll(denied, 0o700))
|
||||||
|
|
||||||
|
cr := &containerReference{
|
||||||
|
input: &NewContainerInput{
|
||||||
|
ValidVolumes: []string{filepath.Join(allowed, "**")},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
escapingPath := allowed + string(filepath.Separator) + ".." + string(filepath.Separator) + "denied"
|
||||||
|
_, hostConf := cr.sanitizeConfig(ctx, &container.Config{}, &container.HostConfig{
|
||||||
|
Binds: []string{escapingPath + ":/mnt"},
|
||||||
|
})
|
||||||
|
assert.Empty(t, hostConf.Binds)
|
||||||
|
|
||||||
|
linkPath := filepath.Join(allowed, "link")
|
||||||
|
if err := os.Symlink(denied, linkPath); err != nil {
|
||||||
|
t.Skipf("cannot create symlink: %v", err)
|
||||||
|
}
|
||||||
|
_, hostConf = cr.sanitizeConfig(ctx, &container.Config{}, &container.HostConfig{
|
||||||
|
Binds: []string{linkPath + ":/mnt"},
|
||||||
|
})
|
||||||
|
assert.Empty(t, hostConf.Binds)
|
||||||
|
|
||||||
|
_, hostConf = cr.sanitizeConfig(ctx, &container.Config{}, &container.HostConfig{
|
||||||
|
Binds: []string{filepath.Join(linkPath, "missing") + ":/mnt"},
|
||||||
|
})
|
||||||
|
assert.Empty(t, hostConf.Binds)
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,13 +37,13 @@ type HostEnvironment struct {
|
|||||||
TmpDir string
|
TmpDir string
|
||||||
ToolCache string
|
ToolCache string
|
||||||
Workdir string
|
Workdir string
|
||||||
// BindWorkdir is true when the app runner mounts the workspace on the host and
|
// CleanWorkdir means teardown owns Workdir and may delete it. Leave false
|
||||||
// deletes the task directory after the job; host teardown must not remove Workdir.
|
// when Workdir points at a caller-owned checkout (e.g. `act` local mode).
|
||||||
BindWorkdir bool
|
CleanWorkdir bool
|
||||||
ActPath string
|
ActPath string
|
||||||
CleanUp func()
|
CleanUp func()
|
||||||
StdOut io.Writer
|
StdOut io.Writer
|
||||||
AllocatePTY bool // allocate a pseudo-TTY for each step's process
|
AllocatePTY bool // allocate a pseudo-TTY for each step's process
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
runningPIDs map[int]struct{}
|
runningPIDs map[int]struct{}
|
||||||
@@ -483,7 +483,7 @@ func (e *HostEnvironment) Remove() common.Executor {
|
|||||||
logger.Warnf("failed to remove host misc state %s: %v", e.Path, err)
|
logger.Warnf("failed to remove host misc state %s: %v", e.Path, err)
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
if !e.BindWorkdir && e.Workdir != "" {
|
if e.CleanWorkdir {
|
||||||
if err := removePathWithRetry(ctx, e.Workdir); err != nil {
|
if err := removePathWithRetry(ctx, e.Workdir); err != nil {
|
||||||
logger.Warnf("failed to remove host workspace %s: %v", e.Workdir, err)
|
logger.Warnf("failed to remove host workspace %s: %v", e.Workdir, err)
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ func TestHostEnvironmentAllocatePTY(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHostEnvironmentRemoveCleansWorkdir(t *testing.T) {
|
func TestHostEnvironmentRemovePreservesWorkdirByDefault(t *testing.T) {
|
||||||
logger := logrus.New()
|
logger := logrus.New()
|
||||||
ctx := common.WithLogger(context.Background(), logrus.NewEntry(logger))
|
ctx := common.WithLogger(context.Background(), logrus.NewEntry(logger))
|
||||||
base := t.TempDir()
|
base := t.TempDir()
|
||||||
@@ -152,9 +152,8 @@ func TestHostEnvironmentRemoveCleansWorkdir(t *testing.T) {
|
|||||||
require.NoError(t, os.MkdirAll(workdir, 0o700))
|
require.NoError(t, os.MkdirAll(workdir, 0o700))
|
||||||
|
|
||||||
e := &HostEnvironment{
|
e := &HostEnvironment{
|
||||||
Path: path,
|
Path: path,
|
||||||
Workdir: workdir,
|
Workdir: workdir,
|
||||||
BindWorkdir: false,
|
|
||||||
CleanUp: func() {
|
CleanUp: func() {
|
||||||
_ = os.RemoveAll(miscRoot)
|
_ = os.RemoveAll(miscRoot)
|
||||||
},
|
},
|
||||||
@@ -162,10 +161,10 @@ func TestHostEnvironmentRemoveCleansWorkdir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
require.NoError(t, e.Remove()(ctx))
|
require.NoError(t, e.Remove()(ctx))
|
||||||
_, err := os.Stat(workdir)
|
_, err := os.Stat(workdir)
|
||||||
assert.ErrorIs(t, err, os.ErrNotExist)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHostEnvironmentRemoveSkipsWorkdirWhenBindWorkdir(t *testing.T) {
|
func TestHostEnvironmentRemoveCleansWorkdirWhenOwned(t *testing.T) {
|
||||||
logger := logrus.New()
|
logger := logrus.New()
|
||||||
ctx := common.WithLogger(context.Background(), logrus.NewEntry(logger))
|
ctx := common.WithLogger(context.Background(), logrus.NewEntry(logger))
|
||||||
base := t.TempDir()
|
base := t.TempDir()
|
||||||
@@ -176,9 +175,9 @@ func TestHostEnvironmentRemoveSkipsWorkdirWhenBindWorkdir(t *testing.T) {
|
|||||||
require.NoError(t, os.MkdirAll(workdir, 0o700))
|
require.NoError(t, os.MkdirAll(workdir, 0o700))
|
||||||
|
|
||||||
e := &HostEnvironment{
|
e := &HostEnvironment{
|
||||||
Path: path,
|
Path: path,
|
||||||
Workdir: workdir,
|
Workdir: workdir,
|
||||||
BindWorkdir: true,
|
CleanWorkdir: true,
|
||||||
CleanUp: func() {
|
CleanUp: func() {
|
||||||
_ = os.RemoveAll(miscRoot)
|
_ = os.RemoveAll(miscRoot)
|
||||||
},
|
},
|
||||||
@@ -186,5 +185,5 @@ func TestHostEnvironmentRemoveSkipsWorkdirWhenBindWorkdir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
require.NoError(t, e.Remove()(ctx))
|
require.NoError(t, e.Remove()(ctx))
|
||||||
_, err := os.Stat(workdir)
|
_, err := os.Stat(workdir)
|
||||||
require.NoError(t, err)
|
assert.ErrorIs(t, err, os.ErrNotExist)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ func parseEnvFile(e Container, srcPath string, env *map[string]string) common.Ex
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s := bufio.NewScanner(reader)
|
s := bufio.NewScanner(reader)
|
||||||
|
// 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() {
|
for s.Scan() {
|
||||||
line := s.Text()
|
line := s.Text()
|
||||||
singleLineEnv := strings.Index(line, "=")
|
singleLineEnv := strings.Index(line, "=")
|
||||||
@@ -50,6 +52,9 @@ func parseEnvFile(e Container, srcPath string, env *map[string]string) common.Ex
|
|||||||
}
|
}
|
||||||
multiLineEnvContent += content
|
multiLineEnvContent += content
|
||||||
}
|
}
|
||||||
|
if err := s.Err(); err != nil {
|
||||||
|
return fmt.Errorf("reading env file: %w", err)
|
||||||
|
}
|
||||||
if !delimiterFound {
|
if !delimiterFound {
|
||||||
return fmt.Errorf("invalid format delimiter '%v' not found before end of file", multiLineEnvDelimiter)
|
return fmt.Errorf("invalid format delimiter '%v' not found before end of file", multiLineEnvDelimiter)
|
||||||
}
|
}
|
||||||
@@ -58,6 +63,9 @@ func parseEnvFile(e Container, srcPath string, env *map[string]string) common.Ex
|
|||||||
return fmt.Errorf("invalid format '%v', expected a line with '=' or '<<'", line)
|
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)
|
||||||
|
}
|
||||||
env = &localEnv
|
env = &localEnv
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
75
act/container/parse_env_file_test.go
Normal file
75
act/container/parse_env_file_test.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newTestHostEnv(t *testing.T) (*HostEnvironment, string) {
|
||||||
|
t.Helper()
|
||||||
|
e := &HostEnvironment{Path: t.TempDir()}
|
||||||
|
return e, filepath.Join(e.Path, "envfile")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseEnvFileSingleLine(t *testing.T) {
|
||||||
|
e, envPath := newTestHostEnv(t)
|
||||||
|
require.NoError(t, os.WriteFile(envPath, []byte("FOO=bar\nBAZ=qux\n"), 0o600))
|
||||||
|
|
||||||
|
env := map[string]string{}
|
||||||
|
require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background()))
|
||||||
|
assert.Equal(t, "bar", env["FOO"])
|
||||||
|
assert.Equal(t, "qux", env["BAZ"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseEnvFileMultiLine(t *testing.T) {
|
||||||
|
e, envPath := newTestHostEnv(t)
|
||||||
|
content := "FOO<<EOF\nline1\nline2\nEOF\n"
|
||||||
|
require.NoError(t, os.WriteFile(envPath, []byte(content), 0o600))
|
||||||
|
|
||||||
|
env := map[string]string{}
|
||||||
|
require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background()))
|
||||||
|
assert.Equal(t, "line1\nline2", env["FOO"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseEnvFileLargeValueWithinLimit(t *testing.T) {
|
||||||
|
e, envPath := newTestHostEnv(t)
|
||||||
|
big := strings.Repeat("x", 2*1024*1024)
|
||||||
|
content := "FOO<<EOF\n" + big + "\nEOF\n"
|
||||||
|
require.NoError(t, os.WriteFile(envPath, []byte(content), 0o600))
|
||||||
|
|
||||||
|
env := map[string]string{}
|
||||||
|
require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background()))
|
||||||
|
assert.Equal(t, big, env["FOO"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseEnvFileLineExceedsBufferReportsScannerError(t *testing.T) {
|
||||||
|
e, envPath := newTestHostEnv(t)
|
||||||
|
tooBig := strings.Repeat("x", 17*1024*1024) // over the 16 MiB cap
|
||||||
|
content := "FOO<<EOF\n" + tooBig + "\nEOF\n"
|
||||||
|
require.NoError(t, os.WriteFile(envPath, []byte(content), 0o600))
|
||||||
|
|
||||||
|
env := map[string]string{}
|
||||||
|
err := parseEnvFile(e, envPath, &env)(context.Background())
|
||||||
|
require.ErrorIs(t, err, bufio.ErrTooLong)
|
||||||
|
assert.Contains(t, err.Error(), "reading env file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseEnvFileMissingDelimiter(t *testing.T) {
|
||||||
|
e, envPath := newTestHostEnv(t)
|
||||||
|
require.NoError(t, os.WriteFile(envPath, []byte("FOO<<EOF\nline1\nline2\n"), 0o600))
|
||||||
|
|
||||||
|
env := map[string]string{}
|
||||||
|
err := parseEnvFile(e, envPath, &env)(context.Background())
|
||||||
|
require.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "delimiter")
|
||||||
|
}
|
||||||
@@ -4,18 +4,6 @@
|
|||||||
|
|
||||||
package lookpath
|
package lookpath
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
type Env interface {
|
type Env interface {
|
||||||
Getenv(name string) string
|
Getenv(name string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
type defaultEnv struct{}
|
|
||||||
|
|
||||||
func (*defaultEnv) Getenv(name string) string {
|
|
||||||
return os.Getenv(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func LookPath(file string) (string, error) {
|
|
||||||
return LookPath2(file, &defaultEnv{})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
||||||
// Copyright 2024 The nektos/act Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package runner
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"io"
|
|
||||||
"path"
|
|
||||||
|
|
||||||
git "github.com/go-git/go-git/v5"
|
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GoGitActionCacheOfflineMode struct {
|
|
||||||
Parent GoGitActionCache
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c GoGitActionCacheOfflineMode) Fetch(ctx context.Context, cacheDir, url, ref, token string) (string, error) {
|
|
||||||
sha, fetchErr := c.Parent.Fetch(ctx, cacheDir, url, ref, token)
|
|
||||||
gitPath := path.Join(c.Parent.Path, safeFilename(cacheDir)+".git")
|
|
||||||
gogitrepo, err := git.PlainOpen(gitPath)
|
|
||||||
if err != nil {
|
|
||||||
return "", fetchErr
|
|
||||||
}
|
|
||||||
refName := plumbing.ReferenceName("refs/action-cache-offline/" + ref)
|
|
||||||
r, err := gogitrepo.Reference(refName, true)
|
|
||||||
if fetchErr == nil {
|
|
||||||
if err != nil || sha != r.Hash().String() {
|
|
||||||
if err == nil {
|
|
||||||
refName = r.Name()
|
|
||||||
}
|
|
||||||
ref := plumbing.NewHashReference(refName, plumbing.NewHash(sha))
|
|
||||||
_ = gogitrepo.Storer.SetReference(ref)
|
|
||||||
}
|
|
||||||
} else if err == nil {
|
|
||||||
return r.Hash().String(), nil
|
|
||||||
}
|
|
||||||
return sha, fetchErr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c GoGitActionCacheOfflineMode) GetTarArchive(ctx context.Context, cacheDir, sha, includePrefix string) (io.ReadCloser, error) {
|
|
||||||
return c.Parent.GetTarArchive(ctx, cacheDir, sha, includePrefix)
|
|
||||||
}
|
|
||||||
@@ -308,6 +308,11 @@ func getGitCloneToken(conf *Config, cloneURL string) string {
|
|||||||
// 1. cloneURL is from the same Gitea instance that the runner is registered to
|
// 1. cloneURL is from the same Gitea instance that the runner is registered to
|
||||||
// 2. the cloneURL does not have basic auth embedded
|
// 2. the cloneURL does not have basic auth embedded
|
||||||
func shouldCloneURLUseToken(instanceURL, cloneURL string) bool {
|
func shouldCloneURLUseToken(instanceURL, cloneURL string) bool {
|
||||||
|
if !strings.HasPrefix(instanceURL, "http://") &&
|
||||||
|
!strings.HasPrefix(instanceURL, "https://") {
|
||||||
|
instanceURL = "https://" + instanceURL
|
||||||
|
}
|
||||||
|
|
||||||
u1, err1 := url.Parse(instanceURL)
|
u1, err1 := url.Parse(instanceURL)
|
||||||
u2, err2 := url.Parse(cloneURL)
|
u2, err2 := url.Parse(cloneURL)
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
|
|||||||
@@ -123,6 +123,65 @@ func TestNewReusableWorkflowExecutorHoldsCloneLock(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetGitCloneTokenWithSchemalessGiteaInstance(t *testing.T) {
|
||||||
|
conf := &Config{
|
||||||
|
GitHubInstance: "gitea.example.net",
|
||||||
|
Secrets: map[string]string{
|
||||||
|
"GITEA_TOKEN": "token-value",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
token := getGitCloneToken(conf, "https://gitea.example.net/actions/tools")
|
||||||
|
|
||||||
|
require.Equal(t, "token-value", token)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestShouldCloneURLUseToken(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
instanceURL string
|
||||||
|
cloneURL string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "same host with schemaless instance",
|
||||||
|
instanceURL: "gitea.example.net",
|
||||||
|
cloneURL: "https://gitea.example.net/actions/tools",
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "same host with schemaless instance and port",
|
||||||
|
instanceURL: "gitea.example.net:3000",
|
||||||
|
cloneURL: "https://gitea.example.net:3000/actions/tools",
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "different host",
|
||||||
|
instanceURL: "gitea.example.net",
|
||||||
|
cloneURL: "https://github.com/actions/tools",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "embedded basic auth",
|
||||||
|
instanceURL: "gitea.example.net",
|
||||||
|
cloneURL: "https://user:pass@gitea.example.net/actions/tools",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid clone URL",
|
||||||
|
instanceURL: "gitea.example.net",
|
||||||
|
cloneURL: "://gitea.example.net/actions/tools",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
require.Equal(t, tt.want, shouldCloneURLUseToken(tt.instanceURL, tt.cloneURL))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func gitMust(t *testing.T, dir string, args ...string) {
|
func gitMust(t *testing.T, dir string, args ...string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
cmd := exec.Command("git", args...)
|
cmd := exec.Command("git", args...)
|
||||||
|
|||||||
@@ -220,12 +220,12 @@ func (rc *RunContext) startHostEnvironment() common.Executor {
|
|||||||
}
|
}
|
||||||
toolCache := filepath.Join(cacheDir, "tool_cache")
|
toolCache := filepath.Join(cacheDir, "tool_cache")
|
||||||
rc.JobContainer = &container.HostEnvironment{
|
rc.JobContainer = &container.HostEnvironment{
|
||||||
Path: path,
|
Path: path,
|
||||||
TmpDir: runnerTmp,
|
TmpDir: runnerTmp,
|
||||||
ToolCache: toolCache,
|
ToolCache: toolCache,
|
||||||
Workdir: rc.Config.Workdir,
|
Workdir: rc.Config.Workdir,
|
||||||
BindWorkdir: rc.Config.BindWorkdir,
|
CleanWorkdir: rc.Config.CleanWorkdir,
|
||||||
ActPath: actPath,
|
ActPath: actPath,
|
||||||
CleanUp: func() {
|
CleanUp: func() {
|
||||||
os.RemoveAll(miscpath)
|
os.RemoveAll(miscpath)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ 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
|
||||||
PlatformPicker func(labels []string) string // platform picker, it will take precedence over Platforms if isn't nil
|
PlatformPicker func(labels []string) string // platform picker, it will take precedence over Platforms if isn't nil
|
||||||
JobLoggerLevel *log.Level // the level of job logger
|
JobLoggerLevel *log.Level // the level of job logger
|
||||||
@@ -91,6 +92,17 @@ func (c Config) GetToken() string {
|
|||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultActionURL returns the host used for implicit remote actions.
|
||||||
|
func (c Config) DefaultActionURL() string {
|
||||||
|
if c.DefaultActionInstance != "" {
|
||||||
|
return c.DefaultActionInstance
|
||||||
|
}
|
||||||
|
if c.GitHubInstance != "" {
|
||||||
|
return c.GitHubInstance
|
||||||
|
}
|
||||||
|
return "github.com"
|
||||||
|
}
|
||||||
|
|
||||||
type caller struct {
|
type caller struct {
|
||||||
runContext *RunContext
|
runContext *RunContext
|
||||||
|
|
||||||
|
|||||||
@@ -113,9 +113,10 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actionDir := fmt.Sprintf("%s/%s", sar.RunContext.ActionCacheDir(), sar.Step.UsesHash())
|
actionDir := fmt.Sprintf("%s/%s", sar.RunContext.ActionCacheDir(), sar.Step.UsesHash())
|
||||||
token := getGitCloneToken(sar.getRunContext().Config, sar.remoteAction.CloneURL(sar.RunContext.Config.DefaultActionInstance))
|
defaultActionURL := sar.RunContext.Config.DefaultActionURL()
|
||||||
|
token := getGitCloneToken(sar.getRunContext().Config, sar.remoteAction.CloneURL(defaultActionURL))
|
||||||
gitClone := stepActionRemoteNewCloneExecutor(git.NewGitCloneExecutorInput{
|
gitClone := stepActionRemoteNewCloneExecutor(git.NewGitCloneExecutorInput{
|
||||||
URL: sar.remoteAction.CloneURL(sar.RunContext.Config.DefaultActionInstance),
|
URL: sar.remoteAction.CloneURL(defaultActionURL),
|
||||||
Ref: sar.remoteAction.Ref,
|
Ref: sar.remoteAction.Ref,
|
||||||
Dir: actionDir,
|
Dir: actionDir,
|
||||||
Token: token,
|
Token: token,
|
||||||
@@ -274,7 +275,7 @@ func (sar *stepActionRemote) cloneSkipTLS() bool {
|
|||||||
if sar.remoteAction.URL == "" {
|
if sar.remoteAction.URL == "" {
|
||||||
// Empty URL means the default action instance should be used
|
// Empty URL means the default action instance should be used
|
||||||
// Return true if the URL of the Gitea instance is the same as the URL of the default action instance
|
// Return true if the URL of the Gitea instance is the same as the URL of the default action instance
|
||||||
return sar.RunContext.Config.DefaultActionInstance == sar.RunContext.Config.GitHubInstance
|
return sar.RunContext.Config.DefaultActionURL() == sar.RunContext.Config.GitHubInstance
|
||||||
}
|
}
|
||||||
// Return true if the URL of the remote action is the same as the URL of the Gitea instance
|
// Return true if the URL of the remote action is the same as the URL of the Gitea instance
|
||||||
return sar.remoteAction.URL == sar.RunContext.Config.GitHubInstance
|
return sar.remoteAction.URL == sar.RunContext.Config.GitHubInstance
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"go.yaml.in/yaml/v4"
|
"go.yaml.in/yaml/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -434,6 +435,57 @@ func TestStepActionRemotePreThroughActionToken(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStepActionRemoteUsesGitHubInstanceWhenDefaultActionInstanceEmpty(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
var actualURL string
|
||||||
|
sarm := &stepActionRemoteMocks{}
|
||||||
|
|
||||||
|
origStepAtionRemoteNewCloneExecutor := stepActionRemoteNewCloneExecutor
|
||||||
|
stepActionRemoteNewCloneExecutor = func(input git.NewGitCloneExecutorInput) common.Executor {
|
||||||
|
return func(ctx context.Context) error {
|
||||||
|
actualURL = input.URL
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
stepActionRemoteNewCloneExecutor = origStepAtionRemoteNewCloneExecutor
|
||||||
|
}()
|
||||||
|
|
||||||
|
sar := &stepActionRemote{
|
||||||
|
Step: &model.Step{
|
||||||
|
Uses: "actions/setup-go@v4",
|
||||||
|
},
|
||||||
|
RunContext: &RunContext{
|
||||||
|
Config: &Config{
|
||||||
|
GitHubInstance: "gitea.example",
|
||||||
|
DefaultActionInstance: "",
|
||||||
|
ActionCacheDir: t.TempDir(),
|
||||||
|
},
|
||||||
|
Run: &model.Run{
|
||||||
|
JobID: "1",
|
||||||
|
Workflow: &model.Workflow{
|
||||||
|
Jobs: map[string]*model.Job{
|
||||||
|
"1": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
readAction: sarm.readAction,
|
||||||
|
}
|
||||||
|
|
||||||
|
suffixMatcher := func(suffix string) any {
|
||||||
|
return mock.MatchedBy(func(actionDir string) bool {
|
||||||
|
return strings.HasSuffix(actionDir, suffix)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
sarm.On("readAction", sar.Step, suffixMatcher(sar.Step.UsesHash()), "", mock.Anything, mock.Anything).Return(&model.Action{}, nil)
|
||||||
|
|
||||||
|
require.NoError(t, sar.prepareActionExecutor()(ctx))
|
||||||
|
assert.Equal(t, "https://gitea.example/actions/setup-go", actualURL)
|
||||||
|
sarm.AssertExpectations(t)
|
||||||
|
}
|
||||||
|
|
||||||
func TestStepActionRemotePost(t *testing.T) {
|
func TestStepActionRemotePost(t *testing.T) {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
||||||
// Copyright 2023 The nektos/act Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package workflowpattern
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
type TraceWriter interface {
|
|
||||||
Info(string, ...any)
|
|
||||||
}
|
|
||||||
|
|
||||||
type EmptyTraceWriter struct{}
|
|
||||||
|
|
||||||
func (*EmptyTraceWriter) Info(string, ...any) {
|
|
||||||
}
|
|
||||||
|
|
||||||
type StdOutTraceWriter struct{}
|
|
||||||
|
|
||||||
func (*StdOutTraceWriter) Info(format string, args ...any) {
|
|
||||||
fmt.Printf(format+"\n", args...) //nolint:forbidigo // pre-existing issue from nektos/act
|
|
||||||
}
|
|
||||||
@@ -1,199 +0,0 @@
|
|||||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
||||||
// Copyright 2023 The nektos/act Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package workflowpattern
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type WorkflowPattern struct {
|
|
||||||
Pattern string
|
|
||||||
Negative bool
|
|
||||||
Regex *regexp.Regexp
|
|
||||||
}
|
|
||||||
|
|
||||||
func CompilePattern(rawpattern string) (*WorkflowPattern, error) {
|
|
||||||
negative := false
|
|
||||||
pattern := rawpattern
|
|
||||||
if strings.HasPrefix(rawpattern, "!") {
|
|
||||||
negative = true
|
|
||||||
pattern = rawpattern[1:]
|
|
||||||
}
|
|
||||||
rpattern, err := PatternToRegex(pattern)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
regex, err := regexp.Compile(rpattern)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &WorkflowPattern{
|
|
||||||
Pattern: pattern,
|
|
||||||
Negative: negative,
|
|
||||||
Regex: regex,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func PatternToRegex(pattern string) (string, error) {
|
|
||||||
var rpattern strings.Builder
|
|
||||||
rpattern.WriteString("^")
|
|
||||||
pos := 0
|
|
||||||
errors := map[int]string{}
|
|
||||||
for pos < len(pattern) {
|
|
||||||
switch pattern[pos] {
|
|
||||||
case '*':
|
|
||||||
if pos+1 < len(pattern) && pattern[pos+1] == '*' {
|
|
||||||
if pos+2 < len(pattern) && pattern[pos+2] == '/' {
|
|
||||||
rpattern.WriteString("(.+/)?")
|
|
||||||
pos += 3
|
|
||||||
} else {
|
|
||||||
rpattern.WriteString(".*")
|
|
||||||
pos += 2
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rpattern.WriteString("[^/]*")
|
|
||||||
pos++
|
|
||||||
}
|
|
||||||
case '+', '?':
|
|
||||||
if pos > 0 {
|
|
||||||
rpattern.WriteByte(pattern[pos])
|
|
||||||
} else {
|
|
||||||
rpattern.WriteString(regexp.QuoteMeta(string([]byte{pattern[pos]})))
|
|
||||||
}
|
|
||||||
pos++
|
|
||||||
case '[':
|
|
||||||
rpattern.WriteByte(pattern[pos])
|
|
||||||
pos++
|
|
||||||
if pos < len(pattern) && pattern[pos] == ']' {
|
|
||||||
errors[pos] = "Unexpected empty brackets '[]'"
|
|
||||||
pos++
|
|
||||||
break
|
|
||||||
}
|
|
||||||
validChar := func(a, b, test byte) bool {
|
|
||||||
return test >= a && test <= b
|
|
||||||
}
|
|
||||||
startPos := pos
|
|
||||||
for pos < len(pattern) && pattern[pos] != ']' {
|
|
||||||
switch pattern[pos] {
|
|
||||||
case '-':
|
|
||||||
if pos <= startPos || pos+1 >= len(pattern) {
|
|
||||||
errors[pos] = "Invalid range"
|
|
||||||
pos++
|
|
||||||
break
|
|
||||||
}
|
|
||||||
validRange := func(a, b byte) bool {
|
|
||||||
return validChar(a, b, pattern[pos-1]) && validChar(a, b, pattern[pos+1]) && pattern[pos-1] <= pattern[pos+1]
|
|
||||||
}
|
|
||||||
if !validRange('A', 'z') && !validRange('0', '9') {
|
|
||||||
errors[pos] = "Ranges can only include a-z, A-Z, A-z, and 0-9"
|
|
||||||
pos++
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rpattern.WriteString(pattern[pos : pos+2])
|
|
||||||
pos += 2
|
|
||||||
default:
|
|
||||||
if !validChar('A', 'z', pattern[pos]) && !validChar('0', '9', pattern[pos]) {
|
|
||||||
errors[pos] = "Ranges can only include a-z, A-Z and 0-9"
|
|
||||||
pos++
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rpattern.WriteString(regexp.QuoteMeta(string([]byte{pattern[pos]})))
|
|
||||||
pos++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if pos >= len(pattern) || pattern[pos] != ']' {
|
|
||||||
errors[pos] = "Missing closing bracket ']' after '['"
|
|
||||||
pos++
|
|
||||||
}
|
|
||||||
rpattern.WriteString("]")
|
|
||||||
pos++
|
|
||||||
case '\\':
|
|
||||||
if pos+1 >= len(pattern) {
|
|
||||||
errors[pos] = "Missing symbol after \\"
|
|
||||||
pos++
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rpattern.WriteString(regexp.QuoteMeta(string([]byte{pattern[pos+1]})))
|
|
||||||
pos += 2
|
|
||||||
default:
|
|
||||||
rpattern.WriteString(regexp.QuoteMeta(string([]byte{pattern[pos]})))
|
|
||||||
pos++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(errors) > 0 {
|
|
||||||
var errorMessage strings.Builder
|
|
||||||
for position, err := range errors {
|
|
||||||
if errorMessage.Len() > 0 {
|
|
||||||
errorMessage.WriteString(", ")
|
|
||||||
}
|
|
||||||
fmt.Fprintf(&errorMessage, "Position: %d Error: %s", position, err)
|
|
||||||
}
|
|
||||||
return "", fmt.Errorf("invalid Pattern '%s': %s", pattern, errorMessage.String())
|
|
||||||
}
|
|
||||||
rpattern.WriteString("$")
|
|
||||||
return rpattern.String(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CompilePatterns(patterns ...string) ([]*WorkflowPattern, error) {
|
|
||||||
ret := []*WorkflowPattern{}
|
|
||||||
for _, pattern := range patterns {
|
|
||||||
cp, err := CompilePattern(pattern)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ret = append(ret, cp)
|
|
||||||
}
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns true if the workflow should be skipped paths/branches
|
|
||||||
func Skip(sequence []*WorkflowPattern, input []string, traceWriter TraceWriter) bool {
|
|
||||||
if len(sequence) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for _, file := range input {
|
|
||||||
matched := false
|
|
||||||
for _, item := range sequence {
|
|
||||||
if item.Regex.MatchString(file) {
|
|
||||||
pattern := item.Pattern
|
|
||||||
if item.Negative {
|
|
||||||
matched = false
|
|
||||||
traceWriter.Info("%s excluded by pattern %s", file, pattern)
|
|
||||||
} else {
|
|
||||||
matched = true
|
|
||||||
traceWriter.Info("%s included by pattern %s", file, pattern)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if matched {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns true if the workflow should be skipped paths-ignore/branches-ignore
|
|
||||||
func Filter(sequence []*WorkflowPattern, input []string, traceWriter TraceWriter) bool {
|
|
||||||
if len(sequence) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for _, file := range input {
|
|
||||||
matched := false
|
|
||||||
for _, item := range sequence {
|
|
||||||
if item.Regex.MatchString(file) == !item.Negative {
|
|
||||||
pattern := item.Pattern
|
|
||||||
traceWriter.Info("%s ignored by pattern %s", file, pattern)
|
|
||||||
matched = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !matched {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
@@ -1,418 +0,0 @@
|
|||||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
||||||
// Copyright 2023 The nektos/act Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package workflowpattern
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMatchPattern(t *testing.T) {
|
|
||||||
kases := []struct {
|
|
||||||
inputs []string
|
|
||||||
patterns []string
|
|
||||||
skipResult bool
|
|
||||||
filterResult bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
patterns: []string{"*"},
|
|
||||||
inputs: []string{"path/with/slash"},
|
|
||||||
skipResult: true,
|
|
||||||
filterResult: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"path/a", "path/b", "path/c"},
|
|
||||||
inputs: []string{"meta", "path/b", "otherfile"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"path/a", "path/b", "path/c"},
|
|
||||||
inputs: []string{"path/b"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"path/a", "path/b", "path/c"},
|
|
||||||
inputs: []string{"path/c", "path/b"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"path/a", "path/b", "path/c"},
|
|
||||||
inputs: []string{"path/c", "path/b", "path/a"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"path/a", "path/b", "path/c"},
|
|
||||||
inputs: []string{"path/c", "path/b", "path/d", "path/a"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{},
|
|
||||||
inputs: []string{},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"\\!file"},
|
|
||||||
inputs: []string{"!file"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"escape\\\\backslash"},
|
|
||||||
inputs: []string{"escape\\backslash"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{".yml"},
|
|
||||||
inputs: []string{"fyml"},
|
|
||||||
skipResult: true,
|
|
||||||
filterResult: false,
|
|
||||||
},
|
|
||||||
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#patterns-to-match-branches-and-tags
|
|
||||||
{
|
|
||||||
patterns: []string{"feature/*"},
|
|
||||||
inputs: []string{"feature/my-branch"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"feature/*"},
|
|
||||||
inputs: []string{"feature/your-branch"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"feature/**"},
|
|
||||||
inputs: []string{"feature/beta-a/my-branch"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"feature/**"},
|
|
||||||
inputs: []string{"feature/beta-a/my-branch"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"feature/**"},
|
|
||||||
inputs: []string{"feature/mona/the/octocat"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"main", "releases/mona-the-octocat"},
|
|
||||||
inputs: []string{"main"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"main", "releases/mona-the-octocat"},
|
|
||||||
inputs: []string{"releases/mona-the-octocat"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*"},
|
|
||||||
inputs: []string{"main"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*"},
|
|
||||||
inputs: []string{"releases"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**"},
|
|
||||||
inputs: []string{"all/the/branches"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**"},
|
|
||||||
inputs: []string{"every/tag"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*feature"},
|
|
||||||
inputs: []string{"mona-feature"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*feature"},
|
|
||||||
inputs: []string{"feature"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*feature"},
|
|
||||||
inputs: []string{"ver-10-feature"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"v2*"},
|
|
||||||
inputs: []string{"v2"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"v2*"},
|
|
||||||
inputs: []string{"v2.0"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"v2*"},
|
|
||||||
inputs: []string{"v2.9"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"v[12].[0-9]+.[0-9]+"},
|
|
||||||
inputs: []string{"v1.10.1"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"v[12].[0-9]+.[0-9]+"},
|
|
||||||
inputs: []string{"v2.0.0"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#patterns-to-match-file-paths
|
|
||||||
{
|
|
||||||
patterns: []string{"*"},
|
|
||||||
inputs: []string{"README.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*"},
|
|
||||||
inputs: []string{"server.rb"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.jsx?"},
|
|
||||||
inputs: []string{"page.js"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.jsx?"},
|
|
||||||
inputs: []string{"page.jsx"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**"},
|
|
||||||
inputs: []string{"all/the/files.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.js"},
|
|
||||||
inputs: []string{"app.js"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.js"},
|
|
||||||
inputs: []string{"index.js"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**.js"},
|
|
||||||
inputs: []string{"index.js"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**.js"},
|
|
||||||
inputs: []string{"js/index.js"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**.js"},
|
|
||||||
inputs: []string{"src/js/app.js"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"docs/*"},
|
|
||||||
inputs: []string{"docs/README.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"docs/*"},
|
|
||||||
inputs: []string{"docs/file.txt"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"docs/**"},
|
|
||||||
inputs: []string{"docs/README.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"docs/**"},
|
|
||||||
inputs: []string{"docs/mona/octocat.txt"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"docs/**/*.md"},
|
|
||||||
inputs: []string{"docs/README.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"docs/**/*.md"},
|
|
||||||
inputs: []string{"docs/mona/hello-world.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"docs/**/*.md"},
|
|
||||||
inputs: []string{"docs/a/markdown/file.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/docs/**"},
|
|
||||||
inputs: []string{"docs/hello.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/docs/**"},
|
|
||||||
inputs: []string{"dir/docs/my-file.txt"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/docs/**"},
|
|
||||||
inputs: []string{"space/docs/plan/space.doc"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/README.md"},
|
|
||||||
inputs: []string{"README.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/README.md"},
|
|
||||||
inputs: []string{"js/README.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/*src/**"},
|
|
||||||
inputs: []string{"a/src/app.js"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/*src/**"},
|
|
||||||
inputs: []string{"my-src/code/js/app.js"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/*-post.md"},
|
|
||||||
inputs: []string{"my-post.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/*-post.md"},
|
|
||||||
inputs: []string{"path/their-post.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/migrate-*.sql"},
|
|
||||||
inputs: []string{"migrate-10909.sql"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/migrate-*.sql"},
|
|
||||||
inputs: []string{"db/migrate-v1.0.sql"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"**/migrate-*.sql"},
|
|
||||||
inputs: []string{"db/sept/migrate-v1.sql"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.md", "!README.md"},
|
|
||||||
inputs: []string{"hello.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.md", "!README.md"},
|
|
||||||
inputs: []string{"README.md"},
|
|
||||||
skipResult: true,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.md", "!README.md"},
|
|
||||||
inputs: []string{"docs/hello.md"},
|
|
||||||
skipResult: true,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.md", "!README.md", "README*"},
|
|
||||||
inputs: []string{"hello.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.md", "!README.md", "README*"},
|
|
||||||
inputs: []string{"README.md"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
patterns: []string{"*.md", "!README.md", "README*"},
|
|
||||||
inputs: []string{"README.doc"},
|
|
||||||
skipResult: false,
|
|
||||||
filterResult: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, kase := range kases {
|
|
||||||
t.Run(strings.Join(kase.patterns, ","), func(t *testing.T) {
|
|
||||||
patterns, err := CompilePatterns(kase.patterns...)
|
|
||||||
assert.NoError(t, err) //nolint:testifylint // pre-existing issue from nektos/act
|
|
||||||
|
|
||||||
assert.EqualValues(t, kase.skipResult, Skip(patterns, kase.inputs, &StdOutTraceWriter{}), "skipResult") //nolint:testifylint // pre-existing issue from nektos/act
|
|
||||||
assert.EqualValues(t, kase.filterResult, Filter(patterns, kase.inputs, &StdOutTraceWriter{}), "filterResult") //nolint:testifylint // pre-existing issue from nektos/act
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -363,6 +363,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
|||||||
EventJSON: string(eventJSON),
|
EventJSON: string(eventJSON),
|
||||||
ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%d", task.Id),
|
ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%d", task.Id),
|
||||||
ContainerMaxLifetime: maxLifetime,
|
ContainerMaxLifetime: maxLifetime,
|
||||||
|
CleanWorkdir: true,
|
||||||
ContainerNetworkMode: container.NetworkMode(r.cfg.Container.Network),
|
ContainerNetworkMode: container.NetworkMode(r.cfg.Container.Network),
|
||||||
ContainerOptions: r.cfg.Container.Options,
|
ContainerOptions: r.cfg.Container.Options,
|
||||||
ContainerDaemonSocket: r.cfg.Container.DockerHost,
|
ContainerDaemonSocket: r.cfg.Container.DockerHost,
|
||||||
|
|||||||
Reference in New Issue
Block a user