Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make jobs.<job_id>.steps required in job-factory #98

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions languageservice/src/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ beforeEach(() => {

describe("validation", () => {
it("valid workflow", async () => {
const result = await validate(createDocument("wf.yaml", "on: push\njobs:\n build:\n runs-on: ubuntu-latest"));
const result = await validate(
createDocument("wf.yaml", "on: push\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - run: echo")
);

expect(result.length).toBe(0);
});
Expand Down Expand Up @@ -144,7 +146,9 @@ jobs:
jobs:
build:
runs-on:
- ubuntu-latest`
- ubuntu-latest
steps:
- run: echo hello`
),
{valueProviderConfig: defaultValueProviders}
);
Expand Down Expand Up @@ -174,7 +178,9 @@ jobs:
- cron: '0 0 * *'
jobs:
build:
runs-on: ubuntu-latest`
runs-on: ubuntu-latest
steps:
- run: echo hello`
),
{valueProviderConfig: defaultValueProviders}
);
Expand Down
99 changes: 90 additions & 9 deletions workflow-parser/src/model/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe("convertWorkflowTemplate", () => {
content: `on: push
jobs:
build:
runs-on: ubuntu-latest`
runs-on: ubuntu-latest
steps: []`
},
nullTrace
);
Expand Down Expand Up @@ -55,9 +56,11 @@ jobs:
build:
if: \${{ true }}
runs-on: ubuntu-latest
steps: []
deploy:
if: true
runs-on: ubuntu-latest`
runs-on: ubuntu-latest
steps: []`
},
nullTrace
);
Expand Down Expand Up @@ -105,7 +108,8 @@ jobs:
jobs:
build:
needs: # comment to preserve whitespace in test
runs-on: ubuntu-latest`
runs-on: ubuntu-latest
steps: []`
},
nullTrace
);
Expand Down Expand Up @@ -150,11 +154,17 @@ jobs:
job1:
needs: [unknown-job, job3]
runs-on: ubuntu-latest
steps:
- run: echo job1
job2:
runs-on: ubuntu-latest
steps:
- run: echo job2
job3:
needs: job1
runs-on: ubuntu-latest`
runs-on: ubuntu-latest
steps:
- run: echo job3`
},
nullTrace
);
Expand All @@ -174,7 +184,7 @@ jobs:
},
{
Message:
"wf.yaml (Line: 9, Col: 12): Job 'job3' depends on job 'job1' which creates a cycle in the dependency graph."
"wf.yaml (Line: 13, Col: 12): Job 'job3' depends on job 'job1' which creates a cycle in the dependency graph."
}
],
events: {
Expand All @@ -190,7 +200,16 @@ jobs:
name: "job1",
needs: ["unknown-job", "job3"],
"runs-on": "ubuntu-latest",
steps: [],
steps: [
{
id: "__run",
if: {
expr: "success()",
type: 3
},
run: "echo job1"
}
],
type: "job"
},
{
Expand All @@ -201,7 +220,16 @@ jobs:
},
name: "job2",
"runs-on": "ubuntu-latest",
steps: [],
steps: [
{
id: "__run",
if: {
expr: "success()",
type: 3
},
run: "echo job2"
}
],
type: "job"
},
{
Expand All @@ -213,7 +241,16 @@ jobs:
name: "job3",
needs: ["job1"],
"runs-on": "ubuntu-latest",
steps: [],
steps: [
{
id: "__run",
if: {
expr: "success()",
type: 3
},
run: "echo job3"
}
],
type: "job"
}
]
Expand Down Expand Up @@ -316,6 +353,49 @@ jobs:
});
});

it("converts workflow with one job without steps", async () => {
const result = parseWorkflow(
{
name: "wf.yaml",
content: `on: push
jobs:
build:
runs-on: ubuntu-latest`
},
nullTrace
);

const template = await convertWorkflowTemplate(result.context, result.value!, undefined, {
errorPolicy: ErrorPolicy.TryConversion
});

expect(serializeTemplate(template)).toEqual({
errors: [
{
Message: "wf.yaml (Line: 4, Col: 5): Required property is missing: steps"
}
],
events: {
push: {}
},
jobs: [
{
id: "build",
if: {
expr: "success()",
type: 3
},
name: "build",
needs: undefined,
outputs: undefined,
"runs-on": "ubuntu-latest",
steps: [],
type: "job"
}
]
});
});

// Extra coverage since workflow_call components are not all covered by x-lang parsers
it("converts workflow_call on", async () => {
const result = parseWorkflow(
Expand All @@ -336,7 +416,8 @@ jobs:
secret2:
jobs:
build:
runs-on: ubuntu-latest`
runs-on: ubuntu-latest
steps: []`
},
nullTrace
);
Expand Down
5 changes: 4 additions & 1 deletion workflow-parser/src/workflow-v1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,10 @@
"concurrency": "job-concurrency",
"outputs": "job-outputs",
"defaults": "job-defaults",
"steps": "steps"
"steps": {
"type": "steps",
"required": true
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include-source: false # Drop file/line/col from output
---
on: push
jobs:
build:
runs-on: ubuntu-latest
---
{
"errors": [
{
"Message": ".github/workflows/errors-job-runs-on-and-no-steps.yml (Line: 4, Col: 5): Required property is missing: steps"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ jobs:
build:
runs-on: ubuntu-latest
uses: ./.github/workflows/foo.yml
steps:
- run: echo hello
---
{
"errors": [
Expand Down
Loading