Skip to content

Commit

Permalink
Merge pull request #694 from armanbilge/topic/de-case-classification
Browse files Browse the repository at this point in the history
The great de-case-classification
  • Loading branch information
armanbilge committed Apr 20, 2024
2 parents 4f2e128 + 94cef84 commit 39b474c
Show file tree
Hide file tree
Showing 15 changed files with 360 additions and 103 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ThisBuild / githubWorkflowPublishTimeoutMinutes := Some(45)
ThisBuild / githubWorkflowPublishNeeds += "validate-steward"

ThisBuild / mergifyStewardConfig ~= {
_.map(_.copy(mergeMinors = true, author = "typelevel-steward[bot]"))
_.map(_.withMergeMinors(true).withAuthor("typelevel-steward[bot]"))
}
ThisBuild / mergifySuccessConditions += MergifyCondition.Custom("#approved-reviews-by>=1")
ThisBuild / mergifyLabelPaths += { "docs" -> file("docs") }
Expand Down
4 changes: 2 additions & 2 deletions ci/src/main/scala/org/typelevel/sbt/CrossRootProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ object TypelevelCiJSPlugin extends AutoPlugin with RootProjectId {
},
githubWorkflowBuild := {
githubWorkflowBuild.value.flatMap {
case testStep @ WorkflowStep.Sbt(List("test"), _, _, _, _, _, _, _) =>
case testStep: WorkflowStep.Sbt if testStep.commands == List("test") =>
val fastOptStep = WorkflowStep.Sbt(
List("Test/scalaJSLinkerResult"),
name = Some("scalaJSLink"),
Expand Down Expand Up @@ -226,7 +226,7 @@ object TypelevelCiNativePlugin extends AutoPlugin with RootProjectId {
},
githubWorkflowBuild := {
githubWorkflowBuild.value.flatMap {
case testStep @ WorkflowStep.Sbt(List("test"), _, _, _, _, _, _, _) =>
case testStep: WorkflowStep.Sbt if testStep.commands == List("test") =>
val nativeLinkStep = WorkflowStep.Sbt(
List("Test/nativeLink"),
name = Some("nativeLink"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@

package org.typelevel.sbt.gha

final case class Concurrency(group: String, cancelInProgress: Option[Boolean] = None)
sealed abstract class Concurrency {
def group: String
def cancelInProgress: Option[Boolean]
}

object Concurrency {

def apply(group: String, cancelInProgress: Option[Boolean] = None): Concurrency =
Impl(group, cancelInProgress)

private final case class Impl(group: String, cancelInProgress: Option[Boolean])
extends Concurrency {
override def productPrefix = "Concurrency"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,39 @@

package org.typelevel.sbt.gha

final case class JobContainer(
image: String,
credentials: Option[(String, String)] = None,
env: Map[String, String] = Map(),
volumes: Map[String, String] = Map(),
ports: List[Int] = Nil,
options: List[String] = Nil)
sealed abstract class JobContainer {
def image: String
def credentials: Option[(String, String)]
def env: Map[String, String]
def volumes: Map[String, String]
def ports: List[Int]
def options: List[String]
}

object JobContainer {

def apply(
image: String,
credentials: Option[(String, String)] = None,
env: Map[String, String] = Map(),
volumes: Map[String, String] = Map(),
ports: List[Int] = Nil,
options: List[String] = Nil): JobContainer =
Impl(image, credentials, env, volumes, ports, options)

private[gha] def unapply(jc: JobContainer) = {
import jc._
Some((image, credentials, env, volumes, ports, options))
}

private final case class Impl(
image: String,
credentials: Option[(String, String)],
env: Map[String, String],
volumes: Map[String, String],
ports: List[Int],
options: List[String])
extends JobContainer {
override def productPrefix: String = "JobContainer"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,16 @@ package org.typelevel.sbt.gha

import java.net.URL

final case class JobEnvironment(name: String, url: Option[URL] = None)
sealed abstract class JobEnvironment {
def name: String
def url: Option[URL]
}

object JobEnvironment {
def apply(name: String, url: Option[URL] = None): JobEnvironment =
Impl(name, url)

private final case class Impl(name: String, url: Option[URL]) extends JobEnvironment {
override def productPrefix = "JobEnvironment"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.typelevel.sbt.gha

sealed trait PREventType extends Product with Serializable
sealed abstract class PREventType extends Product with Serializable

object PREventType {
val Defaults = List(Opened, Reopened, Synchronize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.typelevel.sbt.gha

sealed trait Paths extends Product with Serializable
sealed abstract class Paths extends Product with Serializable

object Paths {
final case class Include(paths: List[String]) extends Paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ object Permissions {
case object ReadAll extends Permissions
case object WriteAll extends Permissions
case object None extends Permissions
final case class Specify private (
actions: PermissionValue,
checks: PermissionValue,
contents: PermissionValue,
deployments: PermissionValue,
idToken: PermissionValue,
issues: PermissionValue,
packages: PermissionValue,
pages: PermissionValue,
pullRequests: PermissionValue,
repositoryProjects: PermissionValue,
securityEvents: PermissionValue,
statuses: PermissionValue
) extends Permissions {
sealed abstract class Specify extends Permissions {
def actions: PermissionValue
def checks: PermissionValue
def contents: PermissionValue
def deployments: PermissionValue
def idToken: PermissionValue
def issues: PermissionValue
def packages: PermissionValue
def pages: PermissionValue
def pullRequests: PermissionValue
def repositoryProjects: PermissionValue
def securityEvents: PermissionValue
def statuses: PermissionValue

private[gha] lazy val asMap: SortedMap[PermissionScope, PermissionValue] = SortedMap(
PermissionScope.Actions -> actions,
PermissionScope.Checks -> checks,
Expand All @@ -58,6 +58,34 @@ object Permissions {
)
}
object Specify {
def apply(
actions: PermissionValue,
checks: PermissionValue,
contents: PermissionValue,
deployments: PermissionValue,
idToken: PermissionValue,
issues: PermissionValue,
packages: PermissionValue,
pages: PermissionValue,
pullRequests: PermissionValue,
repositoryProjects: PermissionValue,
securityEvents: PermissionValue,
statuses: PermissionValue
): Specify =
Impl(
actions,
checks,
contents,
deployments,
idToken,
issues,
packages,
pages,
pullRequests,
repositoryProjects,
securityEvents,
statuses)

// See https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
val defaultPermissive = Specify(
actions = PermissionValue.Write,
Expand Down Expand Up @@ -103,6 +131,23 @@ object Permissions {
securityEvents = PermissionValue.Read,
statuses = PermissionValue.Read
)

private final case class Impl(
actions: PermissionValue,
checks: PermissionValue,
contents: PermissionValue,
deployments: PermissionValue,
idToken: PermissionValue,
issues: PermissionValue,
packages: PermissionValue,
pages: PermissionValue,
pullRequests: PermissionValue,
repositoryProjects: PermissionValue,
securityEvents: PermissionValue,
statuses: PermissionValue
) extends Specify {
override def productPrefix = "Specify"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.typelevel.sbt.gha

sealed trait Ref extends Product with Serializable
sealed abstract class Ref extends Product with Serializable

object Ref {
final case class Branch(name: String) extends Ref
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.typelevel.sbt.gha

sealed trait RefPredicate extends Product with Serializable
sealed abstract class RefPredicate extends Product with Serializable

object RefPredicate {
final case class Equals(ref: Ref) extends RefPredicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.typelevel.sbt.gha

sealed trait UseRef extends Product with Serializable
sealed abstract class UseRef extends Product with Serializable

object UseRef {
final case class Public(owner: String, repo: String, ref: String) extends UseRef
Expand Down
114 changes: 93 additions & 21 deletions github-actions/src/main/scala/org/typelevel/sbt/gha/WorkflowJob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,96 @@

package org.typelevel.sbt.gha

final case class WorkflowJob(
id: String,
name: String,
steps: List[WorkflowStep],
sbtStepPreamble: List[String] = List(s"++ $${{ matrix.scala }}"),
cond: Option[String] = None,
permissions: Option[Permissions] = None,
env: Map[String, String] = Map(),
oses: List[String] = List("ubuntu-latest"),
scalas: List[String] = List("2.13"),
javas: List[JavaSpec] = List(JavaSpec.temurin("11")),
needs: List[String] = List(),
matrixFailFast: Option[Boolean] = None,
matrixAdds: Map[String, List[String]] = Map(),
matrixIncs: List[MatrixInclude] = List(),
matrixExcs: List[MatrixExclude] = List(),
runsOnExtraLabels: List[String] = List(),
container: Option[JobContainer] = None,
environment: Option[JobEnvironment] = None,
concurrency: Option[Concurrency] = None,
timeoutMinutes: Option[Int] = None)
sealed abstract class WorkflowJob {
def id: String
def name: String
def steps: List[WorkflowStep]
def sbtStepPreamble: List[String]
def cond: Option[String]
def permissions: Option[Permissions]
def env: Map[String, String]
def oses: List[String]
def scalas: List[String]
def javas: List[JavaSpec]
def needs: List[String]
def matrixFailFast: Option[Boolean]
def matrixAdds: Map[String, List[String]]
def matrixIncs: List[MatrixInclude]
def matrixExcs: List[MatrixExclude]
def runsOnExtraLabels: List[String]
def container: Option[JobContainer]
def environment: Option[JobEnvironment]
def concurrency: Option[Concurrency]
def timeoutMinutes: Option[Int]
}

object WorkflowJob {
def apply(
id: String,
name: String,
steps: List[WorkflowStep],
sbtStepPreamble: List[String] = List(s"++ $${{ matrix.scala }}"),
cond: Option[String] = None,
permissions: Option[Permissions] = None,
env: Map[String, String] = Map(),
oses: List[String] = List("ubuntu-latest"),
scalas: List[String] = List("2.13"),
javas: List[JavaSpec] = List(JavaSpec.temurin("11")),
needs: List[String] = List(),
matrixFailFast: Option[Boolean] = None,
matrixAdds: Map[String, List[String]] = Map(),
matrixIncs: List[MatrixInclude] = List(),
matrixExcs: List[MatrixExclude] = List(),
runsOnExtraLabels: List[String] = List(),
container: Option[JobContainer] = None,
environment: Option[JobEnvironment] = None,
concurrency: Option[Concurrency] = None,
timeoutMinutes: Option[Int] = None): WorkflowJob =
Impl(
id,
name,
steps,
sbtStepPreamble,
cond,
permissions,
env,
oses,
scalas,
javas,
needs,
matrixFailFast,
matrixAdds,
matrixIncs,
matrixExcs,
runsOnExtraLabels,
container,
environment,
concurrency,
timeoutMinutes
)

private final case class Impl(
id: String,
name: String,
steps: List[WorkflowStep],
sbtStepPreamble: List[String],
cond: Option[String],
permissions: Option[Permissions],
env: Map[String, String],
oses: List[String],
scalas: List[String],
javas: List[JavaSpec],
needs: List[String],
matrixFailFast: Option[Boolean],
matrixAdds: Map[String, List[String]],
matrixIncs: List[MatrixInclude],
matrixExcs: List[MatrixExclude],
runsOnExtraLabels: List[String],
container: Option[JobContainer],
environment: Option[JobEnvironment],
concurrency: Option[Concurrency],
timeoutMinutes: Option[Int])
extends WorkflowJob {
override def productPrefix = "WorkflowJob"
}
}
Loading

0 comments on commit 39b474c

Please sign in to comment.