Skip to content

Commit aa1e7d8

Browse files
authored
Add deployment key support for job environment (#338)
Add a boolean 'deployment' property to the job environment mapping. When set to false, the parsed environment reference sets skipDeployment to signal that no deployment record should be created.
1 parent bd6ce59 commit aa1e7d8

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed

languageservice/src/validate.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,24 @@ jobs:
368368
});
369369
});
370370

371+
describe("environment deployment", () => {
372+
it("allows deployment boolean under environment mapping", async () => {
373+
const workflow = `
374+
on: push
375+
jobs:
376+
build:
377+
runs-on: ubuntu-latest
378+
environment:
379+
name: prod
380+
deployment: false
381+
steps:
382+
- run: echo
383+
`;
384+
const result = await validate(createDocument("wf.yaml", workflow));
385+
expect(result).toEqual([]);
386+
});
387+
});
388+
371389
describe("workflow_dispatch", () => {
372390
it("allows empty string in choice options", async () => {
373391
const result = await validate(

workflow-parser/src/model/converter/job/environment.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export function convertToActionsEnvironmentRef(
3434
case "url":
3535
result.url = property.value;
3636
break;
37+
38+
case "deployment": {
39+
const deploymentValue = property.value.assertBoolean("job environment deployment");
40+
if (deploymentValue.value === false) {
41+
result.skipDeployment = true;
42+
}
43+
break;
44+
}
3745
}
3846
}
3947

workflow-parser/src/model/workflow-template.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type ConcurrencySetting = {
2626
export type ActionsEnvironmentReference = {
2727
name?: TemplateToken;
2828
url?: TemplateToken;
29+
skipDeployment?: boolean;
2930
};
3031

3132
export type WorkflowJob = Job | ReusableWorkflowJob;

workflow-parser/src/workflow-v1.0.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,10 @@
20792079
"url": {
20802080
"type": "string-runner-context-no-secrets",
20812081
"description": "The environment URL, which maps to `environment_url` in the deployments API."
2082+
},
2083+
"deployment": {
2084+
"type": "boolean",
2085+
"description": "Whether to create a deployment record for this environment. Defaults to true."
20822086
}
20832087
}
20842088
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
include-source: false # Drop file/line/col from output
2+
skip:
3+
- C#
4+
---
5+
on: push
6+
jobs:
7+
build:
8+
environment:
9+
name: production
10+
deployment: false
11+
runs-on: ubuntu-latest
12+
steps:
13+
- run: echo hi
14+
build2:
15+
environment:
16+
name: staging
17+
deployment: true
18+
runs-on: ubuntu-latest
19+
steps:
20+
- run: echo hi
21+
---
22+
{
23+
"jobs": [
24+
{
25+
"type": "job",
26+
"id": "build",
27+
"name": "build",
28+
"if": {
29+
"type": 3,
30+
"expr": "success()"
31+
},
32+
"environment": {
33+
"type": 2,
34+
"map": [
35+
{
36+
"Key": "name",
37+
"Value": "production"
38+
},
39+
{
40+
"Key": "deployment",
41+
"Value": false
42+
}
43+
]
44+
},
45+
"runs-on": "ubuntu-latest",
46+
"steps": [
47+
{
48+
"id": "__run",
49+
"if": {
50+
"type": 3,
51+
"expr": "success()"
52+
},
53+
"run": "echo hi"
54+
}
55+
]
56+
},
57+
{
58+
"type": "job",
59+
"id": "build2",
60+
"name": "build2",
61+
"if": {
62+
"type": 3,
63+
"expr": "success()"
64+
},
65+
"environment": {
66+
"type": 2,
67+
"map": [
68+
{
69+
"Key": "name",
70+
"Value": "staging"
71+
},
72+
{
73+
"Key": "deployment",
74+
"Value": true
75+
}
76+
]
77+
},
78+
"runs-on": "ubuntu-latest",
79+
"steps": [
80+
{
81+
"id": "__run",
82+
"if": {
83+
"type": 3,
84+
"expr": "success()"
85+
},
86+
"run": "echo hi"
87+
}
88+
]
89+
}
90+
]
91+
}

0 commit comments

Comments
 (0)