Skip to content

Override the ref, sha and the manifests' source_location attributes in the JSON that will be submitted #249

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

Closed
wants to merge 5 commits into from
Closed
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions sbt-plugin/src/main/contraband/input.contra
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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)
}

test("decode input with onResolveFailure: warning") {
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)
}
}
16 changes: 15 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,21 @@ async function run(): Promise<void> {
? 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')
Expand Down
Loading