Input (#1524)
* added input flags * added input as part of the action event and added test cases * updated readme Co-authored-by: ChristopherHX <christopher.homberger@web.de>
This commit is contained in:
		| @@ -2,6 +2,7 @@ package runner | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
|  | ||||
| @@ -31,6 +32,7 @@ type Config struct { | ||||
| 	LogOutput                          bool              // log the output from docker run | ||||
| 	JSONLogger                         bool              // use json or text logger | ||||
| 	Env                                map[string]string // env for containers | ||||
| 	Inputs                             map[string]string // manually passed action inputs | ||||
| 	Secrets                            map[string]string // list of secrets | ||||
| 	Token                              string            // GitHub token | ||||
| 	InsecureSecrets                    bool              // switch hiding output when printing to terminal | ||||
| @@ -81,6 +83,15 @@ func (runner *runnerImpl) configure() (Runner, error) { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		runner.eventJSON = string(eventJSONBytes) | ||||
| 	} else if len(runner.config.Inputs) != 0 { | ||||
| 		eventMap := map[string]map[string]string{ | ||||
| 			"inputs": runner.config.Inputs, | ||||
| 		} | ||||
| 		eventJSON, err := json.Marshal(eventMap) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		runner.eventJSON = string(eventJSON) | ||||
| 	} | ||||
| 	return runner, nil | ||||
| } | ||||
|   | ||||
| @@ -94,6 +94,7 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config | ||||
| 		ReuseContainers:       false, | ||||
| 		Env:                   cfg.Env, | ||||
| 		Secrets:               cfg.Secrets, | ||||
| 		Inputs:                cfg.Inputs, | ||||
| 		GitHubInstance:        "github.com", | ||||
| 		ContainerArchitecture: cfg.ContainerArchitecture, | ||||
| 	} | ||||
| @@ -419,6 +420,27 @@ func TestRunEventSecrets(t *testing.T) { | ||||
| 	tjfi.runTest(context.Background(), t, &Config{Secrets: secrets, Env: env}) | ||||
| } | ||||
|  | ||||
| func TestRunActionInputs(t *testing.T) { | ||||
| 	if testing.Short() { | ||||
| 		t.Skip("skipping integration test") | ||||
| 	} | ||||
| 	workflowPath := "input-from-cli" | ||||
|  | ||||
| 	tjfi := TestJobFileInfo{ | ||||
| 		workdir:      workdir, | ||||
| 		workflowPath: workflowPath, | ||||
| 		eventName:    "workflow_dispatch", | ||||
| 		errorMessage: "", | ||||
| 		platforms:    platforms, | ||||
| 	} | ||||
|  | ||||
| 	inputs := map[string]string{ | ||||
| 		"SOME_INPUT": "input", | ||||
| 	} | ||||
|  | ||||
| 	tjfi.runTest(context.Background(), t, &Config{Inputs: inputs}) | ||||
| } | ||||
|  | ||||
| func TestRunEventPullRequest(t *testing.T) { | ||||
| 	if testing.Short() { | ||||
| 		t.Skip("skipping integration test") | ||||
|   | ||||
							
								
								
									
										21
									
								
								pkg/runner/testdata/input-from-cli/input.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								pkg/runner/testdata/input-from-cli/input.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| on: | ||||
|   workflow_dispatch: | ||||
|     inputs: | ||||
|       NAME: | ||||
|         description: "A random input name for the workflow" | ||||
|         type: string | ||||
|         required: true | ||||
|       SOME_VALUE: | ||||
|         description: "Some other input to pass" | ||||
|         type: string | ||||
|         required: true | ||||
|  | ||||
| jobs: | ||||
|   test: | ||||
|     name: Test | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     steps: | ||||
|       - name: Test with inputs | ||||
|         run: | | ||||
|           [ -z "${{ github.event.inputs.SOME_INPUT }}" ] && exit 1 || exit 0 | ||||
		Reference in New Issue
	
	Block a user