forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGithubEnv.scala
30 lines (24 loc) · 1.16 KB
/
GithubEnv.scala
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
import scala.util.Properties
import sbt.url
import java.net.URL
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/variables#default-environment-variables
object GithubEnv {
lazy val repositoryVar: Option[(String, String)] = envVar("GITHUB_REPOSITORY")
lazy val runIdVar: Option[(String, String)] = envVar("GITHUB_RUN_ID")
lazy val shaVar: Option[(String, String)] = envVar("GITHUB_SHA")
lazy val workflowVar: Option[(String, String)] = envVar("GITHUB_WORKFLOW")
lazy val runUrl: Option[(String, URL)] =
for {
(_, repository) <- repositoryVar
(_, runId) <- runIdVar
} yield "GitHub Run" -> url(s"https://github.com/$repository/actions/runs/$runId")
lazy val treeUrl: Option[(String, URL)] =
for {
(_, repository) <- repositoryVar
(_, sha) <- shaVar
} yield "GitHub Commit" -> url(s"https://github.com/$repository/tree/$sha")
def develocityValues: Seq[(String, String)] = repositoryVar.toSeq ++ shaVar ++ workflowVar
def develocityLinks: Seq[(String, URL)] = runUrl.toSeq ++ treeUrl
private def envVar(key: String): Option[(String, String)] =
Properties.envOrNone(key).map(key -> _)
}