From a986269044307b25342be21afe9a15ac471d2b62 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Wed, 26 Feb 2025 16:24:52 +0100 Subject: [PATCH 1/5] Add ref-override config --- README.md | 4 ++++ action.yml | 4 ++++ sbt-plugin/src/main/contraband/input.contra | 3 +++ .../scala/ch/epfl/scala/SubmitDependencyGraph.scala | 6 ++++-- src/main.ts | 10 +++++++++- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ce52274..900be56 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ Typically you would specify the correlator in a matrix-based job like this: correlator: ${{ github.job }}-${{ matrix.directory }} ``` +#### - `ref-override` (optional) + +Overrides the `ref` attribute in the generated JSON file before submission. + #### - `token` (optional) GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner. diff --git a/action.yml b/action.yml index d5e20aa..8b9c2fd 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,10 @@ inputs: If 'warning', the job will ignore the failing modules and submit the snapshot. required: false default: error + ref-override: + description: "Overrides the `ref` attribute in the generated JSON file before submission." + 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 78cc8b9..5ce0140 100644 --- a/sbt-plugin/src/main/contraband/input.contra +++ b/sbt-plugin/src/main/contraband/input.contra @@ -26,4 +26,7 @@ type DependencySnapshotInput { ## The job correlator of the snapshot correlator: String + + ## Overrides the ref attribute in the generated JSON file before submission. + refOverride: String } 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 deb06d0..726c2c5 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,7 @@ 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("")) else JsonParser .parseFromString(rawString) @@ -155,11 +155,13 @@ object SubmitDependencyGraph { ) val scanned = Instant.now val manifests = state.get(githubManifestsKey).get + val inputOpt = state.get(githubSnapshotInputKey) + val refOverrideOpt = inputOpt.flatMap(_.refOverride).filterNot(_.trim.isEmpty) DependencySnapshot( 0, githubJob(correlator), githubSha(), - githubRef(), + refOverrideOpt.getOrElse(githubRef()), detector, Map.empty[String, JValue], manifests, diff --git a/src/main.ts b/src/main.ts index 235e07b..8014f1a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,7 +53,15 @@ async function run(): Promise { ? correlatorInput : `${github.context.workflow}_${github.context.job}_${github.context.action}` - const input = { ignoredModules, ignoredConfigs, onResolveFailure, correlator } + const refOverride = core.getInput('ref-override') + + const input = { + ignoredModules, + ignoredConfigs, + onResolveFailure, + correlator, + refOverride, + } if (github.context.eventName === 'pull_request') { core.info('pull request, resetting sha') From 8bf01816a834153a78346f285200bce20a8453f3 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Wed, 26 Feb 2025 20:13:06 +0100 Subject: [PATCH 2/5] Add sha-override config --- README.md | 4 ++++ action.yml | 4 ++++ sbt-plugin/src/main/contraband/input.contra | 3 +++ .../main/scala/ch/epfl/scala/SubmitDependencyGraph.scala | 6 ++++-- src/main.ts | 3 +++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 900be56..7fd2015 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ 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. diff --git a/action.yml b/action.yml index 8b9c2fd..5b9df97 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,10 @@ 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 diff --git a/sbt-plugin/src/main/contraband/input.contra b/sbt-plugin/src/main/contraband/input.contra index 5ce0140..b53c2f1 100644 --- a/sbt-plugin/src/main/contraband/input.contra +++ b/sbt-plugin/src/main/contraband/input.contra @@ -27,6 +27,9 @@ 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 } 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 726c2c5..1afc5c6 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(""), Some("")) + if (rawString.isEmpty) + DependencySnapshotInput(None, Vector.empty, Vector.empty, Some(""), Some(""), Some("")) else JsonParser .parseFromString(rawString) @@ -156,11 +157,12 @@ 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(), + shaOverrideOpt.getOrElse(githubSha()), refOverrideOpt.getOrElse(githubRef()), detector, Map.empty[String, JValue], diff --git a/src/main.ts b/src/main.ts index 8014f1a..6040f70 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,6 +53,8 @@ async function run(): Promise { ? correlatorInput : `${github.context.workflow}_${github.context.job}_${github.context.action}` + const shaOverride = core.getInput('sha-override') + const refOverride = core.getInput('ref-override') const input = { @@ -60,6 +62,7 @@ async function run(): Promise { ignoredConfigs, onResolveFailure, correlator, + shaOverride, refOverride, } From dbbe23c10b67ca2395b087c8660409cddfeb7776 Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Wed, 5 Mar 2025 00:21:28 +0100 Subject: [PATCH 3/5] Add manifest-override config --- README.md | 5 +++++ action.yml | 6 ++++++ sbt-plugin/src/main/contraband/input.contra | 4 ++++ .../scala/ch/epfl/scala/GithubDependencyGraphPlugin.scala | 8 +++++++- .../main/scala/ch/epfl/scala/SubmitDependencyGraph.scala | 2 +- src/main.ts | 3 +++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7fd2015..2d92694 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,11 @@ Overrides the `sha` attribute in the generated JSON file before submission. 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 5b9df97..9337efc 100644 --- a/action.yml +++ b/action.yml @@ -43,6 +43,12 @@ inputs: 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 b53c2f1..7dc9390 100644 --- a/sbt-plugin/src/main/contraband/input.contra +++ b/sbt-plugin/src/main/contraband/input.contra @@ -32,4 +32,8 @@ type DependencySnapshotInput { ## 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 975c3fa..39d0c10 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 1afc5c6..c84dc01 100644 --- a/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala +++ b/sbt-plugin/src/main/scala/ch/epfl/scala/SubmitDependencyGraph.scala @@ -43,7 +43,7 @@ object SubmitDependencyGraph { Parsers.any.*.map { raw => val rawString = raw.mkString if (rawString.isEmpty) - DependencySnapshotInput(None, Vector.empty, Vector.empty, Some(""), Some(""), Some("")) + DependencySnapshotInput(None, Vector.empty, Vector.empty, Some(""), Some(""), Some(""), Some("")) else JsonParser .parseFromString(rawString) diff --git a/src/main.ts b/src/main.ts index 6040f70..9e9274e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -57,6 +57,8 @@ async function run(): Promise { const refOverride = core.getInput('ref-override') + const manifestOverride = core.getInput('manifest-override') + const input = { ignoredModules, ignoredConfigs, @@ -64,6 +66,7 @@ async function run(): Promise { correlator, shaOverride, refOverride, + manifestOverride, } if (github.context.eventName === 'pull_request') { From 338efcd3635c14dd2c4a74f570aca8578400621f Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Thu, 6 Mar 2025 16:53:01 +0100 Subject: [PATCH 4/5] Fix tests --- .../src/test/scala/ch/epfl/scala/JsonProtocolTests.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 e3fdc07..88b0d35 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) } } From dccb52afead7bba1fea53ec00542e24b9cba656c Mon Sep 17 00:00:00 2001 From: Matthias Kurz Date: Thu, 6 Mar 2025 18:15:22 +0100 Subject: [PATCH 5/5] Fix scripted test --- .../dependency-manifest/ignore-scaladoc/build.sbt | 10 +++++++++- .../sbt-test/dependency-manifest/ignore-test/build.sbt | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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 6a2d421..e55ecc5 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 03dcc7b..ec9aeb9 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)) }