From 678a2504f33543e3ddcd0dc9438e9eec4a10984e Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Fri, 24 Mar 2023 14:25:05 +0100 Subject: [PATCH] Fix id of snapshot --- .../scala/GithubDependencyGraphPlugin.scala | 15 +++---------- .../ch/epfl/scala/SubmitDependencyGraph.scala | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala b/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala index 630281b..a68648f 100644 --- a/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala +++ b/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala @@ -1,6 +1,5 @@ package ch.epfl.scala -import java.nio.file.Path import java.nio.file.Paths import scala.collection.mutable @@ -29,7 +28,7 @@ object GithubDependencyGraphPlugin extends AutoPlugin { object autoImport { val githubSubmitInputKey: AttributeKey[SubmitInput] = AttributeKey("githubSubmitInput") - val githubWorkspace: AttributeKey[Path] = AttributeKey("githubWorkspace") + val githubBuildFile: AttributeKey[githubapi.FileInfo] = AttributeKey("githubBuildFile") val githubManifestsKey: AttributeKey[Map[String, githubapi.Manifest]] = AttributeKey("githubDependencyManifests") val githubProjectsKey: AttributeKey[Seq[ProjectRef]] = AttributeKey("githubProjectRefs") val githubDependencyManifest: TaskKey[Option[githubapi.Manifest]] = taskKey( @@ -120,7 +119,7 @@ object GithubDependencyGraphPlugin extends AutoPlugin { val state = Keys.state.value val inputOpt = state.get(githubSubmitInputKey) - val workspaceOpt = state.get(githubWorkspace) + val buildFileOpt = state.get(githubBuildFile) val onResolveFailure = inputOpt.flatMap(_.onResolveFailure) val ignoredConfigs = inputOpt.toSeq.flatMap(_.ignoredConfigs).toSet @@ -191,16 +190,8 @@ object GithubDependencyGraphPlugin extends AutoPlugin { } val projectModuleRef = getReference(projectID) - val buildFile = workspaceOpt match { - case None => "build.sbt" - case Some(workspace) => - if (root.startsWith(workspace)) workspace.relativize(root).resolve("build.sbt").toString - else root.resolve("build.sbt").toString - } - val file = githubapi.FileInfo(buildFile) val metadata = Map("baseDirectory" -> JString(baseDirectory.toString)) - val manifest = githubapi.Manifest(projectModuleRef, file, metadata, resolved.toMap) - logger.info(s"Created manifest of $buildFile") + val manifest = githubapi.Manifest(projectModuleRef, buildFileOpt, metadata, resolved.toMap) Some(manifest) } } diff --git a/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala b/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala index 7c6de60..8c38d1d 100644 --- a/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala +++ b/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala @@ -1,7 +1,6 @@ package ch.epfl.scala import java.nio.charset.StandardCharsets -import java.nio.file.Path import java.nio.file.Paths import java.time.Instant @@ -10,7 +9,6 @@ import scala.concurrent.duration.Duration import scala.util.Properties import scala.util.Try -import ch.epfl.scala.GithubDependencyGraphPlugin.autoImport import ch.epfl.scala.GithubDependencyGraphPlugin.autoImport._ import ch.epfl.scala.JsonProtocol._ import ch.epfl.scala.githubapi.JsonProtocol._ @@ -59,9 +57,16 @@ object SubmitDependencyGraph { .flatMap(projectRef => state.setting(projectRef / Keys.crossScalaVersions)) .distinct + val root = Paths.get(loadedBuild.root).toAbsolutePath + val workspace = Paths.get(githubWorkspace()).toAbsolutePath + val buildFile = + if (root.startsWith(workspace)) workspace.relativize(root).resolve("build.sbt") + else root.resolve("build.sbt") + state.log.info(s"Resolving snapshot of $buildFile") + val initState = state .put(githubSubmitInputKey, input) - .put(autoImport.githubWorkspace, githubWorkspace()) + .put(githubBuildFile, githubapi.FileInfo(buildFile.toString)) .put(githubManifestsKey, Map.empty[String, Manifest]) .put(githubProjectsKey, projectRefs) @@ -85,7 +90,7 @@ object SubmitDependencyGraph { "Authorization" -> s"token ${githubToken()}" ) - state.log.info(s"Submiting dependency snapshot to $snapshotUrl") + state.log.info(s"Submiting dependency snapshot of job ${snapshot.job} to $snapshotUrl") val result = for { httpResp <- Try(Await.result(http.processFull(request), Duration.Inf)) snapshot <- getSnapshot(httpResp) @@ -130,11 +135,11 @@ object SubmitDependencyGraph { } private def githubJob(): Job = { - val correlator = s"${githubJobName()}_${githubWorkflow()}" + val correlator = s"${githubWorkflow()}_${githubJobName()}_${githubAction()}" val id = githubRunId val html_url = for { - serverUrl <- Properties.envOrNone("$GITHUB_SERVER_URL") + serverUrl <- Properties.envOrNone("GITHUB_SERVER_URL") repository <- Properties.envOrNone("GITHUB_REPOSITORY") } yield s"$serverUrl/$repository/actions/runs/$id" Job(correlator, id, html_url) @@ -144,6 +149,7 @@ object SubmitDependencyGraph { githubWorkspace() githubWorkflow() githubJobName() + githubAction() githubRunId() githubSha() githubRef() @@ -152,9 +158,10 @@ object SubmitDependencyGraph { githubToken() } - private def githubWorkspace(): Path = Paths.get(githubCIEnv("GITHUB_WORKSPACE")).toAbsolutePath + private def githubWorkspace(): String = githubCIEnv("GITHUB_WORKSPACE") private def githubWorkflow(): String = githubCIEnv("GITHUB_WORKFLOW") private def githubJobName(): String = githubCIEnv("GITHUB_JOB") + private def githubAction(): String = githubCIEnv("GITHUB_ACTION") private def githubRunId(): String = githubCIEnv("GITHUB_RUN_ID") private def githubSha(): String = githubCIEnv("GITHUB_SHA") private def githubRef(): String = githubCIEnv("GITHUB_REF")