mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-07 01:14:22 +02:00
gitea can not consume the runner's api by version while it's version mismatches the module version:
```
go: gitea.com/gitea/runner@v3.0.1: invalid version: module contains a go.mod file,
so module path must match major version ("gitea.com/gitea/runner/v3")
```
Fix that by bumping the module version now. The existing `v3.0.0` and `v3.0.1` tags stay unusable, so a new tag is needed after this lands.
Also drop the version `-X` linker flags, which would otherwise have to repeat the new path in both `Makefile` and `.goreleaser.yaml`, where a stale path makes injection silently no-op. Go has recorded the module version in the build info since 1.24, so `Version()` reads it from there, keeping the variable as an override for builds without a VCS stamp.
That part started as https://gitea.com/gitea/runner/pulls/1137 but belongs here: the stamp resolves against the tags that are legal for the module path, so without the `/v3` bump it would report `v1.0.9-0.<ts>-<sha>`. Since `release-nightly.yml` triggers on every push to `main`, splitting them would publish a nightly with a `v1` version.
---------
Co-authored-by: bircni <bircni@icloud.com>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1136
Reviewed-by: techknowlogick <9+techknowlogick@noreply.gitea.com>
Reviewed-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
143 lines
3.9 KiB
Go
143 lines
3.9 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Copyright 2022 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runner
|
|
|
|
import (
|
|
"archive/tar"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"io/fs"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
|
|
"gitea.com/gitea/runner/v3/act/common"
|
|
"gitea.com/gitea/runner/v3/act/model"
|
|
)
|
|
|
|
type stepActionLocal struct {
|
|
Step *model.Step
|
|
RunContext *RunContext
|
|
compositeRunContext *RunContext
|
|
compositeSteps *compositeSteps
|
|
runAction runAction
|
|
readAction readAction
|
|
env map[string]string
|
|
action *model.Action
|
|
}
|
|
|
|
func (sal *stepActionLocal) pre() common.Executor {
|
|
sal.env = map[string]string{}
|
|
|
|
return func(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (sal *stepActionLocal) main() common.Executor {
|
|
return runStepExecutor(sal, stepStageMain, func(ctx context.Context) error {
|
|
if common.Dryrun(ctx) {
|
|
return nil
|
|
}
|
|
|
|
printRunActionHeader(ctx, sal.Step, sal.env, sal.getRunContext())
|
|
rawLogger := common.Logger(ctx).WithField(rawOutputField, true)
|
|
defer rawLogger.Infof("::endgroup::")
|
|
|
|
actionDir := filepath.Join(sal.getRunContext().Config.Workdir, sal.Step.Uses)
|
|
|
|
localReader := func(ctx context.Context) actionYamlReader {
|
|
_, cpath := getContainerActionPaths(sal.Step, path.Join(actionDir, ""), sal.RunContext)
|
|
return func(filename string) (io.Reader, io.Closer, error) {
|
|
spath := path.Join(cpath, filename)
|
|
for range maxSymlinkDepth {
|
|
tars, err := sal.RunContext.JobContainer.GetContainerArchive(ctx, spath)
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
return nil, nil, err
|
|
} else if err != nil {
|
|
return nil, nil, fs.ErrNotExist
|
|
}
|
|
treader := tar.NewReader(tars)
|
|
header, err := treader.Next()
|
|
if errors.Is(err, io.EOF) {
|
|
return nil, nil, os.ErrNotExist
|
|
} else if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
if header.FileInfo().Mode()&os.ModeSymlink == os.ModeSymlink {
|
|
spath, err = symlinkJoin(spath, header.Linkname, cpath)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
} else {
|
|
return treader, tars, nil
|
|
}
|
|
}
|
|
return nil, nil, fmt.Errorf("max depth %d of symlinks exceeded while reading %s", maxSymlinkDepth, spath)
|
|
}
|
|
}
|
|
|
|
actionModel, err := sal.readAction(ctx, sal.Step, actionDir, "", localReader(ctx), os.WriteFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
sal.action = actionModel
|
|
|
|
return sal.runAction(sal, actionDir, nil)(ctx)
|
|
})
|
|
}
|
|
|
|
func (sal *stepActionLocal) post() common.Executor {
|
|
return runStepExecutor(sal, stepStagePost, runPostStep(sal)).If(hasPostStep(sal)).If(shouldRunPostStep(sal))
|
|
}
|
|
|
|
func (sal *stepActionLocal) getRunContext() *RunContext {
|
|
return sal.RunContext
|
|
}
|
|
|
|
func (sal *stepActionLocal) getGithubContext(ctx context.Context) *model.GithubContext {
|
|
return sal.getRunContext().getGithubContext(ctx)
|
|
}
|
|
|
|
func (sal *stepActionLocal) getStepModel() *model.Step {
|
|
return sal.Step
|
|
}
|
|
|
|
func (sal *stepActionLocal) getEnv() *map[string]string {
|
|
return &sal.env
|
|
}
|
|
|
|
func (sal *stepActionLocal) getIfExpression(_ context.Context, stage stepStage) string {
|
|
switch stage {
|
|
case stepStageMain:
|
|
return sal.Step.If.Value
|
|
case stepStagePost:
|
|
return sal.action.Runs.PostIf
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (sal *stepActionLocal) getActionModel() *model.Action {
|
|
return sal.action
|
|
}
|
|
|
|
func (sal *stepActionLocal) getCompositeRunContext(ctx context.Context) *RunContext {
|
|
if sal.compositeRunContext == nil {
|
|
actionDir := filepath.Join(sal.RunContext.Config.Workdir, sal.Step.Uses)
|
|
_, containerActionDir := getContainerActionPaths(sal.getStepModel(), actionDir, sal.RunContext)
|
|
|
|
sal.compositeRunContext = newCompositeRunContext(ctx, sal.RunContext, sal, containerActionDir)
|
|
sal.compositeSteps = sal.compositeRunContext.compositeExecutor(sal.action)
|
|
}
|
|
return sal.compositeRunContext
|
|
}
|
|
|
|
func (sal *stepActionLocal) getCompositeSteps() *compositeSteps {
|
|
return sal.compositeSteps
|
|
}
|