diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dac6780..f5e256a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,5 +65,6 @@ jobs: uses: ./ with: working-directory: sbt-plugin + sbt-plugin-version: 2.2.0-SNAPSHOT diff --git a/action.yml b/action.yml index 6ad0fc5..a19b715 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,10 @@ inputs: description: GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner. required: false default: ${{ github.token }} + sbt-plugin-version: + description: Version of the sbt plugin to use. + required: false + default: '2.1.0' runs: using: 'node16' main: 'dist/index.js' 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 6461520..630281b 100644 --- a/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala +++ b/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala @@ -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 @@ -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( @@ -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 = @@ -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) } } 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 45a6ccb..7c6de60 100644 --- a/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala +++ b/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala @@ -1,6 +1,8 @@ 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 @@ -8,6 +10,7 @@ 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._ @@ -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) @@ -137,6 +141,7 @@ object SubmitDependencyGraph { } private def checkGithubEnv(): Unit = { + githubWorkspace() githubWorkflow() githubJobName() githubRunId() @@ -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") diff --git a/src/main.ts b/src/main.ts index 2475c60..74d8ac4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,9 +6,6 @@ import * as fs from 'fs' import * as fsPromises from 'fs/promises' import * as path from 'path' -// Version of the sbt-github-dependency-submission plugin -const pluginVersion = '2.1.0' - async function run(): Promise { try { const token = core.getInput('token') @@ -25,6 +22,7 @@ async function run(): Promise { const uuid = crypto.randomUUID() const pluginFile = path.join(projectDir, `github-dependency-submission-${uuid}.sbt`) + const pluginVersion = core.getInput('sbt-plugin-version') const pluginDep = `addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-submission" % "${pluginVersion}")` await fsPromises.writeFile(pluginFile, pluginDep) // check that sbt is installed