Skip to content

Commit

Permalink
Merge pull request #177 from dmvict/js_action
Browse files Browse the repository at this point in the history
READY: Add coverage for complex expressions evaluation
  • Loading branch information
dmvict authored Nov 19, 2024
2 parents 41d4bef + 037c469 commit 22138f6
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 13 deletions.
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

0 comments on commit 22138f6

Please sign in to comment.