Skip to content

Commit

Permalink
Merge pull request #178 from adpi2/update-readme
Browse files Browse the repository at this point in the history
Describe githubGenerateSnapshot in readme
  • Loading branch information
adpi2 authored May 15, 2024
2 parents a7a4a86 + 11d09d6 commit 5c974fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@ steps:

## Troubleshooting

### How to generate a snapshot locally?

For troubleshooting, it can be convenient to generate a snapshot locally.

To do so you need to install the `sbt-dependency-submission` plugin in your sbt project.

```scala
// In project/plugins.sbt
addSbtPlugin("ch.epfl.scala" % "sbt-github-dependency-submission" % "3.0.0")
```

After reloading your build, you can run:
```
sbt:example> githubGenerateSnapshot
...
[info] Dependency snapshot written to /tmp/dependency-snapshot-3080240838874963577.json
```

Or if you want to exclude some modules or configs:

```
sbt:example> githubGenerateSnapshot {"ignoredModules":["server_2.13"], "ignoredConfigs":["test"]}
...
[info] Dependency snapshot written to /tmp/dependency-snapshot-14803616116503623758.json
```

### Unexpected Status: 404

This error happens when the `Dependency Graph` feature is disabled.
Expand Down
5 changes: 1 addition & 4 deletions sbt-plugin/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ inThisBuild(
},
// Scalafix settings
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalafixDependencies ++= List(
"com.github.liancheng" %% "organize-imports" % "0.6.0"
)
semanticdbVersion := scalafixSemanticdb.revision
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import sjsonnew.support.scalajson.unsafe.{Parser => JsonParser, _}

object SubmitDependencyGraph {
val Generate = "githubGenerateSnapshot"
private val GenerateUsage = s"""$Generate {"projects":[], "scalaVersions":[]}"""
private val GenerateUsage = s"""$Generate {"ignoredModules":[], "ignoredConfig":[]}"""
private val GenerateDetail = "Generate the dependency graph of a set of projects and scala versions"

private val GenerateInternal = s"${Generate}Internal"
Expand All @@ -31,8 +31,6 @@ object SubmitDependencyGraph {
val Submit = "githubSubmitSnapshot"
private val SubmitDetail = "Submit the dependency graph to Github Dependency API."

def usage(command: String): String = s"""$command {"projects":[], "scalaVersions":[]}"""

val commands: Seq[Command] = Seq(
Command(Generate, (GenerateUsage, GenerateDetail), GenerateDetail)(inputParser)(generate),
Command.command(GenerateInternal, InternalOnly, InternalOnly)(generateInternal),
Expand All @@ -43,10 +41,13 @@ object SubmitDependencyGraph {

private def inputParser(state: State): Parser[DependencySnapshotInput] =
Parsers.any.*.map { raw =>
JsonParser
.parseFromString(raw.mkString)
.flatMap(Converter.fromJson[DependencySnapshotInput])
.get
val rawString = raw.mkString
if (rawString.isEmpty) DependencySnapshotInput(None, Vector.empty, Vector.empty)
else
JsonParser
.parseFromString(rawString)
.flatMap(Converter.fromJson[DependencySnapshotInput])
.get
}.failOnException

private def generate(state: State, input: DependencySnapshotInput): State = {
Expand Down

0 comments on commit 5c974fa

Please sign in to comment.