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:
Josh Soref
2021-03-30 15:26:25 -04:00
committed by GitHub
parent d67e282f68
commit 5752a03dcd
16 changed files with 96 additions and 23 deletions

View File

@@ -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:

View 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)

View File

@@ -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.

View File

@@ -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:

View File

@@ -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

View File

@@ -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 {