Skip to content

Commit 12b81f5

Browse files
authored
Merge pull request #93 from scalacenter/multi-build
Find path of build.sbt
2 parents 2bf65d2 + 53f9ef5 commit 12b81f5

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ jobs:
6565
uses: ./
6666
with:
6767
working-directory: sbt-plugin
68+
sbt-plugin-version: 2.2.0-SNAPSHOT
6869

6970

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ inputs:
3333
description: GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner.
3434
required: false
3535
default: ${{ github.token }}
36+
sbt-plugin-version:
37+
description: Version of the sbt plugin to use.
38+
required: false
39+
default: '2.1.0'
3640
runs:
3741
using: 'node16'
3842
main: 'dist/index.js'

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

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

3+
import java.nio.file.Path
4+
import java.nio.file.Paths
5+
36
import scala.collection.mutable
47
import scala.util.Properties
58

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

2730
object autoImport {
2831
val githubSubmitInputKey: AttributeKey[SubmitInput] = AttributeKey("githubSubmitInput")
32+
val githubWorkspace: AttributeKey[Path] = AttributeKey("githubWorkspace")
2933
val githubManifestsKey: AttributeKey[Map[String, githubapi.Manifest]] = AttributeKey("githubDependencyManifests")
3034
val githubProjectsKey: AttributeKey[Seq[ProjectRef]] = AttributeKey("githubProjectRefs")
3135
val githubDependencyManifest: TaskKey[Option[githubapi.Manifest]] = taskKey(
@@ -106,16 +110,20 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
106110
// updateFull is needed to have information about callers and reconstruct dependency tree
107111
val reportResult = Keys.updateFull.result.value
108112
val projectID = Keys.projectID.value
113+
val root = Paths.get(Keys.loadedBuild.value.root).toAbsolutePath
109114
val scalaVersion = (Keys.artifactName / Keys.scalaVersion).value
110115
val scalaBinaryVersion = (Keys.artifactName / Keys.scalaBinaryVersion).value
111116
val crossVersion = CrossVersion.apply(scalaVersion, scalaBinaryVersion)
112117
val allDirectDependencies = Keys.allDependencies.value
113118
val baseDirectory = Keys.baseDirectory.value
114119
val logger = Keys.streams.value.log
115-
val input = Keys.state.value.get(githubSubmitInputKey)
120+
val state = Keys.state.value
116121

117-
val onResolveFailure = input.flatMap(_.onResolveFailure)
118-
val ignoredConfigs = input.toSeq.flatMap(_.ignoredConfigs).toSet
122+
val inputOpt = state.get(githubSubmitInputKey)
123+
val workspaceOpt = state.get(githubWorkspace)
124+
125+
val onResolveFailure = inputOpt.flatMap(_.onResolveFailure)
126+
val ignoredConfigs = inputOpt.toSeq.flatMap(_.ignoredConfigs).toSet
119127
val moduleName = crossVersion(projectID).name
120128

121129
def getReference(module: ModuleID): String =
@@ -183,10 +191,16 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
183191
}
184192

185193
val projectModuleRef = getReference(projectID)
186-
// TODO: find exact build file for this project
187-
val file = githubapi.FileInfo("build.sbt")
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)
188201
val metadata = Map("baseDirectory" -> JString(baseDirectory.toString))
189202
val manifest = githubapi.Manifest(projectModuleRef, file, metadata, resolved.toMap)
203+
logger.info(s"Created manifest of $buildFile")
190204
Some(manifest)
191205
}
192206
}

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

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

33
import java.nio.charset.StandardCharsets
4+
import java.nio.file.Path
5+
import java.nio.file.Paths
46
import java.time.Instant
57

68
import scala.concurrent.Await
79
import scala.concurrent.duration.Duration
810
import scala.util.Properties
911
import scala.util.Try
1012

13+
import ch.epfl.scala.GithubDependencyGraphPlugin.autoImport
1114
import ch.epfl.scala.GithubDependencyGraphPlugin.autoImport._
1215
import ch.epfl.scala.JsonProtocol._
1316
import ch.epfl.scala.githubapi.JsonProtocol._
@@ -58,6 +61,7 @@ object SubmitDependencyGraph {
5861

5962
val initState = state
6063
.put(githubSubmitInputKey, input)
64+
.put(autoImport.githubWorkspace, githubWorkspace())
6165
.put(githubManifestsKey, Map.empty[String, Manifest])
6266
.put(githubProjectsKey, projectRefs)
6367

@@ -137,6 +141,7 @@ object SubmitDependencyGraph {
137141
}
138142

139143
private def checkGithubEnv(): Unit = {
144+
githubWorkspace()
140145
githubWorkflow()
141146
githubJobName()
142147
githubRunId()
@@ -147,6 +152,7 @@ object SubmitDependencyGraph {
147152
githubToken()
148153
}
149154

155+
private def githubWorkspace(): Path = Paths.get(githubCIEnv("GITHUB_WORKSPACE")).toAbsolutePath
150156
private def githubWorkflow(): String = githubCIEnv("GITHUB_WORKFLOW")
151157
private def githubJobName(): String = githubCIEnv("GITHUB_JOB")
152158
private def githubRunId(): String = githubCIEnv("GITHUB_RUN_ID")

src/main.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import * as fs from 'fs'
66
import * as fsPromises from 'fs/promises'
77
import * as path from 'path'
88

9-
// Version of the sbt-github-dependency-submission plugin
10-
const pluginVersion = '2.1.0'
11-
129
async function run(): Promise<void> {
1310
try {
1411
const token = core.getInput('token')
@@ -25,6 +22,7 @@ async function run(): Promise<void> {
2522
const uuid = crypto.randomUUID()
2623
const pluginFile = path.join(projectDir, `github-dependency-submission-${uuid}.sbt`)
2724

25+
const pluginVersion = core.getInput('sbt-plugin-version')
2826
const pluginDep = `addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-submission" % "${pluginVersion}")`
2927
await fsPromises.writeFile(pluginFile, pluginDep)
3028
// check that sbt is installed

0 commit comments

Comments
 (0)