Skip to content

Commit 68d84c6

Browse files
authored
Merge pull request #75 from scalacenter/fix-49
Add configs-ignore input
2 parents cf68df0 + 65b9dfc commit 68d84c6

File tree

9 files changed

+126
-10
lines changed

9 files changed

+126
-10
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ The name of a module contains the name of the project and its binary version.
4545

4646
Example: `foo_2.13 bar_2.13`
4747

48+
#### - `configs-ignore` (optional)
49+
50+
A list of space-separated names of configurations to ignore. The action will not submit the dependencies of these configurations.
51+
52+
Example of configurations are `compile`, `test`, `scala-tool`, `scala-doc-tool`.
53+
4854
#### - `token` (optional)
4955

5056
GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner.
@@ -53,6 +59,8 @@ Example: `${{ secrets.USER_TOKEN }}`
5359

5460
#### Example
5561

62+
##### Excluding some projects or some Scala versions from the dependency submission.
63+
5664
In this example the snapshot will not contain the graphs of `foo_2.13` and `bar_3`.
5765

5866
```yaml
@@ -67,6 +75,22 @@ steps:
6775
modules-ignore: foo_2.13 bar_3
6876
```
6977

78+
#### Excluding the Scaladoc dependencies.
79+
80+
In this example the snapshot will not contain the dependencies of the scala-doc-tool configuration.
81+
82+
```yaml
83+
84+
## in .github/workflows/dependency-graph.md
85+
...
86+
steps:
87+
- uses: actions/checkout@v3
88+
- uses: scalacenter/sbt-dependency-submission@v2
89+
with:
90+
base-dir: ./my-scala-project
91+
configs-ignore: scala-doc-tool
92+
```
93+
7094
## Troubleshooting
7195

7296
### Unexpected Status: 404

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ inputs:
1616
Example: `foo_2.13 bar_2.13`
1717
required: false
1818
default: ''
19+
configs-ignore:
20+
description: |
21+
A list of space-separated names of configurations to ignore. The action will not submit the dependencies of these configurations.
22+
Example: `test scala-doc-tool`
23+
required: false
24+
default: ''
1925
on-resolve-failure:
2026
description: |
2127
Either 'error' or 'warning'.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ type SubmitInput {
1616
## The name of module is composed of the name of the project and its binary version.
1717
## Example: foo_2.13
1818
ignoredModules: [String]
19+
20+
## A set of sbt configurations to ignore.
21+
## Examples:
22+
## - "test" to ignore the test dependencies
23+
## - "scala-doc-tool" to ignore the scaladoc dependencies
24+
## - "scala-tool" to ignore the compiler dependencies
25+
ignoredConfigs: [String]
1926
}

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,20 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
8888

8989
private def includeProject(projectRef: ProjectRef, state: State, logger: Logger): Boolean = {
9090
val ignoredModules = state.attributes(githubSubmitInputKey).ignoredModules
91-
val scalaVersion = state.setting(projectRef / Keys.artifactName / Keys.scalaVersion)
92-
val scalaBinaryVersion = state.setting(projectRef / Keys.artifactName / Keys.scalaBinaryVersion)
93-
val projectID = state.setting(projectRef / Keys.projectID)
94-
val moduleName = CrossVersion(scalaVersion, scalaBinaryVersion).apply(projectID).name
91+
val moduleName = getModuleName(projectRef, state)
9592
val ignored = ignoredModules.contains(moduleName)
9693
if (!ignored) logger.info(s"Including dependency graph of $moduleName")
9794
else logger.info(s"Excluding dependency graph of $moduleName")
9895
!ignored
9996
}
10097

