Skip to content
Open
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
54 changes: 52 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Upload target directories
uses: actions/upload-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}
path: targets.tar

publish:
Expand Down Expand Up @@ -127,7 +127,57 @@ jobs:
- name: Download target directories (2.12.18)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.12.18-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18

- name: Inflate target directories (2.12.18)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.18)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18

- name: Inflate target directories (2.12.18)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.18)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18

- name: Inflate target directories (2.12.18)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.18)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18

- name: Inflate target directories (2.12.18)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.18)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18

- name: Inflate target directories (2.12.18)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.18)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18

- name: Inflate target directories (2.12.18)
run: |
Expand Down
19 changes: 15 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,21 @@ ThisBuild / githubWorkflowPublish := Seq(
)
)
)
ThisBuild / version := {
val orig = (ThisBuild / version).value
if (orig.endsWith("-SNAPSHOT")) orig.split("""\+""").head + "-SNAPSHOT"
else orig

// So that publishLocal doesn't continuously create new versions
def versionFmt(out: sbtdynver.GitDescribeOutput): String = {
val snapshotSuffix = if
(out.isSnapshot()) "-SNAPSHOT"
else ""
out.ref.dropPrefix + snapshotSuffix
}

def fallbackVersion(d: java.util.Date): String = s"HEAD-${sbtdynver.DynVer timestamp d}"

ThisBuild / version := dynverGitDescribeOutput.value.mkVersion(versionFmt, fallbackVersion(dynverCurrentDate.value))
ThisBuild / dynver := {
val d = new java.util.Date
sbtdynver.DynVer.getGitDescribeOutput(d).mkVersion(versionFmt, fallbackVersion(d))
}

sbtPlugin := true
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/sbtghactions/GenerativeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ trait GenerativeKeys {
lazy val githubWorkflowPREventTypes = settingKey[Seq[PREventType]]("A list of pull request event types which will be used to trigger builds (default: [opened, synchronize, reopened])")

lazy val githubWorkflowArtifactUpload = settingKey[Boolean]("Controls whether or not to upload target directories in the event that multiple jobs are running sequentially. Can be set on a per-project basis (default: true)")
lazy val githubWorkflowArtifactDownloadExtraKeys = settingKey[Set[String]](
"Additional matrix keys for which *all* artifacts should be downloaded and not just for the primary value (default: {})")
lazy val githubWorkflowJobSetup = settingKey[Seq[WorkflowStep]]("The automatically-generated checkout, setup, and cache steps which are common to all jobs which touch the build (default: autogenerated)")

lazy val githubWorkflowEnv = settingKey[Map[String, String]](s"A map of static environment variable assignments global to the workflow (default: { GITHUB_TOKEN: $${{ secrets.GITHUB_TOKEN }} })")
Expand Down
87 changes: 79 additions & 8 deletions src/main/scala/sbtghactions/GenerativePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}

override def buildSettings = settingDefaults ++ Seq(
githubWorkflowPREventTypes := PREventType.Defaults,

githubWorkflowArtifactDownloadExtraKeys := Set.empty,
githubWorkflowGeneratedUploadSteps := {
if (githubWorkflowArtifactUpload.value) {
val sanitized = pathStrs.value map { str =>
Expand All @@ -636,14 +636,25 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
List(s"tar cf targets.tar ${sanitized.mkString(" ")} project/target"),
name = Some("Compress target directories"))

val matrixAdditions = githubWorkflowBuildMatrixAdditions.value
val keys = if (matrixAdditions.isEmpty)
""
else
matrixAdditions
.keys
.toList
.sorted
.map(k => s"$${{ matrix.$k }}")
.mkString("-", "-", "")

val upload = WorkflowStep.Use(
UseRef.Public(
"actions",
"upload-artifact",
"v3"),
name = Some(s"Upload target directories"),
params = Map(
"name" -> s"target-$${{ matrix.os }}-$${{ matrix.scala }}-$${{ matrix.java }}",
"name" -> s"target-$${{ matrix.os }}-$${{ matrix.java }}-$${{ matrix.scala }}$keys",
"path" -> "targets.tar"))

Seq(tar, upload)
Expand All @@ -653,24 +664,54 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
},

githubWorkflowGeneratedDownloadSteps := {
val scalas = githubWorkflowScalaVersions.value
val extraKeys = githubWorkflowArtifactDownloadExtraKeys.value
val additions = githubWorkflowBuildMatrixAdditions.value
val matrixAdds = additions.map {
case (key, values) =>
if (extraKeys(key))
key -> values // we want to iterate over all values
else
key -> values.take(1) // we only want the primary value
}

val keys = "scala" :: additions.keys.toList.sorted
val oses = githubWorkflowOSes.value.toList
val scalas = githubWorkflowScalaVersions.value.toList
val javas = githubWorkflowJavaVersions.value.toList
val exclusions = githubWorkflowBuildMatrixExclusions.value.toList

// we build the list of artifacts, by iterating over all combinations of keys
val artifacts =
expandMatrix(
oses,
scalas,
javas,
matrixAdds,
Nil,
exclusions
).map {
case _ :: scala :: _ :: tail => scala :: tail
case _ => sys.error("Bug generating artifact download steps") // shouldn't happen
}

if (githubWorkflowArtifactUpload.value) {
scalas flatMap { v =>
artifacts flatMap { v =>
val pretty = v.mkString(", ")

val download = WorkflowStep.Use(
UseRef.Public(
"actions",
"download-artifact",
"v3"),
name = Some(s"Download target directories ($v)"),
name = Some(s"Download target directories ($pretty)"),
params = Map(
"name" -> s"target-$${{ matrix.os }}-$v-$${{ matrix.java }}"))
"name" -> s"target-$${{ matrix.os }}-$${{ matrix.java }}${v.mkString("-", "-", "")}"))

val untar = WorkflowStep.Run(
List(
"tar xf targets.tar",
"rm targets.tar"),
name = Some(s"Inflate target directories ($v)"))
name = Some(s"Inflate target directories ($pretty)"))

Seq(download, untar)
}
Expand Down Expand Up @@ -931,7 +972,37 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
},
githubWorkflowDir := baseDirectory.value / ".github")

private[sbtghactions] def diff(expected: String, actual: String): String = {
private def expandMatrix(
oses: List[String],
scalas: List[String],
javas: List[JavaSpec],
matrixAdds: Map[String, List[String]],
includes: List[MatrixInclude],
excludes: List[MatrixExclude]
): List[List[String]] = {
val keys = "os" :: "scala" :: "java" :: matrixAdds.keys.toList.sorted
val matrix =
matrixAdds + ("os" -> oses) + ("scala" -> scalas) + ("java" -> javas.map(_.render))

// expand the matrix
keys
.foldLeft(List(List.empty[String])) { (cells, key) =>
val values = matrix.getOrElse(key, Nil)
cells.flatMap { cell => values.map(v => cell ::: v :: Nil) }
}
.filterNot { cell => // remove the excludes
val job = keys.zip(cell).toMap
excludes.exists { // there is an exclude that matches the current job
case MatrixExclude(matching) => matching.toSet.subsetOf(job.toSet)
}
} ::: includes.map { // add the includes
case MatrixInclude(matching, additions) =>
// yoloing here, but let's wait for the bug report
keys.map(matching) ::: additions.values.toList
}
}

private def diff(expected: String, actual: String): String = {
val expectedLines = expected.split("\n", -1)
val actualLines = actual.split("\n", -1)
val (lines, _) = expectedLines.zipAll(actualLines, "", "").foldLeft((Vector.empty[String], false)) {
Expand Down
18 changes: 4 additions & 14 deletions src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Upload target directories
uses: actions/upload-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}-${{ matrix.test }}
path: targets.tar

publish:
Expand Down Expand Up @@ -112,22 +112,12 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: sbt

- name: Download target directories (2.13.10)
- name: Download target directories (2.13.10, 2.12.17, this)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.13.10-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-2.12.17-this

- name: Inflate target directories (2.13.10)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.17)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.12.17-${{ matrix.java }}

- name: Inflate target directories (2.12.17)
- name: Inflate target directories (2.13.10, 2.12.17, this)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Upload target directories
uses: actions/upload-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}
path: targets.tar

publish:
Expand Down Expand Up @@ -105,23 +105,12 @@ jobs:
java-version: 8
cache: sbt

- name: Download target directories (2.13.10)
- name: Download target directories (2.13.10, 2.12.17)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.13.10-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-2.12.17

- name: Inflate target directories (2.13.10)
shell: bash
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.17)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.12.17-${{ matrix.java }}

