@@ -19,24 +19,18 @@ int partialLineLengthSum(string text, int i) {
19
19
result = sum ( int j , int length | j in [ 0 .. i ] and length = lineLength ( text , j ) | length )
20
20
}
21
21
22
- /**
23
- * Holds if `${{ e }}` is a GitHub Actions expression evaluated within this YAML string.
24
- * See https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions.
25
- * Only finds simple expressions like `${{ github.event.comment.body }}`, where the expression contains only alphanumeric characters, underscores, dots, or dashes.
26
- * Does not identify more complicated expressions like `${{ fromJSON(env.time) }}`, or ${{ format('{{Hello {0}!}}', github.event.head_commit.author.name) }}
27
- */
28
- string getASimpleReferenceExpression ( YamlString s , int offset ) {
22
+ string getADelimitedExpression ( YamlString s , int offset ) {
29
23
// We use `regexpFind` to obtain *all* matches of `${{...}}`,
30
24
// not just the last (greedy match) or first (reluctant match).
31
25
result =
32
26
s .getValue ( )
33
- .regexpFind ( "\\$\\{\\{\\s*[A-Za-z0-9'\"_\\[\\]\\*\\(\\)\\.\\-]+ \\s*\\}\\}" , _, offset )
34
- .regexpCapture ( "(\\$\\{\\{\\s*[A-Za-z0-9'\"_\\[\\]\\*\\((\\)\\.\\-]+ \\s*\\}\\})" , 1 )
27
+ .regexpFind ( "\\$\\{\\{\\s*.* \\s*\\}\\}" , _, offset )
28
+ .regexpCapture ( "(\\$\\{\\{\\s*.* \\s*\\}\\})" , 1 )
35
29
}
36
30
37
31
private newtype TAstNode =
38
32
TExpressionNode ( YamlNode key , YamlScalar value , string raw , int exprOffset ) {
39
- raw = getASimpleReferenceExpression ( value , exprOffset ) and
33
+ raw = getADelimitedExpression ( value , exprOffset ) and
40
34
exists ( YamlMapping m |
41
35
(
42
36
exists ( int i | value = m .getValueNode ( i ) and key = m .getKeyNode ( i ) )
@@ -789,11 +783,29 @@ class RunImpl extends StepImpl {
789
783
}
790
784
}
791
785
786
+ /**
787
+ * Holds if `${{ e }}` is a GitHub Actions expression evaluated within this YAML string.
788
+ * See https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions.
789
+ * Only finds simple expressions like `${{ github.event.comment.body }}`, where the expression contains only alphanumeric characters, underscores, dots, or dashes.
790
+ * Does not identify more complicated expressions like `${{ fromJSON(env.time) }}`, or ${{ format('{{Hello {0}!}}', github.event.head_commit.author.name) }}
791
+ */
792
+ bindingset [ s]
793
+ string getASimpleReferenceExpression ( string s , int offset ) {
794
+ // We use `regexpFind` to obtain *all* matches of `${{...}}`,
795
+ // not just the last (greedy match) or first (reluctant match).
796
+ result =
797
+ s .trim ( )
798
+ .regexpFind ( "[A-Za-z0-9'\"_\\[\\]\\*\\(\\)\\.\\-]+" , _, offset )
799
+ .regexpCapture ( "([A-Za-z0-9'\"_\\[\\]\\*\\(\\)\\.\\-]+)" , 1 )
800
+ }
801
+
792
802
/**
793
803
* A ${{}} expression accessing a context variable such as steps, needs, jobs, env, inputs, or matrix.
794
804
* https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
795
805
*/
796
- abstract class ContextExpressionImpl extends ExpressionImpl {
806
+ abstract class SimpleReferenceExpressionImpl extends ExpressionImpl {
807
+ SimpleReferenceExpressionImpl ( ) { exists ( getASimpleReferenceExpression ( expression , _) ) }
808
+
797
809
abstract string getFieldName ( ) ;
798
810
799
811
abstract AstNodeImpl getTarget ( ) ;
@@ -829,7 +841,7 @@ private string wrapRegexp(string regex) {
829
841
* https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
830
842
* e.g. `${{ steps.changed-files.outputs.all_changed_files }}`
831
843
*/
832
- class StepsExpressionImpl extends ContextExpressionImpl {
844
+ class StepsExpressionImpl extends SimpleReferenceExpressionImpl {
833
845
string stepId ;
834
846
string fieldName ;
835
847
@@ -842,7 +854,7 @@ class StepsExpressionImpl extends ContextExpressionImpl {
842
854
override string getFieldName ( ) { result = fieldName }
843
855
844
856
override AstNodeImpl getTarget ( ) {
845
- this .getLocation ( ) . getFile ( ) = result .getLocation ( ) . getFile ( ) and
857
+ this .getEnclosingJob ( ) = result .getEnclosingJob ( ) and
846
858
result .( StepImpl ) .getId ( ) = stepId
847
859
}
848
860
}
@@ -852,7 +864,7 @@ class StepsExpressionImpl extends ContextExpressionImpl {
852
864
* https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
853
865
* e.g. `${{ needs.job1.outputs.foo}}`
854
866
*/
855
- class NeedsExpressionImpl extends ContextExpressionImpl {
867
+ class NeedsExpressionImpl extends SimpleReferenceExpressionImpl {
856
868
JobImpl neededJob ;
857
869
string fieldName ;
858
870
@@ -866,7 +878,10 @@ class NeedsExpressionImpl extends ContextExpressionImpl {
866
878
override string getFieldName ( ) { result = fieldName }
867
879
868
880
override AstNodeImpl getTarget ( ) {
869
- this .getEnclosingJob ( ) .getANeededJob ( ) = neededJob and
881
+ (
882
+ this .getEnclosingJob ( ) .getANeededJob ( ) = neededJob or
883
+ this .getEnclosingJob ( ) = neededJob
884
+ ) and
870
885
(
871
886
// regular jobs
872
887
neededJob .getOutputs ( ) = result
@@ -882,7 +897,7 @@ class NeedsExpressionImpl extends ContextExpressionImpl {
882
897
* https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
883
898
* e.g. `${{ jobs.job1.outputs.foo}}` (within reusable workflows)
884
899
*/
885
- class JobsExpressionImpl extends ContextExpressionImpl {
900
+ class JobsExpressionImpl extends SimpleReferenceExpressionImpl {
886
901
string jobId ;
887
902
string fieldName ;
888
903
@@ -908,7 +923,7 @@ class JobsExpressionImpl extends ContextExpressionImpl {
908
923
* https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
909
924
* e.g. `${{ inputs.foo }}`
910
925
*/
911
- class InputsExpressionImpl extends ContextExpressionImpl {
926
+ class InputsExpressionImpl extends SimpleReferenceExpressionImpl {
912
927
string fieldName ;
913
928
914
929
InputsExpressionImpl ( ) {
@@ -933,7 +948,7 @@ class InputsExpressionImpl extends ContextExpressionImpl {
933
948
* https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
934
949
* e.g. `${{ env.foo }}`
935
950
*/
936
- class EnvExpressionImpl extends ContextExpressionImpl {
951
+ class EnvExpressionImpl extends SimpleReferenceExpressionImpl {
937
952
string fieldName ;
938
953
939
954
EnvExpressionImpl ( ) {
@@ -956,7 +971,7 @@ class EnvExpressionImpl extends ContextExpressionImpl {
956
971
* https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
957
972
* e.g. `${{ matrix.foo }}`
958
973
*/
959
- class MatrixExpressionImpl extends ContextExpressionImpl {
974
+ class MatrixExpressionImpl extends SimpleReferenceExpressionImpl {
960
975
string fieldName ;
961
976
962
977
MatrixExpressionImpl ( ) {
0 commit comments