Merge pull request #106 from github/joshmgross/workflow_call-validation
Skip event context validation for `workflow_call`
This commit is contained in:
@@ -612,6 +612,24 @@ jobs:
|
||||
// pull_request is part of the pull_request event payload
|
||||
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", () => {
|
||||
|
||||
@@ -52,7 +52,7 @@ function getDefaultContext(name: string, workflowContext: WorkflowContext, mode:
|
||||
return getEnvContext(workflowContext);
|
||||
|
||||
case "github":
|
||||
return getGithubContext(workflowContext);
|
||||
return getGithubContext(workflowContext, mode);
|
||||
|
||||
case "inputs":
|
||||
return getInputsContext(workflowContext);
|
||||
|
||||
@@ -47,6 +47,7 @@ import status from "./status.json" assert {type: "json"};
|
||||
import team from "./team.json" assert {type: "json"};
|
||||
import team_add from "./team_add.json" assert {type: "json"};
|
||||
import watch from "./watch.json" assert {type: "json"};
|
||||
import workflow_call from "./workflow_call.json" assert {type: "json"};
|
||||
import workflow_dispatch from "./workflow_dispatch.json" assert {type: "json"};
|
||||
import workflow_run from "./workflow_run.json" assert {type: "json"};
|
||||
|
||||
@@ -101,6 +102,7 @@ export const eventPayloads: {[key: string]: Object} = {
|
||||
team,
|
||||
team_add,
|
||||
watch,
|
||||
workflow_call,
|
||||
workflow_dispatch,
|
||||
workflow_run
|
||||
};
|
||||
|
||||
@@ -1,115 +1,111 @@
|
||||
{
|
||||
"ref": "refs/tags/simple-tag",
|
||||
"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,
|
||||
"action": "on-demand-test",
|
||||
"repository": {
|
||||
"id": 186853002,
|
||||
"node_id": "MDEwOlJlcG9zaXRvcnkxODY4NTMwMDI=",
|
||||
"name": "Hello-World",
|
||||
"full_name": "Codertocat/Hello-World",
|
||||
"private": false,
|
||||
"id": 17273051,
|
||||
"node_id": "MDEwOlJlcG9zaXRvcnkxNzI3MzA1MQ==",
|
||||
"name": "octo-repo",
|
||||
"full_name": "octo-org/octo-repo",
|
||||
"private": true,
|
||||
"owner": {
|
||||
"name": "Codertocat",
|
||||
"email": "[email protected]",
|
||||
"login": "Codertocat",
|
||||
"id": 21031067,
|
||||
"node_id": "MDQ6VXNlcjIxMDMxMDY3",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
|
||||
"login": "octo-org",
|
||||
"id": 6811672,
|
||||
"node_id": "MDEyOk9yZ2FuaXphdGlvbjY4MTE2NzI=",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/6811672?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/Codertocat",
|
||||
"html_url": "https://github.com/Codertocat",
|
||||
"followers_url": "https://api.github.com/users/Codertocat/followers",
|
||||
"following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/Codertocat/orgs",
|
||||
"repos_url": "https://api.github.com/users/Codertocat/repos",
|
||||
"events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
|
||||
"type": "User",
|
||||
"url": "https://api.github.com/users/octo-org",
|
||||
"html_url": "https://github.com/octo-org",
|
||||
"followers_url": "https://api.github.com/users/octo-org/followers",
|
||||
"following_url": "https://api.github.com/users/octo-org/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/octo-org/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/octo-org/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/octo-org/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/octo-org/orgs",
|
||||
"repos_url": "https://api.github.com/users/octo-org/repos",
|
||||
"events_url": "https://api.github.com/users/octo-org/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/octo-org/received_events",
|
||||
"type": "Organization",
|
||||
"site_admin": false
|
||||
},
|
||||
"html_url": "https://github.com/Codertocat/Hello-World",
|
||||
"description": null,
|
||||
"html_url": "https://github.com/octo-org/octo-repo",
|
||||
"description": "My first repo on GitHub!",
|
||||
"fork": false,
|
||||
"url": "https://github.com/Codertocat/Hello-World",
|
||||
"forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks",
|
||||
"keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}",
|
||||
"collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}",
|
||||
"teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams",
|
||||
"hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks",
|
||||
"issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}",
|
||||
"events_url": "https://api.github.com/repos/Codertocat/Hello-World/events",
|
||||
"assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}",
|
||||
"branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}",
|
||||
"tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags",
|
||||
"blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}",
|
||||
"git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}",
|
||||
"git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}",
|
||||
"trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}",
|
||||
"statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}",
|
||||
"languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages",
|
||||
"stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers",
|
||||
"contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors",
|
||||
"subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers",
|
||||
"subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription",
|
||||
"commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}",
|
||||
"git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}",
|
||||
"comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}",
|
||||
"issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}",
|
||||
"contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}",
|
||||
"compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}",
|
||||
"merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges",
|
||||
"archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}",
|
||||
"downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads",
|
||||
"issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}",
|
||||
"pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}",
|
||||
"milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}",
|
||||
"notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}",
|
||||
"labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}",
|
||||
"releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}",
|
||||
"deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments",
|
||||
"created_at": 1557933565,
|
||||
"updated_at": "2019-05-15T15:20:41Z",
|
||||
"pushed_at": 1557933657,
|
||||
"git_url": "git://github.com/Codertocat/Hello-World.git",
|
||||
"ssh_url": "[email protected]:Codertocat/Hello-World.git",
|
||||
"clone_url": "https://github.com/Codertocat/Hello-World.git",
|
||||
"svn_url": "https://github.com/Codertocat/Hello-World",
|
||||
"homepage": null,
|
||||
"size": 0,
|
||||
"url": "https://api.github.com/repos/octo-org/octo-repo",
|
||||
"forks_url": "https://api.github.com/repos/octo-org/octo-repo/forks",
|
||||
"keys_url": "https://api.github.com/repos/octo-org/octo-repo/keys{/key_id}",
|
||||
"collaborators_url": "https://api.github.com/repos/octo-org/octo-repo/collaborators{/collaborator}",
|
||||
"teams_url": "https://api.github.com/repos/octo-org/octo-repo/teams",
|
||||
"hooks_url": "https://api.github.com/repos/octo-org/octo-repo/hooks",
|
||||
"issue_events_url": "https://api.github.com/repos/octo-org/octo-repo/issues/events{/number}",
|
||||
"events_url": "https://api.github.com/repos/octo-org/octo-repo/events",
|
||||
"assignees_url": "https://api.github.com/repos/octo-org/octo-repo/assignees{/user}",
|
||||
"branches_url": "https://api.github.com/repos/octo-org/octo-repo/branches{/branch}",
|
||||
"tags_url": "https://api.github.com/repos/octo-org/octo-repo/tags",
|
||||
"blobs_url": "https://api.github.com/repos/octo-org/octo-repo/git/blobs{/sha}",
|
||||
"git_tags_url": "https://api.github.com/repos/octo-org/octo-repo/git/tags{/sha}",
|
||||
"git_refs_url": "https://api.github.com/repos/octo-org/octo-repo/git/refs{/sha}",
|
||||
"trees_url": "https://api.github.com/repos/octo-org/octo-repo/git/trees{/sha}",
|
||||
"statuses_url": "https://api.github.com/repos/octo-org/octo-repo/statuses/{sha}",
|
||||
"languages_url": "https://api.github.com/repos/octo-org/octo-repo/languages",
|
||||
"stargazers_url": "https://api.github.com/repos/octo-org/octo-repo/stargazers",
|
||||
"contributors_url": "https://api.github.com/repos/octo-org/octo-repo/contributors",
|
||||
"subscribers_url": "https://api.github.com/repos/octo-org/octo-repo/subscribers",
|
||||
"subscription_url": "https://api.github.com/repos/octo-org/octo-repo/subscription",
|
||||
"commits_url": "https://api.github.com/repos/octo-org/octo-repo/commits{/sha}",
|
||||
"git_commits_url": "https://api.github.com/repos/octo-org/octo-repo/git/commits{/sha}",
|
||||
"comments_url": "https://api.github.com/repos/octo-org/octo-repo/comments{/number}",
|
||||
"issue_comment_url": "https://api.github.com/repos/octo-org/octo-repo/issues/comments{/number}",
|
||||
"contents_url": "https://api.github.com/repos/octo-org/octo-repo/contents/{+path}",
|
||||
"compare_url": "https://api.github.com/repos/octo-org/octo-repo/compare/{base}...{head}",
|
||||
"merges_url": "https://api.github.com/repos/octo-org/octo-repo/merges",
|
||||
"archive_url": "https://api.github.com/repos/octo-org/octo-repo/{archive_format}{/ref}",
|
||||
"downloads_url": "https://api.github.com/repos/octo-org/octo-repo/downloads",
|
||||
"issues_url": "https://api.github.com/repos/octo-org/octo-repo/issues{/number}",
|
||||
"pulls_url": "https://api.github.com/repos/octo-org/octo-repo/pulls{/number}",
|
||||
"milestones_url": "https://api.github.com/repos/octo-org/octo-repo/milestones{/number}",
|
||||
"notifications_url": "https://api.github.com/repos/octo-org/octo-repo/notifications{?since,all,participating}",
|
||||
"labels_url": "https://api.github.com/repos/octo-org/octo-repo/labels{/name}",
|
||||
"releases_url": "https://api.github.com/repos/octo-org/octo-repo/releases{/id}",
|
||||
"deployments_url": "https://api.github.com/repos/octo-org/octo-repo/deployments",
|
||||
"created_at": "2014-02-28T02:42:51Z",
|
||||
"updated_at": "2018-10-10T15:58:51Z",
|
||||
"pushed_at": "2018-10-10T15:58:47Z",
|
||||
"git_url": "git://github.com/octo-org/octo-repo.git",
|
||||
"ssh_url": "[email protected]:octo-org/octo-repo.git",
|
||||
"clone_url": "https://github.com/octo-org/octo-repo.git",
|
||||
"svn_url": "https://github.com/octo-org/octo-repo",
|
||||
"homepage": "",
|
||||
"size": 59,
|
||||
"stargazers_count": 0,
|
||||
"watchers_count": 0,
|
||||
"language": "Ruby",
|
||||
"language": "JavaScript",
|
||||
"has_issues": true,
|
||||
"has_projects": true,
|
||||
"has_downloads": true,
|
||||
"has_wiki": true,
|
||||
"has_pages": true,
|
||||
"has_pages": false,
|
||||
"forks_count": 1,
|
||||
"mirror_url": null,
|
||||
"archived": false,
|
||||
"disabled": false,
|
||||
"open_issues_count": 2,
|
||||
"open_issues_count": 23,
|
||||
"license": null,
|
||||
"forks": 1,
|
||||
"open_issues": 2,
|
||||
"open_issues": 23,
|
||||
"watchers": 0,
|
||||
"default_branch": "master",
|
||||
"stargazers": 0,
|
||||
"master_branch": "master"
|
||||
"default_branch": "master"
|
||||
},
|
||||
"pusher": {
|
||||
"name": "Codertocat",
|
||||
"email": "[email protected]"
|
||||
"organization": {
|
||||
"login": "octo-org",
|
||||
"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": {
|
||||
"login": "Codertocat",
|
||||
@@ -130,5 +126,9 @@
|
||||
"received_events_url": "https://api.github.com/users/Codertocat/received_events",
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
},
|
||||
"installation": {
|
||||
"id": 375706,
|
||||
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMzc1NzA2"
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
import {data, DescriptionDictionary} from "@github/actions-expressions";
|
||||
import {ExpressionData} from "@github/actions-expressions/data/expressiondata";
|
||||
import {WorkflowContext} from "../context/workflow-context";
|
||||
import {Mode} from "./default";
|
||||
import {getDescription} from "./descriptions";
|
||||
import {eventPayloads} from "./events/eventPayloads";
|
||||
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
|
||||
const keys = [
|
||||
"action",
|
||||
@@ -51,7 +52,7 @@ export function getGithubContext(workflowContext: WorkflowContext): DescriptionD
|
||||
if (key == "event") {
|
||||
return {
|
||||
key,
|
||||
value: getEventContext(workflowContext),
|
||||
value: getEventContext(workflowContext, mode),
|
||||
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 eventsConfig = workflowContext?.template?.events;
|
||||
|
||||
@@ -73,6 +74,13 @@ function getEventContext(workflowContext: WorkflowContext): ExpressionData {
|
||||
return d;
|
||||
}
|
||||
|
||||
// For callable workflows, the event is inherited from the calling workflow
|
||||
// Allow any value for this case
|
||||
// This includes github.event.inputs, which is only available via the inputs context
|
||||
if (eventsConfig.workflow_call && mode == Mode.Validation) {
|
||||
return new data.Null();
|
||||
}
|
||||
|
||||
const inputs = getInputsContext(workflowContext);
|
||||
if (inputs.values().length > 0) {
|
||||
d.add("inputs", inputs);
|
||||
|
||||
@@ -1164,7 +1164,45 @@ jobs:
|
||||
]);
|
||||
});
|
||||
|
||||
it("validates event inputs", async () => {
|
||||
it("validates event inputs via github.event", async () => {
|
||||
const input = `
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
name:
|
||||
type: string
|
||||
default: some value
|
||||
another-name:
|
||||
type: string
|
||||
jobs:
|
||||
a:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "hello \${{ github.event.inputs.name }}"
|
||||
- run: echo "hello \${{ github.event.inputs.another-name }}"
|
||||
- run: echo "hello \${{ github.event.inputs.random }}"
|
||||
`;
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
message: "Context access might be invalid: random",
|
||||
range: {
|
||||
start: {
|
||||
character: 23,
|
||||
line: 15
|
||||
},
|
||||
end: {
|
||||
character: 56,
|
||||
line: 15
|
||||
}
|
||||
},
|
||||
severity: 2
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("validates event inputs via inputs context", async () => {
|
||||
const input = `
|
||||
on:
|
||||
workflow_dispatch:
|
||||
@@ -1182,9 +1220,6 @@ jobs:
|
||||
a:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "hello \${{ github.event.inputs.name }}"
|
||||
- run: echo "hello \${{ github.event.inputs.third-name }}"
|
||||
- run: echo "hello \${{ github.event.inputs.random }}"
|
||||
- run: echo \${{ fromJSON(inputs.random2) }}
|
||||
- run: echo "hello \${{ inputs.random }}"
|
||||
name: "\${{ fromJSON('test') == inputs.name }}"
|
||||
@@ -1192,47 +1227,33 @@ jobs:
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
message: "Context access might be invalid: random2",
|
||||
range: {
|
||||
start: {
|
||||
character: 16,
|
||||
line: 17
|
||||
},
|
||||
end: {
|
||||
character: 47,
|
||||
line: 17
|
||||
}
|
||||
},
|
||||
severity: 2
|
||||
},
|
||||
{
|
||||
message: "Context access might be invalid: random",
|
||||
range: {
|
||||
end: {
|
||||
character: 56,
|
||||
line: 19
|
||||
},
|
||||
start: {
|
||||
character: 23,
|
||||
line: 19
|
||||
line: 18
|
||||
},
|
||||
end: {
|
||||
character: 43,
|
||||
line: 18
|
||||
}
|
||||
},
|
||||
severity: DiagnosticSeverity.Warning
|
||||
},
|
||||
{
|
||||
message: "Context access might be invalid: random2",
|
||||
range: {
|
||||
end: {
|
||||
character: 47,
|
||||
line: 20
|
||||
},
|
||||
start: {
|
||||
character: 16,
|
||||
line: 20
|
||||
}
|
||||
},
|
||||
severity: 2
|
||||
},
|
||||
{
|
||||
message: "Context access might be invalid: random",
|
||||
range: {
|
||||
end: {
|
||||
character: 43,
|
||||
line: 21
|
||||
},
|
||||
start: {
|
||||
character: 23,
|
||||
line: 21
|
||||
}
|
||||
},
|
||||
severity: 2
|
||||
}
|
||||
]);
|
||||
});
|
||||
@@ -1254,5 +1275,21 @@ jobs:
|
||||
|
||||
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([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user