Skip to content

Commit c9c33b5

Browse files
committed
Add correlator input for matrix based jobs
1 parent 587cef7 commit c9c33b5

File tree

8 files changed

+36
-18
lines changed

8 files changed

+36
-18
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ A list of space-separated names of configurations to ignore. The action will not
5151

5252
Example of configurations are `compile`, `test`, `scala-tool`, `scala-doc-tool`.
5353

54+
### - `correlator` (optional)
55+
56+
An optional identifier to distinguish between multiple dependency snapshots of the same type.
57+
Defaults to the concatenation of the workflow name, the job id and the action id.
58+
59+
Typically you would specify the correlator in a matrix-based job like this:
60+
61+
```yaml
62+
correlator: ${{ github.job }}-${{ matrix.directory }}
63+
```
64+
5465
#### - `token` (optional)
5566

5667
GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner.

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ inputs:
2222
Example: `test scala-doc-tool`
2323
required: false
2424
default: ''
25+
correlator:
26+
description: |
27+
An optional identifier to distinguish between multiple dependency snapshots of the same type.
28+
Defaults to the concatenation of the workflow name, the job id and the action id.
29+
required: false
30+
default: ''
2531
on-resolve-failure:
2632
description: |
2733
Either 'error' or 'warning'.

sbt-plugin/src/main/contraband/input.contra

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ type DependencySnapshotInput {
2323
## - "scala-doc-tool" to ignore the scaladoc dependencies
2424
## - "scala-tool" to ignore the compiler dependencies
2525
ignoredConfigs: [String]
26+
27+
## The job correlator of the snapshot
28+
correlator: String
2629
}

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object SubmitDependencyGraph {
4242
private def inputParser(state: State): Parser[DependencySnapshotInput] =
4343
Parsers.any.*.map { raw =>
4444
val rawString = raw.mkString
45-
if (rawString.isEmpty) DependencySnapshotInput(None, Vector.empty, Vector.empty)
45+
if (rawString.isEmpty) DependencySnapshotInput(None, Vector.empty, Vector.empty, Some(""))
4646
else
4747
JsonParser
4848
.parseFromString(rawString)
@@ -82,7 +82,8 @@ object SubmitDependencyGraph {
8282
}
8383

8484
private def generateInternal(state: State): State = {
85-
val snapshot = githubDependencySnapshot(state)
85+
val input = state.attributes(githubSnapshotInputKey)
86+
val snapshot = githubDependencySnapshot(state, input.correlator.getOrElse(""))
8687
val snapshotJson = CompactPrinter(Converter.toJsonUnsafe(snapshot))
8788
val snapshotJsonFile = IO.withTemporaryFile("dependency-snapshot-", ".json", keepFile = true) { file =>
8889
IO.write(file, snapshotJson)
@@ -103,7 +104,8 @@ object SubmitDependencyGraph {
103104
)
104105
)
105106
val snapshotUrl = s"${githubApiUrl()}/repos/${githubRepository()}/dependency-graph/snapshots"
106-
val job = githubJob()
107+
val input = state.attributes(githubSnapshotInputKey)
108+
val job = githubJob(input.correlator.getOrElse(""))
107109
val request = Gigahorse
108110
.url(snapshotUrl)
109111
.post(snapshotJsonFile)
@@ -145,7 +147,7 @@ object SubmitDependencyGraph {
145147
throw new MessageOnlyException(message)
146148
}
147149

148-
private def githubDependencySnapshot(state: State): DependencySnapshot = {
150+
private def githubDependencySnapshot(state: State, correlator: String): DependencySnapshot = {
149151
val detector = DetectorMetadata(
150152
SbtGithubDependencySubmission.name,
151153
SbtGithubDependencySubmission.homepage.map(_.toString).getOrElse(""),
@@ -155,7 +157,7 @@ object SubmitDependencyGraph {
155157
val manifests = state.get(githubManifestsKey).get
156158
DependencySnapshot(
157159
0,
158-
githubJob(),
160+
githubJob(correlator),
159161
githubSha(),
160162
githubRef(),
161163
detector,
@@ -165,8 +167,7 @@ object SubmitDependencyGraph {
165167
)
166168
}
167169

168-
private def githubJob(): Job = {
169-
val correlator = s"${githubWorkflow()}_${githubJobName()}_${githubAction()}"
170+
private def githubJob(correlator: String): Job = {
170171
val id = githubRunId
171172
val html_url =
172173
for {
@@ -181,9 +182,6 @@ object SubmitDependencyGraph {
181182
throw new MessageOnlyException(s"Missing environment variable $name. This task must run in a Github Action.")
182183
}
183184
check("GITHUB_WORKSPACE")
184-
check("GITHUB_WORKFLOW")
185-
check("GITHUB_JOB")
186-
check("GITHUB_ACTION")
187185
check("GITHUB_RUN_ID")
188186
check("GITHUB_SHA")
189187
check("GITHUB_REF")
@@ -194,9 +192,6 @@ object SubmitDependencyGraph {
194192
}
195193

196194
private def githubWorkspace(): String = Properties.envOrElse("GITHUB_WORKSPACE", "")
197-
private def githubWorkflow(): String = Properties.envOrElse("GITHUB_WORKFLOW", "")
198-
private def githubJobName(): String = Properties.envOrElse("GITHUB_JOB", "")
199-
private def githubAction(): String = Properties.envOrElse("GITHUB_ACTION", "")
200195
private def githubRunId(): String = Properties.envOrElse("GITHUB_RUN_ID", "")
201196
private def githubSha(): String = Properties.envOrElse("GITHUB_SHA", "")
202197
private def githubRef(): String = Properties.envOrElse("GITHUB_REF", "")

sbt-plugin/src/sbt-test/dependency-manifest/ignore-scaladoc/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ inThisBuild(
1717
)
1818

1919
Global / ignoreScaladoc := {
20-
val input = DependencySnapshotInput(None, Vector.empty, ignoredConfigs = Vector("scala-doc-tool"))
20+
val input = DependencySnapshotInput(None, Vector.empty, ignoredConfigs = Vector("scala-doc-tool"), correlator = None)
2121
StateTransform(state => state.put(githubSnapshotInputKey, input))
2222
}
2323

sbt-plugin/src/sbt-test/dependency-manifest/ignore-test/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ inThisBuild(
1717
)
1818

1919
Global / ignoreTestConfig := {
20-
val input = DependencySnapshotInput(None, Vector.empty, ignoredConfigs = Vector("test"))
20+
val input = DependencySnapshotInput(None, Vector.empty, ignoredConfigs = Vector("test"), correlator = None)
2121
StateTransform(state => state.put(githubSnapshotInputKey, input))
2222
}
2323

sbt-plugin/src/test/scala/ch/epfl/scala/JsonProtocolTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class JsonProtocolTests extends FunSuite {
3030
import ch.epfl.scala.JsonProtocol._
3131
val raw = Parser.parseUnsafe("{}")
3232
val obtained = Converter.fromJson[DependencySnapshotInput](raw).get
33-
val expected = DependencySnapshotInput(None, Vector.empty, Vector.empty)
33+
val expected = DependencySnapshotInput(None, Vector.empty, Vector.empty, None)
3434
assertEquals(obtained, expected)
3535
}
3636

3737
test("decode input with onResolveFailure: warning") {
3838
import ch.epfl.scala.JsonProtocol._
3939
val raw = Parser.parseUnsafe("""{"onResolveFailure": "warning"}""")
4040
val obtained = Converter.fromJson[DependencySnapshotInput](raw).get
41-
val expected = DependencySnapshotInput(Some(OnFailure.warning), Vector.empty, Vector.empty)
41+
val expected = DependencySnapshotInput(Some(OnFailure.warning), Vector.empty, Vector.empty, None)
4242
assertEquals(obtained, expected)
4343
}
4444
}

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ async function run(): Promise<void> {
4848
return
4949
}
5050

51-
const input = { ignoredModules, ignoredConfigs, onResolveFailure }
51+
const correlatorInput = core.getInput('correlator')
52+
const correlator = correlatorInput ? correlatorInput : `${github.context.workflow}_${github.context.job}_${github.context.action}`
53+
54+
const input = { ignoredModules, ignoredConfigs, onResolveFailure, correlator }
5255

5356
if (github.context.eventName === 'pull_request') {
5457
core.info('pull request, resetting sha')

0 commit comments

Comments
 (0)