- name: Inflate target directories (2.12.17)
- name: Inflate target directories (2.13.10, 2.12.17)
shell: bash
run: |
tar xf targets.tar
Expand Down
18 changes: 4 additions & 14 deletions src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Upload target directories
uses: actions/upload-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}
path: targets.tar

publish:
Expand All @@ -78,22 +78,12 @@ jobs:
java-version: 8
cache: sbt

- name: Download target directories (2.13.10)
- name: Download target directories (2.13.10, 2.12.17)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.13.10-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-2.12.17

- name: Inflate target directories (2.13.10)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.17)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.12.17-${{ matrix.java }}

- name: Inflate target directories (2.12.17)
- name: Inflate target directories (2.13.10, 2.12.17)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Upload target directories
uses: actions/upload-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}
path: targets.tar

publish:
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Download target directories (2.13.10)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.13.10-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10

- name: Inflate target directories (2.13.10)
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Upload target directories
uses: actions/upload-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}
path: targets.tar

publish:
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Download target directories (2.12.18)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.12.18-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18

- name: Inflate target directories (2.12.18)
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Upload target directories
uses: actions/upload-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}
path: targets.tar

publish:
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Download target directories (2.13.10)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.13.10-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10

- name: Inflate target directories (2.13.10)
run: |
Expand Down