Merge pull request 'cherry-pick some commits from gitea/act_runner' (#1) from earl-warren/runner:wip-sync into main

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1
pull/2/head
earl-warren 2023-03-18 09:25:55 +00:00
commit 634846e944
12 changed files with 174 additions and 812 deletions

View File

@ -5,12 +5,32 @@ on:
env: env:
GOPROXY: https://goproxy.io,direct GOPROXY: https://goproxy.io,direct
GOPATH: /go_path
GOCACHE: /go_cache
jobs: jobs:
lint: lint:
name: check and test name: check and test
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: cache go path
id: cache-go-path
uses: https://github.com/actions/cache@v3
with:
path: /go_path
key: go_path-${{ github.repository }}-${{ github.ref_name }}
restore-keys: |
go_path-${{ github.repository }}-
go_path-
- name: cache go cache
id: cache-go-cache
uses: https://github.com/actions/cache@v3
with:
path: /go_cache
key: go_cache-${{ github.repository }}-${{ github.ref_name }}
restore-keys: |
go_cache-${{ github.repository }}-
go_cache-
- uses: actions/setup-go@v3 - uses: actions/setup-go@v3
with: with:
go-version: 1.20 go-version: 1.20

View File

@ -9,11 +9,13 @@ HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
XGO_VERSION := go-1.18.x XGO_VERSION := go-1.18.x
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10 GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10
RUNNER_CMD_PACKAGE_PATH := codeberg.org/forgejo/runner/cmd
LINUX_ARCHS ?= linux/amd64,linux/arm64 LINUX_ARCHS ?= linux/amd64,linux/arm64
DARWIN_ARCHS ?= darwin-12/amd64,darwin-12/arm64 DARWIN_ARCHS ?= darwin-12/amd64,darwin-12/arm64
WINDOWS_ARCHS ?= windows/amd64 WINDOWS_ARCHS ?= windows/amd64
GOFILES := $(shell find . -type f -name "*.go" ! -name "generated.*") GO_FMT_FILES := $(shell find . -type f -name "*.go" ! -name "generated.*")
GOFILES := $(shell find . -type f -name "*.go" -o -name "go.mod" ! -name "generated.*")
ifneq ($(shell uname), Darwin) ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null) EXTLDFLAGS = -extldflags "-static" $(null)
@ -49,7 +51,7 @@ else
ifneq ($(DRONE_BRANCH),) ifneq ($(DRONE_BRANCH),)
VERSION ?= $(subst release/v,,$(DRONE_BRANCH)) VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
else else
VERSION ?= master VERSION ?= main
endif endif
STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null) STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
@ -61,7 +63,7 @@ else
endif endif
TAGS ?= TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)' LDFLAGS ?= -X "$(RUNNER_CMD_PACKAGE_PATH).version=$(RELASE_VERSION)"
all: build all: build
@ -69,17 +71,27 @@ fmt:
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt@latest; \ $(GO) install mvdan.cc/gofumpt@latest; \
fi fi
$(GOFMT) -w $(GOFILES) $(GOFMT) -w $(GO_FMT_FILES)
vet: vet:
$(GO) vet ./... $(GO) vet ./...
.PHONY: go-check
go-check:
$(eval MIN_GO_VERSION_STR := $(shell grep -Eo '^go\s+[0-9]+\.[0-9]+' go.mod | cut -d' ' -f2))
$(eval MIN_GO_VERSION := $(shell printf "%03d%03d" $(shell echo '$(MIN_GO_VERSION_STR)' | tr '.' ' ')))
$(eval GO_VERSION := $(shell printf "%03d%03d" $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9]+' | tr '.' ' ');))
@if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
echo "Act Runner requires Go $(MIN_GO_VERSION_STR) or greater to build. You can get it at https://go.dev/dl/"; \
exit 1; \
fi
.PHONY: fmt-check .PHONY: fmt-check
fmt-check: fmt-check:
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt@latest; \ $(GO) install mvdan.cc/gofumpt@latest; \
fi fi
@diff=$$($(GOFMT) -d $(GOFILES)); \ @diff=$$($(GOFMT) -d $(GO_FMT_FILES)); \
if [ -n "$$diff" ]; then \ if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \ echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \ echo "$${diff}"; \
@ -92,7 +104,7 @@ test: fmt-check
install: $(GOFILES) install: $(GOFILES)
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' $(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
build: $(EXECUTABLE) build: go-check $(EXECUTABLE)
$(EXECUTABLE): $(GOFILES) $(EXECUTABLE): $(GOFILES)
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@ $(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@

View File

@ -26,7 +26,7 @@ func getHttpClient(endpoint string, insecure bool) *http.Client {
} }
// New returns a new runner client. // New returns a new runner client.
func New(endpoint string, insecure bool, uuid, token string, opts ...connect.ClientOption) *HTTPClient { func New(endpoint string, insecure bool, uuid, token, runnerVersion string, opts ...connect.ClientOption) *HTTPClient {
baseURL := strings.TrimRight(endpoint, "/") + "/api/actions" baseURL := strings.TrimRight(endpoint, "/") + "/api/actions"
opts = append(opts, connect.WithInterceptors(connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc { opts = append(opts, connect.WithInterceptors(connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
@ -37,6 +37,9 @@ func New(endpoint string, insecure bool, uuid, token string, opts ...connect.Cli
if token != "" { if token != "" {
req.Header().Set(core.TokenHeader, token) req.Header().Set(core.TokenHeader, token)
} }
if runnerVersion != "" {
req.Header().Set(core.VersionHeader, runnerVersion)
}
return next(ctx, req) return next(ctx, req)
} }
}))) })))

