-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathWorkflowStep.scala
More file actions
114 lines (99 loc) · 4.78 KB
/
Copy pathWorkflowStep.scala
File metadata and controls
114 lines (99 loc) · 4.78 KB
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
/*
* Copyright 2020-2021 Daniel Spiewak
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sbtghactions
import scala.collection.immutable.ListMap
import scala.concurrent.duration.FiniteDuration
sealed trait WorkflowStep extends Product with Serializable {
def id: Option[String]
def name: Option[String]
def cond: Option[String]
def env: Map[String, String]
def timeout: Option[FiniteDuration]
}
object Action {
val checkout = UseRef.Public("actions", "checkout", "v6")
val setupGraalvm = UseRef.Public("graalvm", "setup-graalvm", "v1")
val setupJava = UseRef.Public("actions", "setup-java", "v5")
val setupSbt = UseRef.Public("sbt", "setup-sbt", "v1")
val tmate = UseRef.Public("mxschmitt", "action-tmate", "v2")
val upload = UseRef.Public("actions", "upload-artifact", "v5")
val download = UseRef.Public("actions", "download-artifact", "v6")
val configurePagefile = UseRef.Public("al-cheb", "configure-pagefile-action", "v1.5")
}
object WorkflowStep {
val DefaultSbtStepPreamble: List[String] = List(s"++ $${{ matrix.scala }}")
val CheckoutFull: WorkflowStep = Use(
Action.checkout,
name = Some("Checkout current branch (full)"),
params = Map("fetch-depth" -> "0"))
val Checkout: WorkflowStep = Use(Action.checkout, name = Some("Checkout current branch (fast)"))
def SetupJava(versions: List[JavaSpec]): List[WorkflowStep] =
versions map {
case jv @ JavaSpec(JavaSpec.Distribution.GraalVM(Graalvm.Version(graalVersion)), version) =>
WorkflowStep.Use(
Action.setupGraalvm,
name = Some(s"Setup GraalVM (${jv.render})"),
cond = Some(s"matrix.java == '${jv.render}'"),
params = ListMap(
"version" -> graalVersion,
"java-version" -> s"$version",
"components" -> "native-image",
"github-token" -> s"$${{ secrets.GITHUB_TOKEN }}",
"cache" -> "sbt"))
case jv @ JavaSpec(JavaSpec.Distribution.GraalVM(Graalvm.Distribution(distribution)), version) =>
// Note: native-image is included by default in GraalVM for JDK 17+
// See: https://github.com/oracle/graal/pull/5995
WorkflowStep.Use(
Action.setupGraalvm,
name = Some(s"Setup GraalVM (${jv.render})"),
cond = Some(s"matrix.java == '${jv.render}'"),
params = ListMap(
"java-version" -> s"$version",
"distribution" -> distribution,
"github-token" -> s"$${{ secrets.GITHUB_TOKEN }}",
"cache" -> "sbt"))
case jv @ JavaSpec(dist, version) =>
WorkflowStep.Use(
Action.setupJava,
name = Some(s"Setup Java (${jv.render})"),
cond = Some(s"matrix.java == '${jv.render}'"),
params = ListMap(
"distribution" -> dist.rendering,
"java-version" -> version,
"cache" -> "sbt"))
}
def SetupSbt(runnerVersion: Option[String] = None): WorkflowStep =
Use(
ref = Action.setupSbt,
params = runnerVersion match {
case Some(v) => Map("sbt-runner-version" -> v)
case None => Map()
},
name = Some("Setup sbt"),
)
val Tmate: WorkflowStep = Use(Action.tmate, name = Some("Setup tmate session"))
def ComputeVar(name: String, cmd: String): WorkflowStep =
Run(
List("echo \"" + name + "=$(" + cmd + ")\" >> $GITHUB_ENV"),
name = Some(s"Export $name"))
def ComputePrependPATH(cmd: String): WorkflowStep =
Run(
List("echo \"$(" + cmd + ")\" >> $GITHUB_PATH"),
name = Some(s"Prepend $$PATH using $cmd"))
final case class Run(commands: List[String], id: Option[String] = None, name: Option[String] = None, cond: Option[String] = None, env: Map[String, String] = Map(), params: Map[String, String] = Map(), timeout: Option[FiniteDuration] = None) extends WorkflowStep
final case class Sbt(commands: List[String], id: Option[String] = None, name: Option[String] = None, cond: Option[String] = None, env: Map[String, String] = Map(), params: Map[String, String] = Map(), timeout: Option[FiniteDuration] = None) extends WorkflowStep
final case class Use(ref: UseRef, params: Map[String, String] = Map(), id: Option[String] = None, name: Option[String] = None, cond: Option[String] = None, env: Map[String, String] = Map(), timeout: Option[FiniteDuration] = None) extends WorkflowStep
}