fix: if condition in composite action misbehaves (#2473)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
@@ -108,6 +108,19 @@ var hashfiles string
|
|||||||
|
|
||||||
// NewStepExpressionEvaluator creates a new evaluator
|
// NewStepExpressionEvaluator creates a new evaluator
|
||||||
func (rc *RunContext) NewStepExpressionEvaluator(ctx context.Context, step step) ExpressionEvaluator {
|
func (rc *RunContext) NewStepExpressionEvaluator(ctx context.Context, step step) ExpressionEvaluator {
|
||||||
|
return rc.NewStepExpressionEvaluatorExt(ctx, step, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewStepExpressionEvaluatorExt creates a new evaluator
|
||||||
|
func (rc *RunContext) NewStepExpressionEvaluatorExt(ctx context.Context, step step, rcInputs bool) ExpressionEvaluator {
|
||||||
|
ghc := rc.getGithubContext(ctx)
|
||||||
|
if rcInputs {
|
||||||
|
return rc.newStepExpressionEvaluator(ctx, step, ghc, getEvaluatorInputs(ctx, rc, nil, ghc))
|
||||||
|
}
|
||||||
|
return rc.newStepExpressionEvaluator(ctx, step, ghc, getEvaluatorInputs(ctx, rc, step, ghc))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RunContext) newStepExpressionEvaluator(ctx context.Context, step step, ghc *model.GithubContext, inputs map[string]interface{}) ExpressionEvaluator {
|
||||||
// todo: cleanup EvaluationEnvironment creation
|
// todo: cleanup EvaluationEnvironment creation
|
||||||
job := rc.Run.Job()
|
job := rc.Run.Job()
|
||||||
strategy := make(map[string]interface{})
|
strategy := make(map[string]interface{})
|
||||||
@@ -127,9 +140,6 @@ func (rc *RunContext) NewStepExpressionEvaluator(ctx context.Context, step step)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ghc := rc.getGithubContext(ctx)
|
|
||||||
inputs := getEvaluatorInputs(ctx, rc, step, ghc)
|
|
||||||
|
|
||||||
ee := &exprparser.EvaluationEnvironment{
|
ee := &exprparser.EvaluationEnvironment{
|
||||||
Github: step.getGithubContext(ctx),
|
Github: step.getGithubContext(ctx),
|
||||||
Env: *step.getEnv(),
|
Env: *step.getEnv(),
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ func isStepEnabled(ctx context.Context, expr string, step step, stage stepStage)
|
|||||||
defaultStatusCheck = exprparser.DefaultStatusCheckSuccess
|
defaultStatusCheck = exprparser.DefaultStatusCheckSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
runStep, err := EvalBool(ctx, rc.NewStepExpressionEvaluator(ctx, step), expr, defaultStatusCheck)
|
runStep, err := EvalBool(ctx, rc.NewStepExpressionEvaluatorExt(ctx, step, stage == stepStageMain), expr, defaultStatusCheck)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf(" \u274C Error in if-expression: \"if: %s\" (%s)", expr, err)
|
return false, fmt.Errorf(" \u274C Error in if-expression: \"if: %s\" (%s)", expr, err)
|
||||||
}
|
}
|
||||||
|
|||||||
47
pkg/runner/testdata/uses-composite-check-for-input-in-if-uses/composite_action/action.yml
vendored
Normal file
47
pkg/runner/testdata/uses-composite-check-for-input-in-if-uses/composite_action/action.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
name: "Test Composite Action"
|
||||||
|
description: "Test action uses composite"
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
b:
|
||||||
|
default: true
|
||||||
|
b2: {}
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- uses: actions/github-script@v7
|
||||||
|
if: inputs.b == 'true'
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
console.log(${{ tojson(inputs) }})
|
||||||
|
if( ${{ tojson(inputs.b) }} != 'true' ) {
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
github-token: noop
|
||||||
|
- uses: actions/github-script@v7
|
||||||
|
if: inputs.b != 'true'
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
console.log(${{ tojson(inputs) }})
|
||||||
|
if( ${{ tojson(inputs.b) }} == 'true' ) {
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
github-token: noop
|
||||||
|
- uses: actions/github-script@v7
|
||||||
|
if: inputs.b2 == 'false'
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
console.log(${{ tojson(inputs) }})
|
||||||
|
if( ${{ tojson(inputs.b2) }} != 'false' ) {
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
github-token: noop
|
||||||
|
- uses: actions/github-script@v7
|
||||||
|
if: inputs.b2 != 'false'
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
console.log(${{ tojson(inputs) }})
|
||||||
|
if( ${{ tojson(inputs.b2) }} == 'false' ) {
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
github-token: noop
|
||||||
24
pkg/runner/testdata/uses-composite-check-for-input-in-if-uses/push.yml
vendored
Normal file
24
pkg/runner/testdata/uses-composite-check-for-input-in-if-uses/push.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
name: uses-composite-check-for-input-in-if-uses
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./uses-composite-check-for-input-in-if-uses/composite_action
|
||||||
|
with:
|
||||||
|
b: true
|
||||||
|
b2: true
|
||||||
|
- uses: ./uses-composite-check-for-input-in-if-uses/composite_action
|
||||||
|
with:
|
||||||
|
b: false
|
||||||
|
b2: false
|
||||||
|
- uses: ./uses-composite-check-for-input-in-if-uses/composite_action
|
||||||
|
with:
|
||||||
|
b: true
|
||||||
|
b2: false
|
||||||
|
- uses: ./uses-composite-check-for-input-in-if-uses/composite_action
|
||||||
|
with:
|
||||||
|
b: false
|
||||||
|
b2: true
|
||||||
Reference in New Issue
Block a user