Skip to content

Commit

Permalink
Fix path of build.sbt
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Mar 24, 2023
1 parent 2bf65d2 commit af5bbb7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package ch.epfl.scala

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

import scala.collection.mutable
import scala.util.Properties

Expand All @@ -26,6 +29,7 @@ object GithubDependencyGraphPlugin extends AutoPlugin {

object autoImport {
val githubSubmitInputKey: AttributeKey[SubmitInput] = AttributeKey("githubSubmitInput")
val githubWorkspace: AttributeKey[Path] = AttributeKey("githubWorkspace")
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 @@ -106,16 +110,20 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
// updateFull is needed to have information about callers and reconstruct dependency tree
val reportResult = Keys.updateFull.result.value
val projectID = Keys.projectID.value
val root = Paths.get(Keys.loadedBuild.value.root).toAbsolutePath
val scalaVersion = (Keys.artifactName / Keys.scalaVersion).value
val scalaBinaryVersion = (Keys.artifactName / Keys.scalaBinaryVersion).value
val crossVersion = CrossVersion.apply(scalaVersion, scalaBinaryVersion)
val allDirectDependencies = Keys.allDependencies.value
val baseDirectory = Keys.baseDirectory.value
val logger = Keys.streams.value.log
val input = Keys.state.value.get(githubSubmitInputKey)
val state = Keys.state.value

val onResolveFailure = input.flatMap(_.onResolveFailure)
val ignoredConfigs = input.toSeq.flatMap(_.ignoredConfigs).toSet
val inputOpt = state.get(githubSubmitInputKey)
val workspaceOpt = state.get(githubWorkspace)

val onResolveFailure = inputOpt.flatMap(_.onResolveFailure)
val ignoredConfigs = inputOpt.toSeq.flatMap(_.ignoredConfigs).toSet
val moduleName = crossVersion(projectID).name

def getReference(module: ModuleID): String =
Expand Down Expand Up @@ -183,10 +191,16 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
}

val projectModuleRef = getReference(projectID)
// TODO: find exact build file for this project
val file = githubapi.FileInfo("build.sbt")
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")
Some(manifest)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package ch.epfl.scala

import java.nio.charset.StandardCharsets
import java.nio.file.Path
import java.nio.file.Paths
import java.time.Instant

import scala.concurrent.Await
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 @@ -58,6 +61,7 @@ object SubmitDependencyGraph {

val initState = state
.put(githubSubmitInputKey, input)
.put(autoImport.githubWorkspace, githubWorkspace())
.put(githubManifestsKey, Map.empty[String, Manifest])
.put(githubProjectsKey, projectRefs)

Expand Down Expand Up @@ -137,6 +141,7 @@ object SubmitDependencyGraph {
}

private def checkGithubEnv(): Unit = {
githubWorkspace()
githubWorkflow()
githubJobName()
githubRunId()
Expand All @@ -147,6 +152,7 @@ object SubmitDependencyGraph {
githubToken()
}

private def githubWorkspace(): Path = Paths.get(githubCIEnv("GITHUB_WORKSPACE")).toAbsolutePath
private def githubWorkflow(): String = githubCIEnv("GITHUB_WORKFLOW")
private def githubJobName(): String = githubCIEnv("GITHUB_JOB")
private def githubRunId(): String = githubCIEnv("GITHUB_RUN_ID")
Expand Down

0 comments on commit af5bbb7

Please sign in to comment.