Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent unintended input replacement in reusable workflows with workflow_dispatch when using workflow_call #2502

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
func defaultImageSurvey(actrc string) error {
var answer string
confirmation := &survey.Select{
Message: "Please choose the default image you want to use with act:\n - Large size image: ca. 17GB download + 53.1GB storage, you will need 75GB of free disk space, snapshots of GitHub Hosted Runners without snap and pulled docker images\n - Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with most actions\n - Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions\n\nDefault image and other options can be changed manually in " + configLocations()[0] + " (please refer to https://github.com/nektos/act#configuration for additional information about file structure)",
Message: "Please choose the default image you want to use with act:\n - Large size image: ca. 17GB download + 53.1GB storage, you will need 75GB of free disk space, snapshots of GitHub Hosted Runners without snap and pulled docker images\n - Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with most actions\n - Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions\n\nDefault image and other options can be changed manually in " + configLocations()[0] + " (please refer to https://github.com/nektos/act#configuration for additional information about file structure)",
Help: "If you want to know why act asks you that, please go to https://github.com/nektos/act/issues/107",
Default: "Medium",
Options: []string{"Large", "Medium", "Micro"},
Expand Down
4 changes: 2 additions & 2 deletions pkg/container/host_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ func goArchToActionArch(arch string) string {

func goOsToActionOs(os string) string {
osMapper := map[string]string{
"linux": "Linux",
"linux": "Linux",
"windows": "Windows",
"darwin": "macOS",
"darwin": "macOS",
}
if os, ok := osMapper[os]; ok {
return os
Expand Down
12 changes: 6 additions & 6 deletions pkg/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,12 @@ type ContainerSpec struct {

// Step is the structure of one step in a job
type Step struct {
ID string `yaml:"id"`
If yaml.Node `yaml:"if"`
Name string `yaml:"name"`
Uses string `yaml:"uses"`
Run string `yaml:"run"`
WorkingDirectory string `yaml:"working-directory"`
ID string `yaml:"id"`
If yaml.Node `yaml:"if"`
Name string `yaml:"name"`
Uses string `yaml:"uses"`
Run string `yaml:"run"`
WorkingDirectory string `yaml:"working-directory"`
// WorkflowShell is the shell really configured in the job, directly at step level or higher in defaults.run.shell
WorkflowShell string `yaml:"-"`
Shell string `yaml:"shell"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ func TestReadWorkflow_Strategy(t *testing.T) {

func TestStep_ShellCommand(t *testing.T) {
tests := []struct {
shell string
shell string
workflowShell string
want string
want string
}{
{"pwsh -v '. {0}'", "", "pwsh -v '. {0}'"},
{"pwsh", "", "pwsh -command . '{0}'"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *mod
}
}

if ghc.EventName == "workflow_dispatch" {
if rc.caller == nil && ghc.EventName == "workflow_dispatch" {
ChristopherHX marked this conversation as resolved.
Show resolved Hide resolved
config := rc.Run.Workflow.WorkflowDispatchConfig()
if config != nil && config.Inputs != nil {
for k, v := range config.Inputs {
Expand Down
1 change: 1 addition & 0 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ func TestRunEvent(t *testing.T) {
{workdir, "workflow_dispatch_no_inputs_mapping", "workflow_dispatch", "", platforms, secrets},
{workdir, "workflow_dispatch-scalar", "workflow_dispatch", "", platforms, secrets},
{workdir, "workflow_dispatch-scalar-composite-action", "workflow_dispatch", "", platforms, secrets},
{workdir, "uses-workflow-defaults", "workflow_dispatch", "", platforms, secrets},
{workdir, "job-needs-context-contains-result", "push", "", platforms, secrets},
{"../model/testdata", "strategy", "push", "", platforms, secrets}, // TODO: move all testdata into pkg so we can validate it with planner and runner
{"../model/testdata", "container-volumes", "push", "", platforms, secrets},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: reuse

on:
workflow_dispatch:
inputs:
my-val:
type: string
required: true
default: "default_value_reuse_workflow_dispatch_call"
dispatch-val:
type: string
default: "I am a dispatch var for checking if I am being used in workflow_call"

workflow_call:
inputs:
my-val:
type: string
required: true
default: "default_value_reuse_workflow_call"

jobs:
reusable_workflow_job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run a one-line script
run: echo "✅ 🚀 ✅ hello this is from workflow reuse. Value - " ${{ inputs.my-val }} ${{ github.event_name }} ${{ inputs.dispatch-val }}
- name: Assert
run: |
exit ${{ ( inputs.my-val == 'default_value_reuse_workflow_call' || inputs.my-val == 'passed value from main' ) && !inputs.dispatch-val && '0' || '1' }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run a one-line script
run: echo "✅ 🚀 ✅ hello this is from workflow main" ${{ github.event_name }}
call-reuse-w-val:
uses: ./.github/workflows/local-reusable-and-dispatch.yml
with:
my-val: "passed value from main"