Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find path of build.sbt #93

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ jobs:
uses: ./
with:
working-directory: sbt-plugin
sbt-plugin-version: 2.2.0-SNAPSHOT


4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
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
4 changes: 1 addition & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
try {
const token = core.getInput('token')
Expand All @@ -25,6 +22,7 @@ async function run(): Promise<void> {
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
Expand Down