Skip secret validation for workflow_call

This commit is contained in:
Beth Brennan
2023-03-13 17:24:05 -04:00
parent 7b3116801d
commit 28dde4d6ac
3 changed files with 37 additions and 15 deletions
+12 -11
View File
@@ -16,13 +16,24 @@ export async function getSecrets(
defaultContext: DescriptionDictionary | undefined, defaultContext: DescriptionDictionary | undefined,
mode: Mode mode: Mode
): Promise<DescriptionDictionary> { ): Promise<DescriptionDictionary> {
const secretsContext = defaultContext || new DescriptionDictionary();
const permission = await getRepoPermission(octokit, cache, repo); const permission = await getRepoPermission(octokit, cache, repo);
if (permission === "none") { if (permission === "none") {
const secretsContext = defaultContext || new DescriptionDictionary();
secretsContext.complete = false; secretsContext.complete = false;
return secretsContext; return secretsContext;
} }
const eventsConfig = workflowContext?.template?.events;
if (eventsConfig?.workflow_call) {
// Unpredictible secrets may be pased in via a workflow_call trigger
secretsContext.complete = false;
// Exit early for validation mode or if workflow_call is the only trigger
if (mode === Mode.Validation || Object.keys(eventsConfig).length == 1) {
return secretsContext;
}
}
let environmentName: string | undefined; let environmentName: string | undefined;
if (workflowContext?.job?.environment) { if (workflowContext?.job?.environment) {
if (isString(workflowContext.job.environment)) { if (isString(workflowContext.job.environment)) {
@@ -39,16 +50,6 @@ export async function getSecrets(
} }
} }
const secretsContext = defaultContext || new DescriptionDictionary();
// Exit early if workflow_call is the only trigger
if (mode === Mode.Completion) {
const eventsConfig = workflowContext?.template?.events;
if (eventsConfig?.workflow_call && Object.keys(eventsConfig).length == 1) {
return secretsContext;
}
}
const secrets = await getRemoteSecrets(octokit, cache, repo, environmentName); const secrets = await getRemoteSecrets(octokit, cache, repo, environmentName);
// Build combined map of secrets // Build combined map of secrets
@@ -11,10 +11,12 @@ export function getSecretsContext(workflowContext: WorkflowContext, mode: Mode):
description: getDescription("secrets", "GITHUB_TOKEN") description: getDescription("secrets", "GITHUB_TOKEN")
}); });
if (mode === Mode.Completion) { const eventsConfig = workflowContext?.template?.events;
const eventsConfig = workflowContext?.template?.events; if (eventsConfig?.workflow_call) {
if (eventsConfig?.workflow_call?.secrets) { // Unpredictible secrets may be pased in via a workflow_call trigger
for (const [name, value] of Object.entries(eventsConfig.workflow_call.secrets)) { d.complete = false;
if (mode === Mode.Completion) {
for (const [name, value] of Object.entries(eventsConfig.workflow_call.secrets || {})) {
d.add(name, new StringData(""), value.description); d.add(name, new StringData(""), value.description);
} }
} }
@@ -98,6 +98,25 @@ jobs:
]); ]);
}); });
it("no secret validation with workflow_call", async () => {
const input = `
on:
workflow_call:
secrets:
my_secret:
env:
my_secret: \${{ secrets.my_secret }}
secret: \${{ secrets.secret-not-exist }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: echo`;
const result = await validate(createDocument("wf.yaml", input));
expect(result).toEqual([]);
});
it("access invalid nested context field", async () => { it("access invalid nested context field", async () => {
const result = await validate( const result = await validate(
createDocument( createDocument(