View File

@ -7,7 +7,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
const version = "0.1.5" // the version of act_runner
var version = "develop"
type globalArgs struct { type globalArgs struct {
EnvFile string EnvFile string
@ -20,7 +21,7 @@ func Execute(ctx context.Context) {
// ./act_runner // ./act_runner
rootCmd := &cobra.Command{ rootCmd := &cobra.Command{
Use: "act [event name to run]\nIf no event name passed, will default to \"on: push\"", Use: "act_runner [event name to run]\nIf no event name passed, will default to \"on: push\"",
Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.", Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.",
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
Version: version, Version: version,

View File

@ -63,6 +63,7 @@ func runDaemon(ctx context.Context, envFile string) func(cmd *cobra.Command, arg
cfg.Client.Insecure, cfg.Client.Insecure,
cfg.Runner.UUID, cfg.Runner.UUID,
cfg.Runner.Token, cfg.Runner.Token,
version,
) )
runner := &runtime.Runner{ runner := &runtime.Runner{
@ -71,6 +72,7 @@ func runDaemon(ctx context.Context, envFile string) func(cmd *cobra.Command, arg
ForgeInstance: cfg.Client.Address, ForgeInstance: cfg.Client.Address,
Environ: cfg.Runner.Environ, Environ: cfg.Runner.Environ,
Labels: cfg.Runner.Labels, Labels: cfg.Runner.Labels,
Version: version,
CacheHandler: handler, CacheHandler: handler,
} }

View File

@ -13,7 +13,6 @@ import (
"strings" "strings"
"time" "time"
"codeberg.org/forgejo/runner/artifactcache"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/nektos/act/pkg/artifacts" "github.com/nektos/act/pkg/artifacts"
"github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/common"
@ -22,6 +21,8 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/term" "golang.org/x/term"
"codeberg.org/forgejo/runner/artifactcache"
) )
type executeArgs struct { type executeArgs struct {
@ -48,6 +49,7 @@ type executeArgs struct {
containerCapAdd []string containerCapAdd []string
containerCapDrop []string containerCapDrop []string
artifactServerPath string artifactServerPath string
artifactServerAddr string
artifactServerPort string artifactServerPort string
noSkipCheckout bool noSkipCheckout bool
debug bool debug bool
@ -262,15 +264,25 @@ func runExecList(ctx context.Context, planner model.WorkflowPlanner, execArgs *e
filterEventName = events[0] filterEventName = events[0]
} }
var err error
if execArgs.job != "" { if execArgs.job != "" {
log.Infof("Preparing plan with a job: %s", execArgs.job) log.Infof("Preparing plan with a job: %s", execArgs.job)
filterPlan = planner.PlanJob(execArgs.job) filterPlan, err = planner.PlanJob(execArgs.job)
if err != nil {
return err
}
} else if filterEventName != "" { } else if filterEventName != "" {
log.Infof("Preparing plan for a event: %s", filterEventName) log.Infof("Preparing plan for a event: %s", filterEventName)
filterPlan = planner.PlanEvent(filterEventName) filterPlan, err = planner.PlanEvent(filterEventName)
if err != nil {
return err
}
} else { } else {
log.Infof("Preparing plan with all jobs") log.Infof("Preparing plan with all jobs")
filterPlan = planner.PlanAll() filterPlan, err = planner.PlanAll()
if err != nil {
return err
}
} }
printList(filterPlan) printList(filterPlan)
@ -317,10 +329,16 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
// build the plan for this run // build the plan for this run
if execArgs.job != "" { if execArgs.job != "" {
log.Infof("Planning job: %s", execArgs.job) log.Infof("Planning job: %s", execArgs.job)
plan = planner.PlanJob(execArgs.job) plan, err = planner.PlanJob(execArgs.job)
if err != nil {
return err
}
} else { } else {
log.Infof("Planning jobs for event: %s", eventName) log.Infof("Planning jobs for event: %s", eventName)
plan = planner.PlanEvent(eventName) plan, err = planner.PlanEvent(eventName)
if err != nil {
return err
}
} }
maxLifetime := 3 * time.Hour maxLifetime := 3 * time.Hour
@ -393,7 +411,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
execArgs.artifactServerPath = tempDir execArgs.artifactServerPath = tempDir
} }
artifactCancel := artifacts.Serve(ctx, execArgs.artifactServerPath, execArgs.artifactServerPort) artifactCancel := artifacts.Serve(ctx, execArgs.artifactServerPath, execArgs.artifactServerAddr, execArgs.artifactServerPort)
log.Debugf("artifacts server started at %s:%s", execArgs.artifactServerPath, execArgs.artifactServerPort) log.Debugf("artifacts server started at %s:%s", execArgs.artifactServerPath, execArgs.artifactServerPort)
ctx = common.WithDryrun(ctx, execArgs.dryrun) ctx = common.WithDryrun(ctx, execArgs.dryrun)

View File

@ -271,7 +271,9 @@ func doRegister(cfg *config.Config, inputs *registerInputs) error {
cli := client.New( cli := client.New(
inputs.InstanceAddr, inputs.InstanceAddr,
inputs.Insecure, inputs.Insecure,
"", "", "",
"",
version,
) )
for { for {

View File

@ -3,6 +3,7 @@ package core
const ( const (
UUIDHeader = "x-runner-uuid" UUIDHeader = "x-runner-uuid"
TokenHeader = "x-runner-token" TokenHeader = "x-runner-token"
VersionHeader = "x-runner-version"
) )
// Runner struct // Runner struct

59
go.mod
View File

@ -1,23 +1,23 @@
module codeberg.org/forgejo/runner module codeberg.org/forgejo/runner
go 1.18 go 1.20
require ( require (
code.gitea.io/actions-proto-go v0.2.0 code.gitea.io/actions-proto-go v0.2.0
code.gitea.io/gitea-vet v0.2.3-0.20230113022436-2b1561217fa5 code.gitea.io/gitea-vet v0.2.3-0.20230113022436-2b1561217fa5
github.com/avast/retry-go/v4 v4.3.1 github.com/avast/retry-go/v4 v4.3.1
github.com/bufbuild/connect-go v1.3.1 github.com/bufbuild/connect-go v1.3.1
github.com/docker/docker v20.10.21+incompatible github.com/docker/docker v23.0.1+incompatible
github.com/go-chi/chi/v5 v5.0.8 github.com/go-chi/chi/v5 v5.0.8
github.com/go-chi/render v1.0.2 github.com/go-chi/render v1.0.2
github.com/joho/godotenv v1.4.0 github.com/joho/godotenv v1.5.1
github.com/kelseyhightower/envconfig v1.4.0 github.com/kelseyhightower/envconfig v1.4.0
github.com/mattn/go-isatty v0.0.16 github.com/mattn/go-isatty v0.0.17
github.com/nektos/act v0.0.0 github.com/nektos/act v0.0.0
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1 github.com/spf13/cobra v1.6.1
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde golang.org/x/sync v0.1.0
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 golang.org/x/term v0.6.0
google.golang.org/protobuf v1.28.1 google.golang.org/protobuf v1.28.1
modernc.org/sqlite v1.14.2 modernc.org/sqlite v1.14.2
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978
@ -25,29 +25,26 @@ require (
) )
require ( require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Masterminds/semver v1.5.0 // indirect github.com/Masterminds/semver v1.5.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/Microsoft/hcsshim v0.9.3 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20220404123522-616f957b79ad // indirect github.com/ProtonMail/go-crypto v0.0.0-20220404123522-616f957b79ad // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/ajg/form v1.5.1 // indirect github.com/ajg/form v1.5.1 // indirect
github.com/containerd/cgroups v1.0.3 // indirect github.com/containerd/containerd v1.6.18 // indirect
github.com/containerd/containerd v1.6.6 // indirect
github.com/creack/pty v1.1.18 // indirect github.com/creack/pty v1.1.18 // indirect
github.com/docker/cli v20.10.21+incompatible // indirect github.com/docker/cli v23.0.1+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect github.com/emirpasic/gods v1.12.0 // indirect
github.com/fatih/color v1.13.0 // indirect github.com/fatih/color v1.13.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-git/v5 v5.4.2 // indirect github.com/go-git/go-git/v5 v5.4.2 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/goccy/go-json v0.8.1 // indirect github.com/goccy/go-json v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
@ -58,23 +55,26 @@ require (
github.com/julienschmidt/httprouter v1.3.0 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/moby/buildkit v0.10.6 // indirect github.com/moby/buildkit v0.11.4 // indirect
github.com/moby/sys/mount v0.3.1 // indirect github.com/moby/patternmatcher v0.5.0 // indirect
github.com/moby/sys/mountinfo v0.6.0 // indirect github.com/moby/sys/sequential v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo v1.12.1 // indirect
github.com/onsi/gomega v1.10.3 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/opencontainers/runc v1.1.2 // indirect github.com/opencontainers/runc v1.1.3 // indirect
github.com/opencontainers/selinux v1.10.2 // indirect github.com/opencontainers/selinux v1.11.0 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/rhysd/actionlint v1.6.22 // indirect github.com/rhysd/actionlint v1.6.23 // indirect
github.com/rivo/uniseg v0.3.4 // indirect github.com/rivo/uniseg v0.4.3 // indirect
github.com/robfig/cron v1.2.0 // indirect github.com/robfig/cron v1.2.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect github.com/sergi/go-diff v1.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
@ -82,12 +82,11 @@ require (
github.com/xanzy/ssh-agent v0.3.1 // indirect github.com/xanzy/ssh-agent v0.3.1 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.opencensus.io v0.23.0 // indirect golang.org/x/crypto v0.2.0 // indirect
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect
golang.org/x/mod v0.4.2 // indirect golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c // indirect golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect golang.org/x/sys v0.6.0 // indirect
golang.org/x/tools v0.1.5 // indirect golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect
@ -104,4 +103,4 @@ require (
modernc.org/token v1.0.0 // indirect modernc.org/token v1.0.0 // indirect
) )
replace github.com/nektos/act => codeberg.org/forgejo/act v1.1.0 replace github.com/nektos/act => code.forgejo.org/forgejo/act v1.2.0

807
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@ import (
// Runner runs the pipeline. // Runner runs the pipeline.
type Runner struct { type Runner struct {
Machine string Machine string
Version string
ForgeInstance string ForgeInstance string
Environ map[string]string Environ map[string]string
Client client.Client Client client.Client
@ -26,7 +27,7 @@ func (s *Runner) Run(ctx context.Context, task *runnerv1.Task) error {
env[k] = v env[k] = v
} }
env["ACTIONS_CACHE_URL"] = s.CacheHandler.ExternalURL() + "/" env["ACTIONS_CACHE_URL"] = s.CacheHandler.ExternalURL() + "/"
return NewTask(s.ForgeInstance, task.Id, s.Client, env, s.platformPicker).Run(ctx, task, s.Machine) return NewTask(s.ForgeInstance, task.Id, s.Client, env, s.platformPicker).Run(ctx, task, s.Machine, s.Version)
} }
func (s *Runner) platformPicker(labels []string) string { func (s *Runner) platformPicker(labels []string) string {

View File

@ -11,7 +11,6 @@ import (
"time" "time"
runnerv1 "code.gitea.io/actions-proto-go/runner/v1" runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
"github.com/nektos/act/pkg/artifacts"
"github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/common"
"github.com/nektos/act/pkg/model" "github.com/nektos/act/pkg/model"
"github.com/nektos/act/pkg/runner" "github.com/nektos/act/pkg/runner"
@ -112,7 +111,7 @@ func getToken(task *runnerv1.Task) string {
return token return token
} }
func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string) (lastErr error) { func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName, runnerVersion string) (lastErr error) {
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
defer cancel() defer cancel()
_, exist := globalTaskMap.Load(task.Id) _, exist := globalTaskMap.Load(task.Id)
@ -141,7 +140,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string)
}() }()
reporter.RunDaemon() reporter.RunDaemon()
reporter.Logf("%s received task %v of job %v", runnerName, task.Id, task.Context.Fields["job"].GetStringValue()) reporter.Logf("%s(version:%s) received task %v of job %v, be triggered by event: %s", runnerName, runnerVersion, task.Id, task.Context.Fields["job"].GetStringValue(), task.Context.Fields["event_name"].GetStringValue())
workflowsPath, err := getWorkflowsPath(t.Input.repoDirectory) workflowsPath, err := getWorkflowsPath(t.Input.repoDirectory)
if err != nil { if err != nil {
@ -156,7 +155,6 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string)
return err return err
} }
var plan *model.Plan
jobIDs := workflow.GetJobIDs() jobIDs := workflow.GetJobIDs()
if len(jobIDs) != 1 { if len(jobIDs) != 1 {
err := fmt.Errorf("multiple jobs found: %v", jobIDs) err := fmt.Errorf("multiple jobs found: %v", jobIDs)
@ -164,7 +162,11 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string)
return err return err
} }
jobID := jobIDs[0] jobID := jobIDs[0]
plan = model.CombineWorkflowPlanner(workflow).PlanJob(jobID) plan, err := model.CombineWorkflowPlanner(workflow).PlanJob(jobID)
if err != nil {
lastWords = err.Error()
return err
}
job := workflow.GetJob(jobID) job := workflow.GetJob(jobID)
reporter.ResetSteps(len(job.Steps)) reporter.ResetSteps(len(job.Steps))
@ -243,13 +245,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string)
return err return err
} }
artifactCancel := artifacts.Serve(ctx, input.artifactServerPath, input.artifactServerPort) executor := r.NewPlanExecutor(plan)
t.log.Debugf("artifacts server started at %s:%s", input.artifactServerPath, input.artifactServerPort)
executor := r.NewPlanExecutor(plan).Finally(func(ctx context.Context) error {
artifactCancel()
return nil
})
t.log.Infof("workflow prepared") t.log.Infof("workflow prepared")
reporter.Logf("workflow prepared") reporter.Logf("workflow prepared")