diff --git a/README.md b/README.md index ce522746..2d926948 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,19 @@ Typically you would specify the correlator in a matrix-based job like this: correlator: ${{ github.job }}-${{ matrix.directory }} ``` +#### - `sha-override` (optional) + +Overrides the `sha` attribute in the generated JSON file before submission. + +#### - `ref-override` (optional) + +Overrides the `ref` attribute in the generated JSON file before submission. + +#### - `manifest-override` (optional) + +Overrides the `source_location` attribute of each `file` object in the manifest entries of the JSON file before submission. +This does not affect which `build.sbt` file is actually processed - that can be controlled by the `working-directory` input. + #### - `token` (optional) GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner. diff --git a/action.yml b/action.yml index d5e20aa2..9337efc6 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,20 @@ inputs: If 'warning', the job will ignore the failing modules and submit the snapshot. required: false default: error + sha-override: + description: "Overrides the `sha` attribute in the generated JSON file before submission." + required: false + default: '' + ref-override: + description: "Overrides the `ref` attribute in the generated JSON file before submission." + required: false + default: '' + manifest-override: + description: | + Overrides the `source_location` attribute of each `file` object in the manifest entries of the JSON file before submission. + This does not affect which `build.sbt` file is actually processed - that can be controlled by the `working-directory` input. + required: false + default: '' token: description: GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner. required: false diff --git a/sbt-plugin/src/main/contraband/input.contra b/sbt-plugin/src/main/contraband/input.contra index 78cc8b9a..7dc9390b 100644 --- a/sbt-plugin/src/main/contraband/input.contra +++ b/sbt-plugin/src/main/contraband/input.contra @@ -26,4 +26,14 @@ type DependencySnapshotInput { ## The job correlator of the snapshot correlator: String + + ## Overrides the sha attribute in the generated JSON file before submission. + shaOverride: String + + ## Overrides the ref attribute in the generated JSON file before submission. + refOverride: String + + ## Overrides the source_location attribute of each file object in the manifest entries of the JSON file before submission. + ## This does not affect which build.sbt file is actually processed - that can be controlled by the working-directory input. + manifestOverride: String } 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 975c3fab..39d0c10c 100644 --- a/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala +++ b/sbt-plugin/src/main/scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala @@ -127,6 +127,7 @@ object GithubDependencyGraphPlugin extends AutoPlugin { val onResolveFailure = inputOpt.flatMap(_.onResolveFailure) val ignoredConfigs = inputOpt.toSeq.flatMap(_.ignoredConfigs).toSet + val manifestOverrideOpt = inputOpt.flatMap(_.manifestOverride).filterNot(_.trim.isEmpty) val moduleName = crossVersion(projectID).name // a reverse view of internalConfigurationMap (internal-test -> test) @@ -205,7 +206,12 @@ object GithubDependencyGraphPlugin extends AutoPlugin { val projectModuleRef = getReference(projectID) val metadata = Map("baseDirectory" -> JString(baseDirectory.toString)) - val manifest = githubapi.Manifest(projectModuleRef, buildFileOpt, metadata, resolved.toMap) + val manifest = githubapi.Manifest( + projectModuleRef, + manifestOverrideOpt.map(githubapi.FileInfo(_)).orElse(buildFileOpt), + metadata, + resolved.toMap + ) 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 deb06d0c..c84dc017 100644 --- a/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala +++ b/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala @@ -42,7 +42,8 @@ object SubmitDependencyGraph { private def inputParser(state: State): Parser[DependencySnapshotInput] = Parsers.any.*.map { raw => val rawString = raw.mkString - if (rawString.isEmpty) DependencySnapshotInput(None, Vector.empty, Vector.empty, Some("")) + if (rawString.isEmpty) + DependencySnapshotInput(None, Vector.empty, Vector.empty, Some(""), Some(""), Some(""), Some("")) else JsonParser .parseFromString(rawString) @@ -155,11 +156,14 @@ object SubmitDependencyGraph { ) val scanned = Instant.now val manifests = state.get(githubManifestsKey).get + val inputOpt = state.get(githubSnapshotInputKey) + val shaOverrideOpt = inputOpt.flatMap(_.shaOverride).filterNot(_.trim.isEmpty) + val refOverrideOpt = inputOpt.flatMap(_.refOverride).filterNot(_.trim.isEmpty) DependencySnapshot( 0, githubJob(correlator), - githubSha(), - githubRef(), + shaOverrideOpt.getOrElse(githubSha()), + refOverrideOpt.getOrElse(githubRef()), detector, Map.empty[String, JValue], manifests, diff --git a/sbt-plugin/src/sbt-test/dependency-manifest/ignore-scaladoc/build.sbt b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-scaladoc/build.sbt index 6a2d4211..e55ecc5d 100644 --- a/sbt-plugin/src/sbt-test/dependency-manifest/ignore-scaladoc/build.sbt +++ b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-scaladoc/build.sbt @@ -17,7 +17,15 @@ inThisBuild( ) Global / ignoreScaladoc := { - val input = DependencySnapshotInput(None, Vector.empty, ignoredConfigs = Vector("scala-doc-tool"), correlator = None) + val input = DependencySnapshotInput( + None, + Vector.empty, + ignoredConfigs = Vector("scala-doc-tool"), + correlator = None, + shaOverride = None, + refOverride = None, + manifestOverride = None + ) StateTransform(state => state.put(githubSnapshotInputKey, input)) } diff --git a/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt index 03dcc7be..ec9aeb93 100644 --- a/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt +++ b/sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt @@ -17,7 +17,15 @@ inThisBuild( ) Global / ignoreTestConfig := { - val input = DependencySnapshotInput(None, Vector.empty, ignoredConfigs = Vector("test"), correlator = None) + val input = DependencySnapshotInput( + None, + Vector.empty, + ignoredConfigs = Vector("test"), + correlator = None, + shaOverride = None, + refOverride = None, + manifestOverride = None + ) StateTransform(state => state.put(githubSnapshotInputKey, input)) } diff --git a/sbt-plugin/src/test/scala/ch/epfl/scala/JsonProtocolTests.scala b/sbt-plugin/src/test/scala/ch/epfl/scala/JsonProtocolTests.scala index e3fdc07c..88b0d353 100644 --- a/sbt-plugin/src/test/scala/ch/epfl/scala/JsonProtocolTests.scala +++ b/sbt-plugin/src/test/scala/ch/epfl/scala/JsonProtocolTests.scala @@ -30,7 +30,7 @@ class JsonProtocolTests extends FunSuite { import ch.epfl.scala.JsonProtocol._ val raw = Parser.parseUnsafe("{}") val obtained = Converter.fromJson[DependencySnapshotInput](raw).get - val expected = DependencySnapshotInput(None, Vector.empty, Vector.empty, None) + val expected = DependencySnapshotInput(None, Vector.empty, Vector.empty, None, None, None, None) assertEquals(obtained, expected) } @@ -38,7 +38,7 @@ class JsonProtocolTests extends FunSuite { import ch.epfl.scala.JsonProtocol._ val raw = Parser.parseUnsafe("""{"onResolveFailure": "warning"}""") val obtained = Converter.fromJson[DependencySnapshotInput](raw).get - val expected = DependencySnapshotInput(Some(OnFailure.warning), Vector.empty, Vector.empty, None) + val expected = DependencySnapshotInput(Some(OnFailure.warning), Vector.empty, Vector.empty, None, None, None, None) assertEquals(obtained, expected) } } diff --git a/src/main.ts b/src/main.ts index 235e07b0..9e9274ea 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,7 +53,21 @@ async function run(): Promise { ? correlatorInput : `${github.context.workflow}_${github.context.job}_${github.context.action}` - const input = { ignoredModules, ignoredConfigs, onResolveFailure, correlator } + const shaOverride = core.getInput('sha-override') + + const refOverride = core.getInput('ref-override') + + const manifestOverride = core.getInput('manifest-override') + + const input = { + ignoredModules, + ignoredConfigs, + onResolveFailure, + correlator, + shaOverride, + refOverride, + manifestOverride, + } if (github.context.eventName === 'pull_request') { core.info('pull request, resetting sha')