diff --git a/actions-languageserver/src/context-providers/secrets.ts b/actions-languageserver/src/context-providers/secrets.ts index 61c6ca0..85ad93d 100644 --- a/actions-languageserver/src/context-providers/secrets.ts +++ b/actions-languageserver/src/context-providers/secrets.ts @@ -2,6 +2,7 @@ import {data, DescriptionDictionary} from "@github/actions-expressions"; import {StringData} from "@github/actions-expressions/data/string"; import {WorkflowContext} from "@github/actions-languageservice/context/workflow-context"; import {isMapping, isString} from "@github/actions-workflow-parser"; +import {isJob} from "@github/actions-workflow-parser/model/type-guards"; import {Octokit} from "@octokit/rest"; import {RepositoryContext} from "../initializationOptions"; import {TTLCache} from "../utils/cache"; @@ -14,11 +15,13 @@ export async function getSecrets( defaultContext: DescriptionDictionary | undefined ): Promise { let environmentName: string | undefined; - if (workflowContext?.job?.environment) { - if (isString(workflowContext.job.environment)) { - environmentName = workflowContext.job.environment.value; - } else if (isMapping(workflowContext.job.environment)) { - for (const x of workflowContext.job.environment) { + const job = workflowContext?.job; + const environment = job && isJob(job) && job.environment; + if (environment) { + if (isString(environment)) { + environmentName = environment.value; + } else if (isMapping(environment)) { + for (const x of environment) { if (isString(x.key) && x.key.value === "name") { if (isString(x.value)) { environmentName = x.value.value; diff --git a/actions-languageserver/src/context-providers/steps.ts b/actions-languageserver/src/context-providers/steps.ts index eea315b..a3bed5e 100644 --- a/actions-languageserver/src/context-providers/steps.ts +++ b/actions-languageserver/src/context-providers/steps.ts @@ -1,7 +1,7 @@ import {data, DescriptionDictionary, isDescriptionDictionary} from "@github/actions-expressions"; import {parseActionReference} from "@github/actions-languageservice/action"; import {WorkflowContext} from "@github/actions-languageservice/context/workflow-context"; -import {isActionStep} from "@github/actions-workflow-parser/model/type-guards"; +import {isActionStep, isReusableWorkflowJob} from "@github/actions-workflow-parser/model/type-guards"; import {Octokit} from "@octokit/rest"; import {TTLCache} from "../utils/cache"; import {getActionOutputs} from "./action-outputs"; @@ -12,7 +12,8 @@ export async function getStepsContext( defaultContext: DescriptionDictionary | undefined, workflowContext: WorkflowContext ): Promise { - if (!defaultContext || !workflowContext.job) { + const job = workflowContext.job; + if (!defaultContext || !job || isReusableWorkflowJob(job)) { return defaultContext; } @@ -26,7 +27,7 @@ export async function getStepsContext( // Copy the default context for each step // If the step is an action, add the action outputs to the context const stepsContext = new DescriptionDictionary(); - for (const step of workflowContext.job.steps) { + for (const step of job.steps) { if (!contextSteps.has(step.id)) { continue; } diff --git a/actions-languageserver/src/context-providers/variables.ts b/actions-languageserver/src/context-providers/variables.ts index 52babbd..d14b20b 100644 --- a/actions-languageserver/src/context-providers/variables.ts +++ b/actions-languageserver/src/context-providers/variables.ts @@ -6,6 +6,7 @@ import {Pair} from "@github/actions-expressions/data/expressiondata"; import {RepositoryContext} from "../initializationOptions"; import {StringData} from "@github/actions-expressions/data/index"; import {TTLCache} from "../utils/cache"; +import {isJob} from "@github/actions-workflow-parser/model/type-guards"; export async function getVariables( workflowContext: WorkflowContext, @@ -15,11 +16,13 @@ export async function getVariables( defaultContext: DescriptionDictionary | undefined ): Promise { let environmentName: string | undefined; - if (workflowContext?.job?.environment) { - if (isString(workflowContext.job.environment)) { - environmentName = workflowContext.job.environment.value; - } else if (isMapping(workflowContext.job.environment)) { - for (const x of workflowContext.job.environment) { + const job = workflowContext?.job; + const environment = job && isJob(job) && job.environment; + if (environment) { + if (isString(environment)) { + environmentName = environment.value; + } else if (isMapping(environment)) { + for (const x of environment) { if (isString(x.key) && x.key.value === "name") { if (isString(x.value)) { environmentName = x.value.value; diff --git a/actions-languageserver/src/test-utils/workflow-context.ts b/actions-languageserver/src/test-utils/workflow-context.ts index aef5cfe..44b3654 100644 --- a/actions-languageserver/src/test-utils/workflow-context.ts +++ b/actions-languageserver/src/test-utils/workflow-context.ts @@ -1,5 +1,6 @@ import {WorkflowContext} from "@github/actions-languageservice/context/workflow-context"; import {convertWorkflowTemplate, parseWorkflow, TraceWriter} from "@github/actions-workflow-parser"; +import {isJob} from "@github/actions-workflow-parser/model/type-guards"; const nullTrace: TraceWriter = { info: x => {}, @@ -19,8 +20,8 @@ export function createWorkflowContext(workflow: string, job?: string, stepIndex? context.job = template.jobs.find(j => j.id.value === job); } - if (stepIndex !== undefined) { - context.step = context.job?.steps[stepIndex]; + if (stepIndex !== undefined && context.job && isJob(context.job)) { + context.step = context.job.steps[stepIndex]; } return context;