-
Notifications
You must be signed in to change notification settings - Fork 2
/
pipeline.dhall
153 lines (141 loc) · 4.51 KB
/
pipeline.dhall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
let Concourse = ../package.dhall
let Prelude = ../lib/prelude.dhall
let mainBranch =
Concourse.schemas.Resource::{
, name = "main"
, type = Concourse.Types.ResourceType.InBuilt "git"
, icon = Some "git"
, source = Some
( toMap
{ uri =
Prelude.JSON.string
"https://github.com/akshaymankar/dhall-concourse"
}
)
}
let testTask =
λ(repo : Concourse.Types.Resource) →
Concourse.helpers.taskStep
Concourse.schemas.TaskStep::{
, task = "test"
, config =
Concourse.Types.TaskSpec.Config
Concourse.schemas.TaskConfig::{
, image_resource = Some Concourse.schemas.ImageResource::{
, type = "registry-image"
, source = Some
( toMap
{ repository = Prelude.JSON.string "nixos/nix"
, tag = Prelude.JSON.string "latest"
}
)
}
, inputs = Some
[ Concourse.schemas.TaskInput::{ name = repo.name } ]
, run = Concourse.schemas.TaskRunConfig::{
, path = "sh"
, args = Some
[ "-c"
, ./test.sh as Text
, let dollarZero = "test.sh" in dollarZero
, repo.name
]
}
}
}
let mainBranchJob =
Concourse.schemas.Job::{
, name = "main"
, plan =
[ Concourse.helpers.getStep
Concourse.schemas.GetStep::{
, resource = mainBranch
, trigger = Some True
}
, testTask mainBranch
]
}
let prResource =
Concourse.schemas.CustomResourceType::{
, name = "github-pr"
, type = "registry-image"
, source = Some
( toMap
{ repository = Prelude.JSON.string "teliaoss/github-pr-resource" }
)
}
let pr =
Concourse.schemas.Resource::{
, name = "pr"
, type = Concourse.Types.ResourceType.Custom prResource
, icon = Some "source-pull"
, source = Some
( toMap
{ repository = Prelude.JSON.string "akshaymankar/dhall-concourse"
, access_token = Prelude.JSON.string "((github-access-token))"
, labels = Prelude.JSON.array [ Prelude.JSON.string "ok-to-test" ]
}
)
}
let checkContext = "tests"
let markCheckPending =
Concourse.helpers.putStep
Concourse.schemas.PutStep::{
, put = Some "mark-pending"
, resource = pr
, inputs = Some [ pr.name ]
, params = Some
( toMap
{ path = Prelude.JSON.string pr.name
, status = Prelude.JSON.string "PENDING"
, context = Prelude.JSON.string checkContext
, description =
Prelude.JSON.string "waiting for tests to finish"
}
)
}
let markCheckSuccess =
Concourse.helpers.putStep
Concourse.schemas.PutStep::{
, put = Some "mark-success"
, resource = pr
, inputs = Some [ pr.name ]
, params = Some
( toMap
{ path = Prelude.JSON.string pr.name
, status = Prelude.JSON.string "SUCCESS"
, context = Prelude.JSON.string checkContext
}
)
}
let markCheckFailure =
Concourse.helpers.putStep
Concourse.schemas.PutStep::{
, put = Some "mark-failure"
, resource = pr
, inputs = Some [ pr.name ]
, params = Some
( toMap
{ path = Prelude.JSON.string pr.name
, status = Prelude.JSON.string "FAILURE"
, context = Prelude.JSON.string checkContext
}
)
}
let prJob =
Concourse.schemas.Job::{
, name = "pull-requests"
, public = Some True
, plan =
[ Concourse.helpers.getStep
Concourse.schemas.GetStep::{ resource = pr, trigger = Some True }
, markCheckPending
, Concourse.helpers.addHooks
(testTask pr)
Concourse.schemas.StepHooks::{
, on_success = Some markCheckSuccess
, on_failure = Some markCheckFailure
}
]
}
in Concourse.render.pipeline [ mainBranchJob, prJob ]