@@ -115,6 +115,9 @@ class JobStmt extends Statement instanceof Actions::Job {
115115 */
116116 string getId ( ) { result = super .getId ( ) }
117117
118+ /** Gets the workflow that this job is a part of. */
119+ WorkflowStmt getWorkflowStmt ( ) { result = super .getWorkflow ( ) }
120+
118121 /** Gets the step at the given index within this job. */
119122 StepStmt getStepStmt ( int index ) { result = super .getStep ( index ) }
120123
@@ -181,6 +184,26 @@ class StepStmt extends Statement instanceof Actions::Step {
181184 string getId ( ) { result = super .getId ( ) }
182185
183186 JobStmt getJobStmt ( ) { result = super .getJob ( ) }
187+
188+ /**
189+ * Gets a environment variable expression by name in the scope of the current step.
190+ */
191+ Expression getEnvExpr ( string name ) {
192+ exists ( Actions:: StepEnv env |
193+ env .getStep ( ) = this and
194+ env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
195+ )
196+ or
197+ exists ( Actions:: JobEnv env |
198+ env .getJob ( ) = this .getJobStmt ( ) and
199+ env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
200+ )
201+ or
202+ exists ( Actions:: WorkflowEnv env |
203+ env .getWorkflow ( ) = this .getJobStmt ( ) .getWorkflowStmt ( ) and
204+ env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
205+ )
206+ }
184207}
185208
186209/**
@@ -192,6 +215,8 @@ abstract class UsesExpr extends Expression {
192215 abstract string getVersion ( ) ;
193216
194217 abstract Expression getArgumentExpr ( string key ) ;
218+
219+ abstract Expression getEnvExpr ( string name ) ;
195220}
196221
197222/**
@@ -212,6 +237,8 @@ class StepUsesExpr extends StepStmt, UsesExpr {
212237 result = with .lookup ( key )
213238 )
214239 }
240+
241+ override Expression getEnvExpr ( string name ) { result = this .( StepStmt ) .getEnvExpr ( name ) }
215242}
216243
217244/**
@@ -260,6 +287,23 @@ class JobUsesExpr extends UsesExpr instanceof YamlMapping {
260287 override Expression getArgumentExpr ( string key ) {
261288 this .( YamlMapping ) .lookup ( "with" ) .( YamlMapping ) .lookup ( key ) = result
262289 }
290+
291+ /**
292+ * Gets a environment variable expression by name in the scope of the current node.
293+ */
294+ override Expression getEnvExpr ( string name ) {
295+ this .( YamlMapping ) .lookup ( "env" ) .( YamlMapping ) .lookup ( name ) = result
296+ or
297+ exists ( Actions:: JobEnv env |
298+ env .getJob ( ) = this .getJobStmt ( ) and
299+ env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
300+ )
301+ or
302+ exists ( Actions:: WorkflowEnv env |
303+ env .getWorkflow ( ) = this .getJobStmt ( ) .getWorkflowStmt ( ) and
304+ env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
305+ )
306+ }
263307}
264308
265309/**
@@ -272,13 +316,6 @@ class RunExpr extends StepStmt, Expression {
272316
273317 Expression getScriptExpr ( ) { result = scriptExpr }
274318
275- Expression getEnvExpr ( string name ) {
276- exists ( Actions:: StepEnv env |
277- env .getStep ( ) = this and
278- env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
279- )
280- }
281-
282319 string getScript ( ) { result = scriptExpr .getValue ( ) }
283320}
284321
0 commit comments