From 1f8af4e0025030ba6e6f31e3f7c3ae755fed1159 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Sun, 22 Oct 2023 10:18:27 +0200 Subject: [PATCH 1/6] Calculate snapshot version properly --- build.sbt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index 3a1c42af..95d44e8c 100644 --- a/build.sbt +++ b/build.sbt @@ -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 From 1b9a8f659fb5b3be2c429aa00f2ec94ebe048302 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sun, 23 Jan 2022 23:54:30 +0100 Subject: [PATCH 2/6] Use all matrix keys for artifact ids (cherry picked from commit 1d3ab46c3830bcd4ed224776178c034b149edd26) --- .github/workflows/ci.yml | 8 +-- .../scala/sbtghactions/GenerativeKeys.scala | 2 + .../scala/sbtghactions/GenerativePlugin.scala | 50 ++++++++++++++++--- .../check-and-regenerate/expected-ci.yml | 18 ++----- .../.github/workflows/ci.yml | 19 ++----- .../no-clean/.github/workflows/ci.yml | 18 ++----- .../.github/workflows/ci.yml | 6 +-- .../.github/workflows/ci.yml | 6 +-- .../suppressed-scala-version/expected-ci.yml | 6 +-- 9 files changed, 71 insertions(+), 62 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db458021..f58f9007 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }}-${{ matrix.project }} path: targets.tar publish: @@ -124,12 +124,12 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} cache: sbt - - name: Download target directories (2.12.18) + - name: Download target directories (2.12.18,rootJVM) uses: actions/download-artifact@v3 with: - name: target-${{ matrix.os }}-2.12.18-${{ matrix.java }} + name: target-${{ matrix.os }}-2.12.18-${{ matrix.java }}-2.12.18-rootJVM - - name: Inflate target directories (2.12.18) + - name: Inflate target directories (List(2.12.18, rootJVM)) run: | tar xf targets.tar rm targets.tar diff --git a/src/main/scala/sbtghactions/GenerativeKeys.scala b/src/main/scala/sbtghactions/GenerativeKeys.scala index 255eba37..dd727558 100644 --- a/src/main/scala/sbtghactions/GenerativeKeys.scala +++ b/src/main/scala/sbtghactions/GenerativeKeys.scala @@ -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 }} })") diff --git a/src/main/scala/sbtghactions/GenerativePlugin.scala b/src/main/scala/sbtghactions/GenerativePlugin.scala index 37786006..bb7f690f 100644 --- a/src/main/scala/sbtghactions/GenerativePlugin.scala +++ b/src/main/scala/sbtghactions/GenerativePlugin.scala @@ -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 => @@ -636,6 +636,14 @@ ${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 keys = githubWorkflowBuildMatrixAdditions + .value + .keys + .toList + .sorted + .map(k => s"$${{ matrix.$k }}") + .mkString("-", "-", "") + val upload = WorkflowStep.Use( UseRef.Public( "actions", @@ -643,7 +651,7 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} "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) @@ -653,18 +661,48 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} }, githubWorkflowGeneratedDownloadSteps := { - val scalas = githubWorkflowScalaVersions.value + val extraKeys = githubWorkflowArtifactDownloadExtraKeys.value + val additions = githubWorkflowBuildMatrixAdditions.value + val matrix = 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 scalas = githubWorkflowScalaVersions.value.toList + val exclusions = githubWorkflowBuildMatrixExclusions.value + + // we build the list of artifacts, by iterating over all combinations of keys + val artifacts = matrix + .toList + .sortBy(_._1) + .map(_._2) + .foldLeft(List(scalas)) { (artifacts, values) => + for { + artifact <- artifacts + value <- values + } yield artifact :+ value + } // then, we filter artifacts for keys that are excluded from the matrix + .filterNot { artifact => + val job = keys.zip(artifact).toMap + exclusions.exists { // there is an exclude that matches the current job + case MatrixExclude(matching) => matching.toSet.subsetOf(job.toSet) + } + } if (githubWorkflowArtifactUpload.value) { - scalas flatMap { v => + artifacts flatMap { v => val download = WorkflowStep.Use( UseRef.Public( "actions", "download-artifact", "v3"), - name = Some(s"Download target directories ($v)"), + name = Some(s"Download target directories (${v.mkString(",")})"), params = Map( - "name" -> s"target-$${{ matrix.os }}-$v-$${{ matrix.java }}")) + "name" -> s"target-$${{ matrix.os }}-$${{ matrix.java }}${v.mkString("-", "-", "")}")) val untar = WorkflowStep.Run( List( diff --git a/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml b/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml index be4d31f8..fd89dc2c 100644 --- a/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml +++ b/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml @@ -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: @@ -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 (List(2.13.10, 2.12.17, this)) run: | tar xf targets.tar rm targets.tar diff --git a/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml index ae164536..a7d797f5 100644 --- a/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml @@ -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: @@ -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 (List(2.13.10, 2.12.17)) shell: bash run: | tar xf targets.tar diff --git a/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml index aacb7405..86d9195d 100644 --- a/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml @@ -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: @@ -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 (List(2.13.10, 2.12.17)) run: | tar xf targets.tar rm targets.tar diff --git a/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml index 9fa73b9b..1b7337a8 100644 --- a/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml @@ -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: @@ -80,9 +80,9 @@ 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) + - name: Inflate target directories (List(2.13.10)) run: | tar xf targets.tar rm targets.tar diff --git a/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml index edf23b23..20af15fd 100644 --- a/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml @@ -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: @@ -97,9 +97,9 @@ 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) + - name: Inflate target directories (List(2.12.18)) run: | tar xf targets.tar rm targets.tar diff --git a/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml b/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml index 60dddc34..83011c17 100644 --- a/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml +++ b/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml @@ -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: @@ -82,9 +82,9 @@ 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) + - name: Inflate target directories (List(2.13.10)) run: | tar xf targets.tar rm targets.tar From e4ae4e435013f7fe7a4022c5ad58e154ecb42d08 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Mon, 18 Sep 2023 11:37:20 +0200 Subject: [PATCH 3/6] Handle case where githubWorkflowBuildMatrixAdditions is empty --- .github/workflows/ci.yml | 8 ++++---- src/main/scala/sbtghactions/GenerativePlugin.scala | 7 +++++-- .../.github/workflows/ci.yml | 2 +- .../sbtghactions/no-clean/.github/workflows/ci.yml | 2 +- .../non-existent-target/.github/workflows/ci.yml | 2 +- .../sbt-native-thin-client/.github/workflows/ci.yml | 2 +- .../sbtghactions/suppressed-scala-version/expected-ci.yml | 2 +- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f58f9007..ca19e1b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,7 +76,7 @@ jobs: - name: Upload target directories uses: actions/upload-artifact@v3 with: - name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}-${{ matrix.project }} + name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }} path: targets.tar publish: @@ -124,12 +124,12 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} cache: sbt - - name: Download target directories (2.12.18,rootJVM) + - name: Download target directories (2.12.18) uses: actions/download-artifact@v3 with: - name: target-${{ matrix.os }}-2.12.18-${{ matrix.java }}-2.12.18-rootJVM + name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18 - - name: Inflate target directories (List(2.12.18, rootJVM)) + - name: Inflate target directories (List(2.12.18)) run: | tar xf targets.tar rm targets.tar diff --git a/src/main/scala/sbtghactions/GenerativePlugin.scala b/src/main/scala/sbtghactions/GenerativePlugin.scala index bb7f690f..9e5ec0e6 100644 --- a/src/main/scala/sbtghactions/GenerativePlugin.scala +++ b/src/main/scala/sbtghactions/GenerativePlugin.scala @@ -636,8 +636,11 @@ ${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 keys = githubWorkflowBuildMatrixAdditions - .value + val matrixAdditions = githubWorkflowBuildMatrixAdditions.value + val keys = if (matrixAdditions.isEmpty) + "" + else + matrixAdditions .keys .toList .sorted diff --git a/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml index a7d797f5..623ae26f 100644 --- a/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: - name: Upload target directories uses: actions/upload-artifact@v3 with: - name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}- + name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }} path: targets.tar publish: diff --git a/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml index 86d9195d..375f4cac 100644 --- a/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: - name: Upload target directories uses: actions/upload-artifact@v3 with: - name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}- + name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }} path: targets.tar publish: diff --git a/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml index 1b7337a8..e2bc2ebd 100644 --- a/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: - name: Upload target directories uses: actions/upload-artifact@v3 with: - name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}- + name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }} path: targets.tar publish: diff --git a/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml index 20af15fd..7a93a143 100644 --- a/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: - name: Upload target directories uses: actions/upload-artifact@v3 with: - name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}- + name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }} path: targets.tar publish: diff --git a/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml b/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml index 83011c17..f542f053 100644 --- a/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml +++ b/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml @@ -52,7 +52,7 @@ jobs: - name: Upload target directories uses: actions/upload-artifact@v3 with: - name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}- + name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }} path: targets.tar publish: From 862239f2be69380c3ebb0a6c3f293cae74e68e76 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sun, 23 Jan 2022 23:59:29 +0100 Subject: [PATCH 4/6] Add a space (cherry picked from commit 347b0640da74692626127bd91568c582b4e525c7) --- src/main/scala/sbtghactions/GenerativePlugin.scala | 2 +- src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml | 2 +- .../githubworkflowoses-clean-publish/.github/workflows/ci.yml | 2 +- src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/scala/sbtghactions/GenerativePlugin.scala b/src/main/scala/sbtghactions/GenerativePlugin.scala index 9e5ec0e6..d9a460fa 100644 --- a/src/main/scala/sbtghactions/GenerativePlugin.scala +++ b/src/main/scala/sbtghactions/GenerativePlugin.scala @@ -703,7 +703,7 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} "actions", "download-artifact", "v3"), - name = Some(s"Download target directories (${v.mkString(",")})"), + name = Some(s"Download target directories (${v.mkString(", ")})"), params = Map( "name" -> s"target-$${{ matrix.os }}-$${{ matrix.java }}${v.mkString("-", "-", "")}")) diff --git a/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml b/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml index fd89dc2c..76f08531 100644 --- a/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml +++ b/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml @@ -112,7 +112,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} cache: sbt - - name: Download target directories (2.13.10,2.12.17,this) + - name: Download target directories (2.13.10, 2.12.17, this) uses: actions/download-artifact@v3 with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-2.12.17-this diff --git a/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml index 623ae26f..9bb02994 100644 --- a/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: java-version: 8 cache: sbt - - name: Download target directories (2.13.10,2.12.17) + - name: Download target directories (2.13.10, 2.12.17) uses: actions/download-artifact@v3 with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-2.12.17 diff --git a/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml index 375f4cac..9f47ccf1 100644 --- a/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs: java-version: 8 cache: sbt - - name: Download target directories (2.13.10,2.12.17) + - name: Download target directories (2.13.10, 2.12.17) uses: actions/download-artifact@v3 with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-2.12.17 From 6163e00741ff668a0024ec884c94ab9c6183438b Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Mon, 24 Jan 2022 00:01:26 +0100 Subject: [PATCH 5/6] Fix rendering (cherry picked from commit 94e06227498a7f95d1d938bde5ef980d5fe7fd14) --- .github/workflows/ci.yml | 2 +- src/main/scala/sbtghactions/GenerativePlugin.scala | 6 ++++-- .../sbtghactions/check-and-regenerate/expected-ci.yml | 2 +- .../.github/workflows/ci.yml | 2 +- src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml | 2 +- .../non-existent-target/.github/workflows/ci.yml | 2 +- .../sbt-native-thin-client/.github/workflows/ci.yml | 2 +- .../sbtghactions/suppressed-scala-version/expected-ci.yml | 2 +- 8 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca19e1b5..793753fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,7 @@ jobs: with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18 - - name: Inflate target directories (List(2.12.18)) + - name: Inflate target directories (2.12.18) run: | tar xf targets.tar rm targets.tar diff --git a/src/main/scala/sbtghactions/GenerativePlugin.scala b/src/main/scala/sbtghactions/GenerativePlugin.scala index d9a460fa..8df94146 100644 --- a/src/main/scala/sbtghactions/GenerativePlugin.scala +++ b/src/main/scala/sbtghactions/GenerativePlugin.scala @@ -698,12 +698,14 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} if (githubWorkflowArtifactUpload.value) { artifacts flatMap { v => + val pretty = v.mkString(", ") + val download = WorkflowStep.Use( UseRef.Public( "actions", "download-artifact", "v3"), - name = Some(s"Download target directories (${v.mkString(", ")})"), + name = Some(s"Download target directories ($pretty)"), params = Map( "name" -> s"target-$${{ matrix.os }}-$${{ matrix.java }}${v.mkString("-", "-", "")}")) @@ -711,7 +713,7 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} 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) } diff --git a/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml b/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml index 76f08531..baeedf69 100644 --- a/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml +++ b/src/sbt-test/sbtghactions/check-and-regenerate/expected-ci.yml @@ -117,7 +117,7 @@ jobs: with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-2.12.17-this - - name: Inflate target directories (List(2.13.10, 2.12.17, this)) + - name: Inflate target directories (2.13.10, 2.12.17, this) run: | tar xf targets.tar rm targets.tar diff --git a/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml index 9bb02994..76ee29e8 100644 --- a/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/githubworkflowoses-clean-publish/.github/workflows/ci.yml @@ -110,7 +110,7 @@ jobs: with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-2.12.17 - - name: Inflate target directories (List(2.13.10, 2.12.17)) + - name: Inflate target directories (2.13.10, 2.12.17) shell: bash run: | tar xf targets.tar diff --git a/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml index 9f47ccf1..fce12d1e 100644 --- a/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/no-clean/.github/workflows/ci.yml @@ -83,7 +83,7 @@ jobs: with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-2.12.17 - - name: Inflate target directories (List(2.13.10, 2.12.17)) + - name: Inflate target directories (2.13.10, 2.12.17) run: | tar xf targets.tar rm targets.tar diff --git a/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml index e2bc2ebd..1ea0cc41 100644 --- a/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/non-existent-target/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10 - - name: Inflate target directories (List(2.13.10)) + - name: Inflate target directories (2.13.10) run: | tar xf targets.tar rm targets.tar diff --git a/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml b/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml index 7a93a143..3f67212c 100644 --- a/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml +++ b/src/sbt-test/sbtghactions/sbt-native-thin-client/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.18 - - name: Inflate target directories (List(2.12.18)) + - name: Inflate target directories (2.12.18) run: | tar xf targets.tar rm targets.tar diff --git a/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml b/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml index f542f053..0e4d0904 100644 --- a/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml +++ b/src/sbt-test/sbtghactions/suppressed-scala-version/expected-ci.yml @@ -84,7 +84,7 @@ jobs: with: name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10 - - name: Inflate target directories (List(2.13.10)) + - name: Inflate target directories (2.13.10) run: | tar xf targets.tar rm targets.tar From 796352371f8ffd6545c87e9b31f67078a284354f Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 23 Feb 2022 22:29:53 +0100 Subject: [PATCH 6/6] Checkpoint matrix expansion changes (cherry picked from commit 5b86e388b09753349138ce453933532459fe14c7) --- .github/workflows/ci.yml | 50 +++++++++++++++ .../scala/sbtghactions/GenerativePlugin.scala | 64 +++++++++++++------ 2 files changed, 96 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 793753fa..f9263cee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -134,6 +134,56 @@ jobs: 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: | + tar xf targets.tar + rm targets.tar + - name: Publish project env: PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} diff --git a/src/main/scala/sbtghactions/GenerativePlugin.scala b/src/main/scala/sbtghactions/GenerativePlugin.scala index 8df94146..7e355a84 100644 --- a/src/main/scala/sbtghactions/GenerativePlugin.scala +++ b/src/main/scala/sbtghactions/GenerativePlugin.scala @@ -666,7 +666,7 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} githubWorkflowGeneratedDownloadSteps := { val extraKeys = githubWorkflowArtifactDownloadExtraKeys.value val additions = githubWorkflowBuildMatrixAdditions.value - val matrix = additions.map { + val matrixAdds = additions.map { case (key, values) => if (extraKeys(key)) key -> values // we want to iterate over all values @@ -675,25 +675,23 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} } val keys = "scala" :: additions.keys.toList.sorted + val oses = githubWorkflowOSes.value.toList val scalas = githubWorkflowScalaVersions.value.toList - val exclusions = githubWorkflowBuildMatrixExclusions.value + 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 = matrix - .toList - .sortBy(_._1) - .map(_._2) - .foldLeft(List(scalas)) { (artifacts, values) => - for { - artifact <- artifacts - value <- values - } yield artifact :+ value - } // then, we filter artifacts for keys that are excluded from the matrix - .filterNot { artifact => - val job = keys.zip(artifact).toMap - exclusions.exists { // there is an exclude that matches the current job - case MatrixExclude(matching) => matching.toSet.subsetOf(job.toSet) - } + 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) { @@ -974,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)) {