98+
private def getModuleName(projectRef: ProjectRef, state: State): String = {
99+
val scalaVersion = state.setting(projectRef / Keys.artifactName / Keys.scalaVersion)
100+
val scalaBinaryVersion = state.setting(projectRef / Keys.artifactName / Keys.scalaBinaryVersion)
101+
val projectID = state.setting(projectRef / Keys.projectID)
102+
CrossVersion(scalaVersion, scalaBinaryVersion).apply(projectID).name
103+
}
104+
101105
private def manifestTask: Def.Initialize[Task[Option[Manifest]]] = Def.task {
102106
// updateFull is needed to have information about callers and reconstruct dependency tree
103107
val reportResult = Keys.updateFull.result.value
@@ -108,17 +112,26 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
108112
val allDirectDependencies = Keys.allDependencies.value
109113
val baseDirectory = Keys.baseDirectory.value
110114
val logger = Keys.streams.value.log
111-
val onResolveFailure = Keys.state.value.get(githubSubmitInputKey).flatMap(_.onResolveFailure)
115+
val input = Keys.state.value.get(githubSubmitInputKey)
116+
117+
val onResolveFailure = input.flatMap(_.onResolveFailure)
118+
val ignoredConfigs = input.toSeq.flatMap(_.ignoredConfigs).toSet
119+
val moduleName = crossVersion(projectID).name
112120

113121
def getReference(module: ModuleID): String =
114122
crossVersion(module)
115123
.withConfigurations(None)
116124
.withExtraAttributes(Map.empty)
117125
.toString
118126

127+
def includeConfig(config: ConfigRef): Boolean =
128+
if (ignoredConfigs.contains(config.name)) {
129+
logger.info(s"Excluding config ${config.name} of ${moduleName} from its dependency graph")
130+
false
131+
} else true
132+
119133
reportResult match {
120134
case Inc(cause) =>
121-
val moduleName = crossVersion(projectID).name
122135
val message = s"Failed to resolve the dependencies of $moduleName"
123136
onResolveFailure match {
124137
case Some(OnFailure.warning) =>
@@ -132,9 +145,9 @@ object GithubDependencyGraphPlugin extends AutoPlugin {
132145
val alreadySeen = mutable.Set[String]()
133146
val moduleReports = mutable.Buffer[(ModuleReport, ConfigRef)]()
134147
val allDependencies = mutable.Buffer[(String, String)]()
135-
136148
for {
137149
configReport <- report.configurations
150+
if includeConfig(configReport.configuration)
138151
moduleReport <- configReport.modules
139152
moduleRef = getReference(moduleReport.module)
140153
if !moduleReport.evicted && !alreadySeen.contains(moduleRef)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import ch.epfl.scala.githubapi.DependencyRelationship
2+
import ch.epfl.scala.githubapi.DependencyScope
3+
import ch.epfl.scala.githubapi.Manifest
4+
import ch.epfl.scala.SubmitInput
5+
import sjsonnew.shaded.scalajson.ast.unsafe.JString
6+
7+
val checkScaladoc = taskKey[Unit]("Check scaladoc_3 is in the manifest ")
8+
val ignoreScaladoc = taskKey[StateTransform]("Ignore the scala-doc-tool in the submit input")
9+
val checkIgnoreScaladoc = taskKey[Unit]("Check scaladoc_3 is absent in the manifest")
10+
11+
inThisBuild(
12+
Seq(
13+
organization := "ch.epfl.scala",
14+
version := "1.2.0-SNAPSHOT",
15+
scalaVersion := "3.2.1"
16+
)
17+
)
18+
19+
Global / ignoreScaladoc := {
20+
val input = SubmitInput(None, Vector.empty, ignoredConfigs = Vector("scala-doc-tool"))
21+
StateTransform(state => state.put(githubSubmitInputKey, input))
22+
}
23+
24+
lazy val p1 = project
25+
.in(file("p1"))
26+
.settings(
27+
checkScaladoc := {
28+
val manifest = githubDependencyManifest.value.get
29+
checkDependency(manifest, "org.scala-lang:scaladoc_3:3.2.1")(
30+
expectedRelationship = DependencyRelationship.direct,
31+
expectedScope = DependencyScope.development,
32+
expectedConfig = "scala-doc-tool"
33+
)
34+
},
35+
checkIgnoreScaladoc := {
36+
val manifest = githubDependencyManifest.value.get
37+
val suspicious = manifest.resolved.keys.filter(dep => dep.contains("scaladoc_3"))
38+
assert(suspicious.isEmpty, s"The manifest should not contain scaladoc_3, found ${suspicious.mkString(", ")}")
39+
}
40+
)
41+
42+
def checkDependency(manifest: Manifest, name: String)(
43+
expectedRelationship: DependencyRelationship = DependencyRelationship.direct,
44+
expectedScope: DependencyScope = DependencyScope.runtime,
45+
expectedConfig: String = "compile",
46+
expectedDeps: Seq[String] = Seq.empty
47+
): Unit = {
48+
val node = manifest.resolved(name)
49+
assert(node.package_url.startsWith("pkg:maven/"), s"Wrong package_url for node $name: ${node.package_url}")
50+
assert(node.relationship.contains(expectedRelationship), s"Wrong relationship for node $name: ${node.relationship}")
51+
assert(node.scope.contains(expectedScope), s"Wrong scope for node $name: ${node.scope}")
52+
val configurations = node.metadata.get("config").collect { case JString(c) => c }
53+
assert(configurations.contains(expectedConfig), s"Wrong config in metadata for node $name: $configurations")
54+
expectedDeps.foreach(d => assert(node.dependencies.contains(d), s"missing dependency $d in node $name"))
55+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val pluginVersion = sys.props("plugin.version")
2+
3+
addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-submission" % pluginVersion)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> p1 / checkScaladoc
2+
> Global / ignoreScaladoc
3+
> p1 / checkIgnoreScaladoc

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[SubmitInput](raw).get
33-
val expected = SubmitInput(None, Vector.empty)
33+
val expected = SubmitInput(None, Vector.empty, Vector.empty)
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[SubmitInput](raw).get
41-
val expected = SubmitInput(Some(OnFailure.warning), Vector.empty)
41+
val expected = SubmitInput(Some(OnFailure.warning), Vector.empty, Vector.empty)
4242
assertEquals(obtained, expected)
4343
}
4444
}

src/main.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ async function run(): Promise<void> {
3535
.split(' ')
3636
.filter(value => value.length > 0)
3737

38+
const ignoredConfigs = core
39+
.getInput('configs-ignore')
40+
.split(' ')
41+
.filter(value => value.length > 0)
42+
3843
const onResolveFailure = core.getInput('on-resolve-failure')
3944
if (!['error', 'warning'].includes(onResolveFailure)) {
4045
core.setFailed(
@@ -43,7 +48,7 @@ async function run(): Promise<void> {
4348
return
4449
}
4550

46-
const input = { ignoredModules, onResolveFailure }
51+
const input = { ignoredModules, ignoredConfigs, onResolveFailure }
4752

4853
process.env['GITHUB_TOKEN'] = token
4954
await cli.exec('sbt', [`githubSubmitDependencyGraph ${JSON.stringify(input)}`], {

0 commit comments

Comments
 (0)