Skip to content

Commit fab4ada

Browse files
authored
Merge pull request #96 from scalacenter/multi-build
Fix correlator of snapshot
2 parents 405eccd + 678a250 commit fab4ada

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ch.epfl.scala
22

3-
import java.nio.file.Path
43
import java.nio.file.Paths
54

65
import scala.collection.mutable
@@ -29,7 +28,7 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
2928

3029
object autoImport {
3130
val githubSubmitInputKey: AttributeKey[SubmitInput] = AttributeKey("githubSubmitInput")
32-
val githubWorkspace: AttributeKey[Path] = AttributeKey("githubWorkspace")
31+
val githubBuildFile: AttributeKey[githubapi.FileInfo] = AttributeKey("githubBuildFile")
3332
val githubManifestsKey: AttributeKey[Map[String, githubapi.Manifest]] = AttributeKey("githubDependencyManifests")
3433
val githubProjectsKey: AttributeKey[Seq[ProjectRef]] = AttributeKey("githubProjectRefs")
3534
val githubDependencyManifest: TaskKey[Option[githubapi.Manifest]] = taskKey(
@@ -120,7 +119,7 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
120119
val state = Keys.state.value
121120

122121
val inputOpt = state.get(githubSubmitInputKey)
123-
val workspaceOpt = state.get(githubWorkspace)
122+
val buildFileOpt = state.get(githubBuildFile)
124123

125124
val onResolveFailure = inputOpt.flatMap(_.onResolveFailure)
126125
val ignoredConfigs = inputOpt.toSeq.flatMap(_.ignoredConfigs).toSet
@@ -191,16 +190,8 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
191190
}
192191

193192
val projectModuleRef = getReference(projectID)
194-
val buildFile = workspaceOpt match {
195-
case None => "build.sbt"
196-
case Some(workspace) =>
197-
if (root.startsWith(workspace)) workspace.relativize(root).resolve("build.sbt").toString
198-
else root.resolve("build.sbt").toString
199-
}
200-
val file = githubapi.FileInfo(buildFile)
201193
val metadata = Map("baseDirectory" -> JString(baseDirectory.toString))
202-
val manifest = githubapi.Manifest(projectModuleRef, file, metadata, resolved.toMap)
203-
logger.info(s"Created manifest of $buildFile")
194+
val manifest = githubapi.Manifest(projectModuleRef, buildFileOpt, metadata, resolved.toMap)
204195
Some(manifest)
205196
}
206197
}

sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ch.epfl.scala
22

33
import java.nio.charset.StandardCharsets
4-
import java.nio.file.Path
54
import java.nio.file.Paths
65
import java.time.Instant
76

@@ -10,7 +9,6 @@ import scala.concurrent.duration.Duration
109
import scala.util.Properties
1110
import scala.util.Try
1211

13-
import ch.epfl.scala.GithubDependencyGraphPlugin.autoImport
1412
import ch.epfl.scala.GithubDependencyGraphPlugin.autoImport._
1513
import ch.epfl.scala.JsonProtocol._
1614
import ch.epfl.scala.githubapi.JsonProtocol._
@@ -59,9 +57,16 @@ object SubmitDependencyGraph {
5957
.flatMap(projectRef => state.setting(projectRef / Keys.crossScalaVersions))
6058
.distinct
6159

60+
val root = Paths.get(loadedBuild.root).toAbsolutePath
61+
val workspace = Paths.get(githubWorkspace()).toAbsolutePath
62+
val buildFile =
63+
if (root.startsWith(workspace)) workspace.relativize(root).resolve("build.sbt")
64+
else root.resolve("build.sbt")
65+
state.log.info(s"Resolving snapshot of $buildFile")
66+
6267
val initState = state
6368
.put(githubSubmitInputKey, input)
64-
.put(autoImport.githubWorkspace, githubWorkspace())
69+
.put(githubBuildFile, githubapi.FileInfo(buildFile.toString))
6570
.put(githubManifestsKey, Map.empty[String, Manifest])
6671
.put(githubProjectsKey, projectRefs)
6772

@@ -85,7 +90,7 @@ object SubmitDependencyGraph {
8590
"Authorization" -> s"token ${githubToken()}"
8691
)
8792

88-
state.log.info(s"Submiting dependency snapshot to $snapshotUrl")
93+
state.log.info(s"Submiting dependency snapshot of job ${snapshot.job} to $snapshotUrl")
8994
val result = for {
9095
httpResp <- Try(Await.result(http.processFull(request), Duration.Inf))
9196
snapshot <- getSnapshot(httpResp)
@@ -130,11 +135,11 @@ object SubmitDependencyGraph {
130135
}
131136

132137
private def githubJob(): Job = {
133-
val correlator = s"${githubJobName()}_${githubWorkflow()}"
138+
val correlator = s"${githubWorkflow()}_${githubJobName()}_${githubAction()}"
134139
val id = githubRunId
135140
val html_url =
136141
for {
137-
serverUrl <- Properties.envOrNone("$GITHUB_SERVER_URL")
142+
serverUrl <- Properties.envOrNone("GITHUB_SERVER_URL")
138143
repository <- Properties.envOrNone("GITHUB_REPOSITORY")
139144
} yield s"$serverUrl/$repository/actions/runs/$id"
140145
Job(correlator, id, html_url)
@@ -144,6 +149,7 @@ object SubmitDependencyGraph {
144149
githubWorkspace()
145150
githubWorkflow()
146151
githubJobName()
152+
githubAction()
147153
githubRunId()
148154
githubSha()
149155
githubRef()
@@ -152,9 +158,10 @@ object SubmitDependencyGraph {
152158
githubToken()
153159
}
154160

155-
private def githubWorkspace(): Path = Paths.get(githubCIEnv("GITHUB_WORKSPACE")).toAbsolutePath
161+
private def githubWorkspace(): String = githubCIEnv("GITHUB_WORKSPACE")
156162
private def githubWorkflow(): String = githubCIEnv("GITHUB_WORKFLOW")
157163
private def githubJobName(): String = githubCIEnv("GITHUB_JOB")
164+
private def githubAction(): String = githubCIEnv("GITHUB_ACTION")
158165
private def githubRunId(): String = githubCIEnv("GITHUB_RUN_ID")
159166
private def githubSha(): String = githubCIEnv("GITHUB_SHA")
160167
private def githubRef(): String = githubCIEnv("GITHUB_REF")

0 commit comments

Comments
 (0)