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

READY: Add coverage for complex expressions evaluation #177

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,29 @@ Example of condition with check of current step output:
option2: value
```

**How to use complex conditions**

The library used for evaluating expressions does not account for operator precedence, which can lead to incorrect results in complex expressions where the order of operations is crucial.

Example of the issue. Consider the following expression:
```yaml
'main' == 'main' && 'main' != 'master'
```

Due to the library's evaluation method, this expression is interpreted as:
```yaml
(('main' == 'main') && 'main') != 'master'
```

As a result, it evaluates to `false`, which is not the intended outcome.

To ensure that the expression is evaluated correctly, you can use parentheses to explicitly define the order of operations. The corrected expression should be written as:
```yaml
('main' == 'main') && ('main' != 'master')
```

This adjustment clarifies the intended precedence and will yield the correct result.

### `github_token`

A token to access private actions. Does not required for public actions.
Expand Down
2 changes: 1 addition & 1 deletion node_modules/github-actions-parser/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/github-actions-parser/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/github-actions-parser/dist/index.modern.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/github-actions-parser/dist/index.modern.mjs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/github-actions-parser/dist/index.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/github-actions-parser/dist/index.umd.js.map

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

39 changes: 39 additions & 0 deletions test/Common.test.s
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,44 @@ function shouldExit( test )
test.close( 'with conditions' );
}

//

function evaluateExpression( test )
{
var contextGet = ( _contextName ) => {
return {
_this:
{
outputs: {
status: 'FAILED'
}
}
};
};

test.case = 'evaluate simple expression to true';
var got = common.evaluateExpression( 'steps._this.outputs.status == \'FAILED\'', contextGet );
test.identical( got, true );

test.case = 'evaluate simple expression to false';
var got = common.evaluateExpression( 'steps._this.outputs.status != \'FAILED\'', contextGet );
test.identical( got, false );

test.case = 'evaluate combined expression to true';
var got = common.evaluateExpression
(
'(steps._this.outputs.status != \'WARN\') && (steps._this.outputs.status == \'FAILED\')', contextGet
);
test.identical( got, true );

test.case = 'evaluate simple expression to false';
var got = common.evaluateExpression
(
'(steps._this.outputs.status != \'WARN\') && (steps._this.outputs.status != \'FAILED\')', contextGet
);
test.identical( got, false );
}

// --
// declare
// --
Expand All @@ -1434,6 +1472,7 @@ const Proto =
contextGet,
envOptionsSetup,
shouldExit,
evaluateExpression,
},
};

Expand Down