Inputs and cron in github.event context
This commit is contained in:
@@ -280,6 +280,10 @@ on:
|
|||||||
default: some value
|
default: some value
|
||||||
another-name:
|
another-name:
|
||||||
type: string
|
type: string
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
third-name:
|
||||||
|
type: boolean
|
||||||
jobs:
|
jobs:
|
||||||
a:
|
a:
|
||||||
outputs:
|
outputs:
|
||||||
@@ -295,7 +299,7 @@ jobs:
|
|||||||
`;
|
`;
|
||||||
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
|
|
||||||
expect(result.map(x => x.label)).toEqual(["another-name", "name"]);
|
expect(result.map(x => x.label)).toEqual(["another-name", "name", "third-name"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("no inputs", async () => {
|
it("no inputs", async () => {
|
||||||
@@ -320,21 +324,94 @@ jobs:
|
|||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("github context includes expected keys", async () => {
|
describe("github context", () => {
|
||||||
const input = `
|
it("includes expected keys", async () => {
|
||||||
on: push
|
const input = `
|
||||||
|
on: push
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- run: echo \${{ github.| }}
|
- run: echo \${{ github.| }}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const result = await complete(...getPositionFromCursor(input), undefined, undefined);
|
||||||
|
|
||||||
|
expect(result.map(x => x.label)).toContain("actor");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("includes event inputs", async () => {
|
||||||
|
const input = `
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
default: some value
|
||||||
|
another-name:
|
||||||
|
type: string
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
third-name:
|
||||||
|
type: boolean
|
||||||
|
jobs:
|
||||||
|
a:
|
||||||
|
outputs:
|
||||||
|
build_id: my-build-id
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo hello a
|
||||||
|
b:
|
||||||
|
needs: [a]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo "hello \${{ github.event.inputs.|
|
||||||
`;
|
`;
|
||||||
|
const result = await complete(...getPositionFromCursor(input), undefined, undefined);
|
||||||
|
|
||||||
const result = await complete(...getPositionFromCursor(input), undefined, undefined);
|
expect(result.map(x => x.label)).toEqual(["another-name", "name", "third-name"]);
|
||||||
|
});
|
||||||
|
|
||||||
expect(result.map(x => x.label)).toContain("actor");
|
it("excludes event inputs and cron when no relevant events", async () => {
|
||||||
|
const input = `
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: echo \${{ github.event.| }}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const result = await complete(...getPositionFromCursor(input), undefined, undefined);
|
||||||
|
|
||||||
|
expect(result.map(x => x.label)).not.toContain("inputs");
|
||||||
|
expect(result.map(x => x.label)).not.toContain("cron");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("includes cron schedules", async () => {
|
||||||
|
const input = `
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: echo \${{ github.event.| }}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const result = await complete(...getPositionFromCursor(input), undefined, undefined);
|
||||||
|
|
||||||
|
expect(result.map(x => x.label)).toContain("cron");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("excludes cron scheudle when no schedule", async () => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("steps context", () => {
|
describe("steps context", () => {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export async function getContext(
|
|||||||
function getDefaultContext(name: string, workflowContext: WorkflowContext, mode: Mode): ContextValue | undefined {
|
function getDefaultContext(name: string, workflowContext: WorkflowContext, mode: Mode): ContextValue | undefined {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "github":
|
case "github":
|
||||||
return getGithubContext();
|
return getGithubContext(workflowContext);
|
||||||
|
|
||||||
case "inputs":
|
case "inputs":
|
||||||
return getInputsContext(workflowContext);
|
return getInputsContext(workflowContext);
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import {data} from "@github/actions-expressions";
|
import {data} from "@github/actions-expressions";
|
||||||
|
import {ExpressionData, Pair} from "@github/actions-expressions/data/expressiondata";
|
||||||
|
import {WorkflowContext} from "../context/workflow-context";
|
||||||
|
import {getInputsContext} from "./inputs";
|
||||||
|
|
||||||
export function getGithubContext(): data.Dictionary {
|
export function getGithubContext(workflowContext: WorkflowContext): data.Dictionary {
|
||||||
// https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
|
// https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
|
||||||
const keys = [
|
const keys = [
|
||||||
"action",
|
"action",
|
||||||
@@ -41,7 +44,33 @@ export function getGithubContext(): data.Dictionary {
|
|||||||
|
|
||||||
return new data.Dictionary(
|
return new data.Dictionary(
|
||||||
...keys.map(key => {
|
...keys.map(key => {
|
||||||
|
if (key == "event") {
|
||||||
|
return {key, value: getEventContext(workflowContext)};
|
||||||
|
}
|
||||||
|
|
||||||
return {key, value: new data.Null()};
|
return {key, value: new data.Null()};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getEventContext(workflowContext: WorkflowContext): ExpressionData {
|
||||||
|
const d = new data.Dictionary();
|
||||||
|
const events = workflowContext?.template?.events;
|
||||||
|
|
||||||
|
if (!events) {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputs = getInputsContext(workflowContext);
|
||||||
|
if (inputs.values().length > 0) {
|
||||||
|
d.add("inputs", inputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
const schedule = events["schedule"];
|
||||||
|
if (schedule && schedule.length > 0) {
|
||||||
|
const default_cron = schedule[0].cron;
|
||||||
|
d.add("cron", new data.StringData(default_cron));
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|||||||
@@ -777,4 +777,86 @@ jobs:
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("github context", () => {
|
||||||
|
it("includes only expected keys", async () => {
|
||||||
|
const input = `
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo \${{ github.action }}
|
||||||
|
- run: echo \${{ github.steps }}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const result = await validate(createDocument("wf.yaml", input));
|
||||||
|
|
||||||
|
expect(result).toEqual([
|
||||||
|
{
|
||||||
|
message: "Context access might be invalid: steps",
|
||||||
|
range: {
|
||||||
|
end: {
|
||||||
|
character: 37,
|
||||||
|
line: 8
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
character: 18,
|
||||||
|
line: 8
|
||||||
|
}
|
||||||
|
},
|
||||||
|
severity: DiagnosticSeverity.Warning
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it("validates event inputs", async () => {
|
||||||
|
const input = `
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
default: some value
|
||||||
|
another-name:
|
||||||
|
type: string
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
third-name:
|
||||||
|
type: boolean
|
||||||
|
jobs:
|
||||||
|
a:
|
||||||
|
outputs:
|
||||||
|
build_id: my-build-id
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo hello a
|
||||||
|
b:
|
||||||
|
needs: [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 }}"
|
||||||
|
`;
|
||||||
|
const result = await validate(createDocument("wf.yaml", input));
|
||||||
|
|
||||||
|
expect(result).toEqual([
|
||||||
|
{
|
||||||
|
message: "Context access might be invalid: random",
|
||||||
|
range: {
|
||||||
|
end: {
|
||||||
|
character: 56,
|
||||||
|
line: 26
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
character: 23,
|
||||||
|
line: 26
|
||||||
|
}
|
||||||
|
},
|
||||||
|
severity: DiagnosticSeverity.Warning
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user