Skip to content

Commit a796a7b

Browse files
committed
Implement support for job inherits keyword
Adds the `inherits` keyword to job definitions, as described on https://docs.gitlab.com/ee/ci/yaml/index.html#inherit. Also examples/inherit-examples.dhall as a test & example.
1 parent 428aec4 commit a796a7b

File tree

11 files changed

+147
-1
lines changed

11 files changed

+147
-1
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ jobs:
1717
- uses: dhall-lang/setup-dhall@v4
1818
- run: dhall text --file examples/single-job.dhall
1919
- run: dhall text --file examples/multiple-jobs.dhall
20+
- run: dhall text --file examples/inehrit-examples.dhall

GitLab/Inherit/Type.dhall

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Several fields either allow you to set a global default (true/false)
2+
-- or a list of keywords (such as variable names). So we define `Choice`
3+
-- to represent those fields.
4+
let Choice = <Defaults : Bool | Keywords : List Text>
5+
6+
-- Implements the `inherit` keyword provided for jobs (https://docs.gitlab.com/ee/ci/yaml/index.html#inherit)
7+
8+
let Inherit = {
9+
`default`: Optional Choice,
10+
variables: Optional Choice
11+
}
12+
13+
in { Inherit, Choice }

GitLab/Inherit/package.dhall

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let Types = ./Type.dhall
2+
3+
in { Type = Types.Inherit
4+
, Choice = Types.Choice
5+
, default = None Types.Inherit
6+
, toJSON = ./toJSON.dhall
7+
}

GitLab/Inherit/toJSON.dhall

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
let Prelude = ../Prelude.dhall
2+
3+
let Optional/map = Prelude.Optional.map
4+
5+
let Map = Prelude.Map
6+
7+
let JSON = Prelude.JSON
8+
9+
let dropNones = ../utils/dropNones.dhall
10+
11+
let Types = ./Type.dhall
12+
13+
let choiceToJSON = λ(choice : Types.Choice) merge {
14+
Defaults = λ(b : Bool) JSON.bool b,
15+
Keywords = λ(ks : List Text) -> JSON.array
16+
( Prelude.List.map
17+
Text
18+
JSON.Type
19+
JSON.string
20+
ks
21+
)
22+
} choice
23+
24+
let Inherit/toJSON : Types.Inherit JSON.Type = λ(inherit : Types.Inherit)
25+
let everything = toMap {
26+
`default` = Optional/map Types.Choice JSON.Type choiceToJSON inherit.`default`,
27+
variables = Optional/map Types.Choice JSON.Type choiceToJSON inherit.variables
28+
}
29+
30+
in JSON.object (dropNones Text JSON.Type everything)
31+
32+
in Inherit/toJSON

GitLab/Job/Type.dhall

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ let Rule = ../Rule/Type.dhall
1616

1717
let Trigger = ../Trigger/Type.dhall
1818

19+
let Inherit = ../Inherit/package.dhall
20+
1921
in { stage : Optional Text
2022
, image : Optional Image
2123
, variables : Prelude.Map.Type Text Text
@@ -35,4 +37,5 @@ in { stage : Optional Text
3537
, trigger : Optional Trigger
3638
, timeout : Optional Text
3739
, extends : List Text
40+
, inherit : Optional Inherit.Type
3841
}

GitLab/Job/append.dhall

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ let Rule = ../Rule/package.dhall
1919

2020
let Trigger = ../Trigger/package.dhall
2121

22+
let Inherit = ../Inherit/package.dhall
23+
2224
let mergeOptional = ../utils/mergeOptional.dhall
2325

2426
let mergeOptionalRight = ../utils/mergeOptionalRight.dhall
@@ -60,6 +62,7 @@ let append
6062
mergeOptional Trigger.Type Trigger.append a.trigger b.trigger
6163
, timeout = mergeOptionalRight Text a.timeout b.timeout
6264
, extends = a.extends # b.extends
65+
, inherit = mergeOptionalRight Inherit.Type a.inherit b.inherit
6366
}
6467

6568
in append

GitLab/Job/default.dhall

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ let Environment = ../Environment/Type.dhall
1616

1717
let Trigger = ../Trigger/Type.dhall
1818

19+
let Inherit = ../Inherit/package.dhall
20+
1921
in { stage = None Text
2022
, image = None Image
2123
, variables = Prelude.Map.empty Text Text
@@ -35,5 +37,6 @@ in { stage = None Text
3537
, trigger = None Trigger
3638
, timeout = None Text
3739
, extends = [] : List Text
40+
, inherit = None Inherit.Type
3841
}
3942
: ./Type.dhall

GitLab/Job/toJSON.dhall

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ let Optional/map = Prelude.Optional.map
3232

3333
let Optional/toList = Prelude.Optional.toList
3434

35+
let Inherit = ../Inherit/package.dhall
36+
37+
let Inherit/toJSON = Inherit.toJSON
38+
3539
in let Job/toJSON
3640
: Job JSON.Type
3741
= λ(job : Job)
@@ -155,6 +159,8 @@ in let Job/toJSON
155159
job.extends
156160
)
157161
)
162+
, inherit =
163+
Optional/map Inherit.Type JSON.Type Inherit/toJSON job.inherit
158164
}
159165

160166
in JSON.object (dropNones Text JSON.Type everything)

GitLab/package.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
, Defaults = ./Defaults/package.dhall
1818
, Service = ./Service/package.dhall
1919
, CachePolicy = ./CachePolicy/package.dhall
20+
, Inherit = ./Inherit/package.dhall
2021
}

Prelude.dhall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
-}
2222

2323
env:DHALL_PRELUDE
24-
? https://raw.githubusercontent.com/dhall-lang/dhall-lang/v17.0.0/Prelude/package.dhall sha256:0c04cbe34f1f2d408e8c8b8cb0aa3ff4d5656336910f7e86190a6d14326f966d
24+
? https://raw.githubusercontent.com/dhall-lang/dhall-lang/v17.0.0/Prelude/package.dhall sha256:10db3c919c25e9046833df897a8ffe2701dc390fa0893d958c3430524be5a43e
2525
? https://raw.githubusercontent.com/dhall-lang/dhall-lang/v17.0.0/Prelude/package.dhall

0 commit comments

Comments
 (0)