Skip to content

Commit

Permalink
fix: if condition in composite action misbehaves with uses
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX committed Sep 27, 2024
1 parent 6657fca commit 95d5fb9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/runner/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func isStepEnabled(ctx context.Context, expr string, step step, stage stepStage)
defaultStatusCheck = exprparser.DefaultStatusCheckSuccess
}

runStep, err := EvalBool(ctx, rc.NewStepExpressionEvaluator(ctx, step), expr, defaultStatusCheck)
runStep, err := EvalBool(ctx, rc.NewExpressionEvaluatorWithEnv(ctx, *step.getEnv()), expr, defaultStatusCheck)
if err != nil {
return false, fmt.Errorf(" \u274C Error in if-expression: \"if: %s\" (%s)", expr, err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 95d5fb9

Please sign in to comment.