mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
Support running commands in repositories without action.yaml (#293)
* Comment for public function * Add git describe fallback * spelling: github * Set initial branch to satisfy tests for modern git * Clarify -even- if * Go 1.16 * Support running commands in repositories without action.yaml Support runnings commands with only a Docker file Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
parent
6d023b011e
commit
ac92a02474
13 changed files with 93 additions and 20 deletions
|
@ -2,7 +2,10 @@ package runner
|
|||
|
||||
import (
|
||||
"context"
|
||||
// Go told me to?
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -296,12 +299,55 @@ func (sc *StepContext) runUsesContainer() common.Executor {
|
|||
}
|
||||
}
|
||||
|
||||
//go:embed res/trampoline.js
|
||||
var trampoline []byte
|
||||
|
||||
func (sc *StepContext) setupAction(actionDir string, actionPath string) common.Executor {
|
||||
return func(ctx context.Context) error {
|
||||
f, err := os.Open(filepath.Join(actionDir, actionPath, "action.yml"))
|
||||
if os.IsNotExist(err) {
|
||||
f, err = os.Open(filepath.Join(actionDir, actionPath, "action.yaml"))
|
||||
if err != nil {
|
||||
if _, err2 := os.Stat(filepath.Join(actionDir, actionPath, "Dockerfile")); err2 == nil {
|
||||
sc.Action = &model.Action{
|
||||
Name: "(Synthetic)",
|
||||
Runs: model.ActionRuns{
|
||||
Using: "docker",
|
||||
Image: "Dockerfile",
|
||||
},
|
||||
}
|
||||
log.Debugf("Using synthetic action %v for Dockerfile", sc.Action)
|
||||
return nil
|
||||
}
|
||||
if sc.Step.With != nil {
|
||||
if val, ok := sc.Step.With["args"]; ok {
|
||||
err2 := ioutil.WriteFile(filepath.Join(actionDir, actionPath, "trampoline.js"), trampoline, 0400)
|
||||
if err2 != nil {
|
||||
return err
|
||||
}
|
||||
sc.Action = &model.Action{
|
||||
Name: "(Synthetic)",
|
||||
Inputs: map[string]model.Input{
|
||||
"cwd": {
|
||||
Description: "(Actual working directory)",
|
||||
Required: false,
|
||||
Default: filepath.Join(actionDir, actionPath),
|
||||
},
|
||||
"command": {
|
||||
Description: "(Actual program)",
|
||||
Required: false,
|
||||
Default: val,
|
||||
},
|
||||
},
|
||||
Runs: model.ActionRuns{
|
||||
Using: "node12",
|
||||
Main: "trampoline.js",
|
||||
},
|
||||
}
|
||||
log.Debugf("Using synthetic action %v", sc.Action)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue