Skip to content

Commit 64bc77d

Browse files
committed
Bin friendlier Triggers, added Workflow Call
1 parent 350ab43 commit 64bc77d

File tree

3 files changed

+204
-33
lines changed

3 files changed

+204
-33
lines changed

github-actions/src/main/scala/org/typelevel/sbt/gha/GenerativeKeys.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ trait GenerativeKeys {
2727

2828
lazy val githubWorkflows = settingKey[Map[String, Workflow]](
2929
"The map of jobs which will make up the generated workflows, with the keys being the workflow file path.")
30+
lazy val githubWorkflowCI =
31+
settingKey[Workflow]("The Workflow which will make up the generated ci workflow (ci.yml)")
3032
lazy val githubWorkflowGeneratedCI = settingKey[Seq[WorkflowJob]](
3133
"The sequence of jobs which will make up the generated ci workflow (ci.yml)")
3234
lazy val githubWorkflowGeneratedUploadSteps = settingKey[Seq[WorkflowStep]](

github-actions/src/main/scala/org/typelevel/sbt/gha/GenerativePlugin.scala

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ object GenerativePlugin extends AutoPlugin {
152152
indent("push", 1)
153153
else
154154
indent("push:\n" + indent(renderedBranches + renderedTags + renderedPaths, 1), 1)
155+
case _: WorkflowTrigger.WorkflowCall => indent("workflow_call", 1)
156+
case raw: WorkflowTrigger.Raw => indent(raw.toYaml, 1)
155157
}
156158
.mkString("\n", "\n", "")
157159

@@ -944,21 +946,20 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
944946
timeoutMinutes = githubWorkflowPublishTimeoutMinutes.value
945947
)
946948
},
947-
githubWorkflows := Map(
948-
"ci" -> toWorkflow(
949-
name = "Continuous Integration",
950-
branches = githubWorkflowTargetBranches.value.toList,
951-
tags = githubWorkflowTargetTags.value.toList,
952-
paths = githubWorkflowTargetPaths.value,
953-
prEventTypes = githubWorkflowPREventTypes.value.toList,
954-
permissions = githubWorkflowPermissions.value,
955-
env = githubWorkflowEnv.value,
956-
concurrency = githubWorkflowConcurrency.value,
957-
jobs = githubWorkflowGeneratedCI.value.toList
958-
)
959-
) ++ (if (githubWorkflowIncludeClean.value)
960-
Map("clean" -> cleanFlow)
961-
else Map.empty),
949+
githubWorkflowCI := toWorkflow(
950+
name = "Continuous Integration",
951+
branches = githubWorkflowTargetBranches.value.toList,
952+
tags = githubWorkflowTargetTags.value.toList,
953+
paths = githubWorkflowTargetPaths.value,
954+
prEventTypes = githubWorkflowPREventTypes.value.toList,
955+
permissions = githubWorkflowPermissions.value,
956+
env = githubWorkflowEnv.value,
957+
concurrency = githubWorkflowConcurrency.value,
958+
jobs = githubWorkflowGeneratedCI.value.toList
959+
),
960+
githubWorkflows := Map("ci" -> githubWorkflowCI.value) ++
961+
(if (githubWorkflowIncludeClean.value) Map("clean" -> cleanFlow)
962+
else Map.empty),
962963
githubWorkflowGeneratedCI := {
963964
val publishJobOpt: Seq[WorkflowJob] =
964965
Seq(githubWorkflowPublishJob.value).filter(_ =>

github-actions/src/main/scala/org/typelevel/sbt/gha/WorkflowTrigger.scala

Lines changed: 186 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,190 @@ package org.typelevel.sbt.gha
1818

1919
sealed trait WorkflowTrigger
2020
object WorkflowTrigger {
21-
// TODO: make bin compat friendly
22-
// TODO: Make branches and tags work like Paths
23-
case class PullRequest(
24-
branches: List[String] = List.empty,
25-
paths: Paths = Paths.None,
26-
branchesIgnore: List[String] = List.empty,
27-
tags: List[String] = List.empty,
28-
tagsIgnore: List[String] = List.empty,
29-
types: List[PREventType] = List.empty
30-
) extends WorkflowTrigger
31-
32-
case class Push(
33-
branches: List[String] = List.empty,
34-
branchesIgnore: List[String] = List.empty,
35-
paths: Paths = Paths.None,
36-
tags: List[String] = List.empty,
37-
tagsIgnore: List[String] = List.empty
38-
) extends WorkflowTrigger
21+
sealed trait PullRequest extends WorkflowTrigger {
22+
def branches: List[String]
23+
def paths: Paths
24+
def branchesIgnore: List[String]
25+
def tags: List[String]
26+
def tagsIgnore: List[String]
27+
def types: List[PREventType]
28+
29+
def withBranches(branches: List[String]): PullRequest
30+
def withPaths(paths: Paths): PullRequest
31+
def withBranchesIgnore(branchesIgnore: List[String]): PullRequest
32+
def withTags(tags: List[String]): PullRequest
33+
def withTagsIgnore(tagsIgnore: List[String]): PullRequest
34+
def withTypes(types: List[PREventType]): PullRequest
35+
}
36+
object PullRequest {
37+
def apply(
38+
branches: List[String] = List.empty,
39+
paths: Paths = Paths.None,
40+
branchesIgnore: List[String] = List.empty,
41+
tags: List[String] = List.empty,
42+
tagsIgnore: List[String] = List.empty,
43+
types: List[PREventType] = List.empty
44+
): PullRequest = Impl(
45+
branches = branches,
46+
paths = paths,
47+
branchesIgnore = branchesIgnore,
48+
tags = tags,
49+
tagsIgnore = tagsIgnore,
50+
types = types
51+
)
52+
53+
private final case class Impl(
54+
branches: List[String],
55+
paths: Paths,
56+
branchesIgnore: List[String],
57+
tags: List[String],
58+
tagsIgnore: List[String],
59+
types: List[PREventType]
60+
) extends PullRequest {
61+
override def productPrefix = "PullRequest"
62+
63+
// scalafmt: { maxColumn = 200 }
64+
def withBranches(branches: List[String]): PullRequest = copy(branches = branches)
65+
def withPaths(paths: Paths): PullRequest = copy(paths = paths)
66+
def withBranchesIgnore(branchesIgnore: List[String]): PullRequest = copy(branchesIgnore = branchesIgnore)
67+
def withTags(tags: List[String]): PullRequest = copy(tags = tags)
68+
def withTagsIgnore(tagsIgnore: List[String]): PullRequest = copy(tagsIgnore = tagsIgnore)
69+
def withTypes(types: List[PREventType]): PullRequest = copy(types = types)
70+
// scalafmt: { maxColumn = 96 }
71+
}
72+
}
73+
74+
sealed trait Push extends WorkflowTrigger {
75+
def branches: List[String]
76+
def branchesIgnore: List[String]
77+
def paths: Paths
78+
def tags: List[String]
79+
def tagsIgnore: List[String]
80+
81+
def withBranches(branches: List[String]): Push
82+
def withBranchesIgnore(branchesIgnore: List[String]): Push
83+
def withPaths(paths: Paths): Push
84+
def withTags(tags: List[String]): Push
85+
def withTagsIgnore(tagsIgnore: List[String]): Push
86+
}
87+
object Push {
88+
def apply(
89+
branches: List[String] = List.empty,
90+
branchesIgnore: List[String] = List.empty,
91+
paths: Paths = Paths.None,
92+
tags: List[String] = List.empty,
93+
tagsIgnore: List[String] = List.empty
94+
): Push = Impl(
95+
branches = branches,
96+
branchesIgnore = branchesIgnore,
97+
paths = paths,
98+
tags = tags,
99+
tagsIgnore = tagsIgnore
100+
)
101+
102+
private final case class Impl(
103+
branches: List[String],
104+
branchesIgnore: List[String],
105+
paths: Paths,
106+
tags: List[String],
107+
tagsIgnore: List[String]
108+
) extends Push {
109+
override def productPrefix = "Push"
110+
111+
// scalafmt: { maxColumn = 200 }
112+
def withBranches(branches: List[String]): Push = copy(branches = branches)
113+
def withBranchesIgnore(branchesIgnore: List[String]): Push = copy(branchesIgnore = branchesIgnore)
114+
def withPaths(paths: Paths): Push = copy(paths = paths)
115+
def withTags(tags: List[String]): Push = copy(tags = tags)
116+
def withTagsIgnore(tagsIgnore: List[String]): Push = copy(tagsIgnore = tagsIgnore)
117+
// scalafmt: { maxColumn = 96 }
118+
}
119+
}
120+
121+
sealed trait WorkflowCall extends WorkflowTrigger
122+
object WorkflowCall {
123+
def apply(): WorkflowCall = Impl
124+
private final case object Impl extends WorkflowCall {
125+
override def productPrefix = "WorkflowCall"
126+
}
127+
}
128+
129+
/**
130+
* A workflow trigger, inserted directly into the yaml, with 1 level of indention. This is an
131+
* escape hatch for people wanting triggers other than the supported ones.
132+
*/
133+
sealed trait Raw extends WorkflowTrigger {
134+
def toYaml: String
135+
}
136+
object Raw {
137+
def raw(yaml: String): Raw = Impl(yaml)
138+
139+
private final case class Impl(toYaml: String) extends Raw
140+
}
141+
142+
/*
143+
* Other Triggers not implemented here:
144+
*
145+
* branch_protection_rule
146+
* check_run
147+
* check_suite
148+
* create
149+
* delete
150+
* deployment
151+
* deployment_status
152+
* discussion
153+
* discussion_comment
154+
* fork
155+
* gollum
156+
* issue_comment
157+
* issues
158+
* label
159+
* merge_group
160+
* milestone
161+
* page_build
162+
* public
163+
* pull_request_comment (use issue_comment)
164+
* pull_request_review
165+
* pull_request_review_comment
166+
* pull_request_target
167+
* registry_package
168+
* release
169+
* repository_dispatch
170+
* schedule
171+
* status
172+
* watch
173+
* workflow_disbranch_protection_rule
174+
* check_run
175+
* check_suite
176+
* create
177+
* delete
178+
* deployment
179+
* deployment_status
180+
* discussion
181+
* discussion_comment
182+
* fork
183+
* gollum
184+
* issue_comment
185+
* issues
186+
* label
187+
* merge_group
188+
* milestone
189+
* page_build
190+
* public
191+
* pull_request
192+
* pull_request_comment (use issue_comment)
193+
* pull_request_review
194+
* pull_request_review_comment
195+
* pull_request_target
196+
* push
197+
* registry_package
198+
* release
199+
* repository_dispatch
200+
* schedule
201+
* status
202+
* watch
203+
* workflow_dispatch
204+
* workflow_runpatch
205+
* workflow_run
206+
*/
39207
}

0 commit comments

Comments
 (0)