Skip to content

Commit

Permalink
Fix id of snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Mar 24, 2023
1 parent 405eccd commit 678a250
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.epfl.scala

import java.nio.file.Path
import java.nio.file.Paths

import scala.collection.mutable
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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._
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -144,6 +149,7 @@ object SubmitDependencyGraph {
githubWorkspace()
githubWorkflow()
githubJobName()
githubAction()
githubRunId()
githubSha()
githubRef()
Expand All @@ -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")
Expand Down

0 comments on commit 678a250

Please sign in to comment.