Skip event context validation for workflow_call

This commit is contained in:
Josh Gross
2023-01-25 15:24:57 -05:00
parent a6c1383bfb
commit 64bcc2f287
6 changed files with 139 additions and 96 deletions
@@ -605,6 +605,24 @@ jobs:
// pull_request is part of the pull_request event payload // pull_request is part of the pull_request event payload
expect(result.map(x => x.label)).toContain("pull_request"); expect(result.map(x => x.label)).toContain("pull_request");
}); });
it("includes event payload for workflow_call", async () => {
const input = `
on: [workflow_call]
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo \${{ github.event.| }}
`;
const result = await complete(...getPositionFromCursor(input), undefined, undefined);
// We don't validate github.event for workflow_call,
// but there should still be auto-completion suggestions
expect(result.length).toBeGreaterThan(0);
});
}); });
describe("steps context", () => { describe("steps context", () => {
@@ -52,7 +52,7 @@ function getDefaultContext(name: string, workflowContext: WorkflowContext, mode:
return getEnvContext(workflowContext); return getEnvContext(workflowContext);
case "github": case "github":
return getGithubContext(workflowContext); return getGithubContext(workflowContext, mode);
case "inputs": case "inputs":
return getInputsContext(workflowContext); return getInputsContext(workflowContext);
@@ -47,6 +47,7 @@ import status from "./status.json";
import team from "./team.json"; import team from "./team.json";
import team_add from "./team_add.json"; import team_add from "./team_add.json";
import watch from "./watch.json"; import watch from "./watch.json";
import workflow_call from "./workflow_call.json";
import workflow_dispatch from "./workflow_dispatch.json"; import workflow_dispatch from "./workflow_dispatch.json";
import workflow_run from "./workflow_run.json"; import workflow_run from "./workflow_run.json";
@@ -101,6 +102,7 @@ export const eventPayloads: {[key: string]: Object} = {
team, team,
team_add, team_add,
watch, watch,
workflow_call,
workflow_dispatch, workflow_dispatch,
workflow_run workflow_run
}; };
@@ -1,115 +1,111 @@
{ {
"ref": "refs/tags/simple-tag", "action": "on-demand-test",
"before": "6113728f27ae82c7b1a177c8d03f9e96e0adf246",
"after": "0000000000000000000000000000000000000000",
"created": false,
"deleted": true,
"forced": false,
"base_ref": null,
"compare": "https://github.com/Codertocat/Hello-World/compare/6113728f27ae...000000000000",
"commits": [],
"head_commit": null,
"repository": { "repository": {
"id": 186853002, "id": 17273051,
"node_id": "MDEwOlJlcG9zaXRvcnkxODY4NTMwMDI=", "node_id": "MDEwOlJlcG9zaXRvcnkxNzI3MzA1MQ==",
"name": "Hello-World", "name": "octo-repo",
"full_name": "Codertocat/Hello-World", "full_name": "octo-org/octo-repo",
"private": false, "private": true,
"owner": { "owner": {
"name": "Codertocat", "login": "octo-org",
"email": "[email protected]", "id": 6811672,
"login": "Codertocat", "node_id": "MDEyOk9yZ2FuaXphdGlvbjY4MTE2NzI=",
"id": 21031067, "avatar_url": "https://avatars3.githubusercontent.com/u/6811672?v=4",
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
"gravatar_id": "", "gravatar_id": "",
"url": "https://api.github.com/users/Codertocat", "url": "https://api.github.com/users/octo-org",
"html_url": "https://github.com/Codertocat", "html_url": "https://github.com/octo-org",
"followers_url": "https://api.github.com/users/Codertocat/followers", "followers_url": "https://api.github.com/users/octo-org/followers",
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}", "following_url": "https://api.github.com/users/octo-org/following{/other_user}",
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}", "gists_url": "https://api.github.com/users/octo-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}", "starred_url": "https://api.github.com/users/octo-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions", "subscriptions_url": "https://api.github.com/users/octo-org/subscriptions",
"organizations_url": "https://api.github.com/users/Codertocat/orgs", "organizations_url": "https://api.github.com/users/octo-org/orgs",
"repos_url": "https://api.github.com/users/Codertocat/repos", "repos_url": "https://api.github.com/users/octo-org/repos",
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}", "events_url": "https://api.github.com/users/octo-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/Codertocat/received_events", "received_events_url": "https://api.github.com/users/octo-org/received_events",
"type": "User", "type": "Organization",
"site_admin": false "site_admin": false
}, },
"html_url": "https://github.com/Codertocat/Hello-World", "html_url": "https://github.com/octo-org/octo-repo",
"description": null, "description": "My first repo on GitHub!",
"fork": false, "fork": false,
"url": "https://github.com/Codertocat/Hello-World", "url": "https://api.github.com/repos/octo-org/octo-repo",
"forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks", "forks_url": "https://api.github.com/repos/octo-org/octo-repo/forks",
"keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}", "keys_url": "https://api.github.com/repos/octo-org/octo-repo/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}", "collaborators_url": "https://api.github.com/repos/octo-org/octo-repo/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams", "teams_url": "https://api.github.com/repos/octo-org/octo-repo/teams",
"hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks", "hooks_url": "https://api.github.com/repos/octo-org/octo-repo/hooks",
"issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}", "issue_events_url": "https://api.github.com/repos/octo-org/octo-repo/issues/events{/number}",
"events_url": "https://api.github.com/repos/Codertocat/Hello-World/events", "events_url": "https://api.github.com/repos/octo-org/octo-repo/events",
"assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}", "assignees_url": "https://api.github.com/repos/octo-org/octo-repo/assignees{/user}",
"branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}", "branches_url": "https://api.github.com/repos/octo-org/octo-repo/branches{/branch}",
"tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags", "tags_url": "https://api.github.com/repos/octo-org/octo-repo/tags",
"blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}", "blobs_url": "https://api.github.com/repos/octo-org/octo-repo/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}", "git_tags_url": "https://api.github.com/repos/octo-org/octo-repo/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}", "git_refs_url": "https://api.github.com/repos/octo-org/octo-repo/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}", "trees_url": "https://api.github.com/repos/octo-org/octo-repo/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}", "statuses_url": "https://api.github.com/repos/octo-org/octo-repo/statuses/{sha}",
"languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages", "languages_url": "https://api.github.com/repos/octo-org/octo-repo/languages",
"stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers", "stargazers_url": "https://api.github.com/repos/octo-org/octo-repo/stargazers",
"contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors", "contributors_url": "https://api.github.com/repos/octo-org/octo-repo/contributors",
"subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers", "subscribers_url": "https://api.github.com/repos/octo-org/octo-repo/subscribers",
"subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription", "subscription_url": "https://api.github.com/repos/octo-org/octo-repo/subscription",
"commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}", "commits_url": "https://api.github.com/repos/octo-org/octo-repo/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}", "git_commits_url": "https://api.github.com/repos/octo-org/octo-repo/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}", "comments_url": "https://api.github.com/repos/octo-org/octo-repo/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}", "issue_comment_url": "https://api.github.com/repos/octo-org/octo-repo/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}", "contents_url": "https://api.github.com/repos/octo-org/octo-repo/contents/{+path}",
"compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}", "compare_url": "https://api.github.com/repos/octo-org/octo-repo/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges", "merges_url": "https://api.github.com/repos/octo-org/octo-repo/merges",
"archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}", "archive_url": "https://api.github.com/repos/octo-org/octo-repo/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads", "downloads_url": "https://api.github.com/repos/octo-org/octo-repo/downloads",
"issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}", "issues_url": "https://api.github.com/repos/octo-org/octo-repo/issues{/number}",
"pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}", "pulls_url": "https://api.github.com/repos/octo-org/octo-repo/pulls{/number}",
"milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}", "milestones_url": "https://api.github.com/repos/octo-org/octo-repo/milestones{/number}",
"notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}", "notifications_url": "https://api.github.com/repos/octo-org/octo-repo/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}", "labels_url": "https://api.github.com/repos/octo-org/octo-repo/labels{/name}",
"releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}", "releases_url": "https://api.github.com/repos/octo-org/octo-repo/releases{/id}",
"deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments", "deployments_url": "https://api.github.com/repos/octo-org/octo-repo/deployments",
"created_at": 1557933565, "created_at": "2014-02-28T02:42:51Z",
"updated_at": "2019-05-15T15:20:41Z", "updated_at": "2018-10-10T15:58:51Z",
"pushed_at": 1557933657, "pushed_at": "2018-10-10T15:58:47Z",
"git_url": "git://github.com/Codertocat/Hello-World.git", "git_url": "git://github.com/octo-org/octo-repo.git",
"ssh_url": "[email protected]:Codertocat/Hello-World.git", "ssh_url": "[email protected]:octo-org/octo-repo.git",
"clone_url": "https://github.com/Codertocat/Hello-World.git", "clone_url": "https://github.com/octo-org/octo-repo.git",
"svn_url": "https://github.com/Codertocat/Hello-World", "svn_url": "https://github.com/octo-org/octo-repo",
"homepage": null, "homepage": "",
"size": 0, "size": 59,
"stargazers_count": 0, "stargazers_count": 0,
"watchers_count": 0, "watchers_count": 0,
"language": "Ruby", "language": "JavaScript",
"has_issues": true, "has_issues": true,
"has_projects": true, "has_projects": true,
"has_downloads": true, "has_downloads": true,
"has_wiki": true, "has_wiki": true,
"has_pages": true, "has_pages": false,
"forks_count": 1, "forks_count": 1,
"mirror_url": null, "mirror_url": null,
"archived": false, "archived": false,
"disabled": false, "open_issues_count": 23,
"open_issues_count": 2,
"license": null, "license": null,
"forks": 1, "forks": 1,
"open_issues": 2, "open_issues": 23,
"watchers": 0, "watchers": 0,
"default_branch": "master", "default_branch": "master"
"stargazers": 0,
"master_branch": "master"
}, },
"pusher": { "organization": {
"name": "Codertocat", "login": "octo-org",
"email": "[email protected]" "id": 6811672,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjY4MTE2NzI=",
"url": "https://api.github.com/orgs/octo-org",
"repos_url": "https://api.github.com/orgs/octo-org/repos",
"events_url": "https://api.github.com/orgs/octo-org/events",
"hooks_url": "https://api.github.com/orgs/octo-org/hooks",
"issues_url": "https://api.github.com/orgs/octo-org/issues",
"members_url": "https://api.github.com/orgs/octo-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/octo-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/6811672?v=4",
"description": "Working better together!"
}, },
"sender": { "sender": {
"login": "Codertocat", "login": "Codertocat",
@@ -130,5 +126,9 @@
"received_events_url": "https://api.github.com/users/Codertocat/received_events", "received_events_url": "https://api.github.com/users/Codertocat/received_events",
"type": "User", "type": "User",
"site_admin": false "site_admin": false
},
"installation": {
"id": 375706,
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMzc1NzA2"
} }
} }
@@ -1,11 +1,12 @@
import {data, DescriptionDictionary} from "@github/actions-expressions"; import {data, DescriptionDictionary} from "@github/actions-expressions";
import {ExpressionData} from "@github/actions-expressions/data/expressiondata"; import {ExpressionData} from "@github/actions-expressions/data/expressiondata";
import {WorkflowContext} from "../context/workflow-context"; import {WorkflowContext} from "../context/workflow-context";
import {Mode} from "./default";
import {getDescription} from "./descriptions"; import {getDescription} from "./descriptions";
import {eventPayloads} from "./events/eventPayloads"; import {eventPayloads} from "./events/eventPayloads";
import {getInputsContext} from "./inputs"; import {getInputsContext} from "./inputs";
export function getGithubContext(workflowContext: WorkflowContext): DescriptionDictionary { export function getGithubContext(workflowContext: WorkflowContext, mode: Mode): DescriptionDictionary {
// https://docs.github.com/en/actions/learn-github-actions/contexts#github-cwontext // https://docs.github.com/en/actions/learn-github-actions/contexts#github-cwontext
const keys = [ const keys = [
"action", "action",
@@ -51,7 +52,7 @@ export function getGithubContext(workflowContext: WorkflowContext): DescriptionD
if (key == "event") { if (key == "event") {
return { return {
key, key,
value: getEventContext(workflowContext), value: getEventContext(workflowContext, mode),
description description
}; };
} }
@@ -65,7 +66,7 @@ export function getGithubContext(workflowContext: WorkflowContext): DescriptionD
); );
} }
function getEventContext(workflowContext: WorkflowContext): ExpressionData { function getEventContext(workflowContext: WorkflowContext, mode: Mode): ExpressionData {
const d = new data.Dictionary(); const d = new data.Dictionary();
const eventsConfig = workflowContext?.template?.events; const eventsConfig = workflowContext?.template?.events;
@@ -73,6 +74,12 @@ function getEventContext(workflowContext: WorkflowContext): ExpressionData {
return d; return d;
} }
// For callable workflows, the event is inherited from the calling workflow
// Allow any value for this case
if (eventsConfig.workflow_call && mode == Mode.Validation) {
return new data.Null();
}
const inputs = getInputsContext(workflowContext); const inputs = getInputsContext(workflowContext);
if (inputs.values().length > 0) { if (inputs.values().length > 0) {
d.add("inputs", inputs); d.add("inputs", inputs);
@@ -1254,5 +1254,21 @@ jobs:
expect(result).toEqual([]); expect(result).toEqual([]);
}); });
it("allows any event property for workflow_call", async () => {
const input = `
on:
workflow_call:
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo \${{ github.event.anything }}`;
const result = await validate(createDocument("wf.yaml", input));
expect(result).toEqual([]);
});
}); });
}); });