pipeline.dhall 4.5 KB

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