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:
@@ -211,7 +211,7 @@ func updateTestExpressionWorkflow(t *testing.T, tables []struct {
|
||||
}
|
||||
|
||||
workflow := fmt.Sprintf(`
|
||||
name: "Test how expressions are handled on Github"
|
||||
name: "Test how expressions are handled on GitHub"
|
||||
on: push
|
||||
|
||||
env:
|
||||
|
14
pkg/runner/res/trampoline.js
Normal file
14
pkg/runner/res/trampoline.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const { spawnSync } = require('child_process')
|
||||
const spawnArguments={
|
||||
cwd: process.env['INPUT_CWD'],
|
||||
stdio: [
|
||||
process.stdin,
|
||||
process.stdout,
|
||||
process.stderr,
|
||||
]
|
||||
}
|
||||
const child=spawnSync(
|
||||
'/bin/sh',
|
||||
[ '-c' ].concat(process.env['INPUT_COMMAND']),
|
||||
spawnArguments)
|
||||
process.exit(child.status)
|
@@ -316,7 +316,7 @@ func (rc *RunContext) EvalBool(expr string) (bool, error) {
|
||||
|
||||
interpolatedPart, isString := rc.ExprEval.InterpolateWithStringCheck(part)
|
||||
|
||||
// This peculiar transformation has to be done because the Github parser
|
||||
// This peculiar transformation has to be done because the GitHub parser
|
||||
// treats false returned from contexts as a string, not a boolean.
|
||||
// Hence env.SOMETHING will be evaluated to true in an if: expression
|
||||
// regardless if SOMETHING is set to false, true or any other string.
|
||||
|
@@ -169,7 +169,7 @@ func updateTestIfWorkflow(t *testing.T, tables []struct {
|
||||
}
|
||||
|
||||
workflow := fmt.Sprintf(`
|
||||
name: "Test what expressions result in true and false on Github"
|
||||
name: "Test what expressions result in true and false on GitHub"
|
||||
on: push
|
||||
|
||||
env:
|
||||
|
@@ -24,7 +24,7 @@ type Config struct {
|
||||
EventPath string // path to JSON file to use for event.json in containers
|
||||
DefaultBranch string // name of the main branch for this repository
|
||||
ReuseContainers bool // reuse containers to maintain state
|
||||
ForcePull bool // force pulling of the image, if already present
|
||||
ForcePull bool // force pulling of the image, even if already present
|
||||
LogOutput bool // log the output from docker run
|
||||
Env map[string]string // env for containers
|
||||
Secrets map[string]string // list of secrets
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user