Skip to content

Commit

Permalink
fix: interpolate action input defaults
Browse files Browse the repository at this point in the history
This fixes the regression to interpolate input defaults which contain
expressions.
  • Loading branch information
KnisterPeter committed Oct 7, 2022
1 parent 48188a6 commit 54ff401
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/runner/action_composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func evaluateCompositeInputAndEnv(ctx context.Context, parent *RunContext, step
}
}

ee := parent.NewStepExpressionEvaluator(ctx, step)

for inputID, input := range step.getActionModel().Inputs {
envKey := regexp.MustCompile("[^A-Z0-9-]").ReplaceAllString(strings.ToUpper(inputID), "_")
envKey = fmt.Sprintf("INPUT_%s", strings.ToUpper(envKey))
Expand All @@ -31,7 +33,8 @@ func evaluateCompositeInputAndEnv(ctx context.Context, parent *RunContext, step
if value, ok := stepEnv[envKey]; defined && ok {
env[envKey] = value
} else {
env[envKey] = input.Default
// defaults could contain expressions
env[envKey] = ee.Interpolate(ctx, input.Default)
}
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/runner/testdata/uses-composite-with-inputs/action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
some:
description: "some input"
required: true
other:
description: "other input"
default: "${{ inputs.some }}"
required: false
outputs:
out:
description: "some output"
Expand All @@ -17,3 +21,9 @@ runs:
echo "action input=${{ inputs.some }}"
[[ "${{ inputs.some == 'value' }}" = "true" ]] || exit 1
shell: bash
- run: |
echo "ENV_VAR=$ENV_VAR"
[[ "$ENV_VAR" = "value" ]] || exit 1
shell: bash
env:
ENV_VAR: ${{ inputs.other }}

0 comments on commit 54ff401

Please sign in to comment.