From c416668ee8c313fc18a3f083ce29aaf581578ede Mon Sep 17 00:00:00 2001 From: tanishiking24 Date: Thu, 14 Nov 2019 01:16:30 +0900 Subject: [PATCH 1/3] Introduce localSnapshotVersion - Before this commit, `sbt publishLocal` publish the build to local ivy with the version something like `1.6.0-RC4+blahblah+yyyymmdd-SNAPSHOT` - when scalafmt-dynamic tries to download scalafmt-core whose version is `1.6.0-xxx-SNAPSHOT`, it looks for scalafmt built with 2.12 - However, the default scala version is now 2.13 and `sbt publishLocal` will build scalafmt with 2.13 and publish it with `1.6.0-xxx-SNAPSHOT`. - As a result, scalafmt-dynamic cannot resolve the local build. I know we can avoid this problem(?) by building snapshot build with 2.12 instead of 2.13, but it would be handy if we can test the snapshot version only with `sbt publishLocal` instead of `sbt +publishLocal`. The idea of localSnapshotVersion is come from [metals](https://github.com/scalameta/metals/blob/05017dc44e384ab8e0a8202ebd128f697594d686/build.sbt#L1-L19) --- build.sbt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.sbt b/build.sbt index f37a6c3bec..84f5dbbae6 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,7 @@ import Dependencies._ import sbtcrossproject.CrossPlugin.autoImport.crossProject +def localSnapshotVersion = "2.2.3-SNAPSHOT" +def isCI = System.getenv("CI") != null def scala211 = "2.11.12" def scala212 = "2.12.8" @@ -7,6 +9,10 @@ def scala213 = "2.13.1" inThisBuild( List( + version ~= { dynVer => + if (isCI) dynVer + else localSnapshotVersion // only for local publishng + }, organization := "org.scalameta", homepage := Some(url("https://github.com/scalameta/scalafmt")), licenses := List( From 1ac63594f1caa2758533ffc4402b37e5c2691a75 Mon Sep 17 00:00:00 2001 From: tanishiking24 Date: Thu, 14 Nov 2019 01:52:15 +0900 Subject: [PATCH 2/3] Enable scalafmt-dynamic to parse snapshot versions --- .../org/scalafmt/dynamic/ScalafmtVersion.scala | 2 +- .../src/test/scala/tests/DynamicSuite.scala | 5 +++-- .../test/scala/tests/ScalafmtVersionSuite.scala | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtVersion.scala b/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtVersion.scala index ad632cc7db..2c545cd929 100644 --- a/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtVersion.scala +++ b/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtVersion.scala @@ -22,7 +22,7 @@ object ScalafmtVersion { extends Exception(s"Invalid scalafmt version $version") with NoStackTrace - private val versionRegex = """(\d)\.(\d)\.(\d)(-RC(\d))?""".r + private val versionRegex = """(\d)\.(\d)\.(\d)(-RC(\d))?(?:-SNAPSHOT)?""".r def parse(version: String): Either[InvalidVersionException, ScalafmtVersion] = try { diff --git a/scalafmt-dynamic/src/test/scala/tests/DynamicSuite.scala b/scalafmt-dynamic/src/test/scala/tests/DynamicSuite.scala index e81b8368a1..39dd5b433b 100644 --- a/scalafmt-dynamic/src/test/scala/tests/DynamicSuite.scala +++ b/scalafmt-dynamic/src/test/scala/tests/DynamicSuite.scala @@ -323,9 +323,10 @@ class DynamicSuite extends FunSuite with DiffAssertions { check("wrong-version") { f => f.setVersion("1.0") f.assertError( - "error: path/.scalafmt.conf: failed to resolve Scalafmt version '1.0'" + """|error: path/.scalafmt.conf: org.scalafmt.dynamic.exceptions.ScalafmtException: failed to resolve Scalafmt version '1.0' + |Caused by: org.scalafmt.dynamic.ScalafmtVersion$InvalidVersionException: Invalid scalafmt version 1.0""".stripMargin ) - assert(f.downloadLogs.nonEmpty) + assert(f.downloadLogs.isEmpty) } check("sbt") { f => diff --git a/scalafmt-dynamic/src/test/scala/tests/ScalafmtVersionSuite.scala b/scalafmt-dynamic/src/test/scala/tests/ScalafmtVersionSuite.scala index 9c9719c990..52c065804b 100644 --- a/scalafmt-dynamic/src/test/scala/tests/ScalafmtVersionSuite.scala +++ b/scalafmt-dynamic/src/test/scala/tests/ScalafmtVersionSuite.scala @@ -12,6 +12,15 @@ class ScalafmtVersionSuite extends FunSuite { ScalafmtVersion.parse("2.0.0-RC4") == Right(ScalafmtVersion(2, 0, 0, 4)) ) assert(ScalafmtVersion.parse("2.1.1") == Right(ScalafmtVersion(2, 1, 1, 0))) + assert( + ScalafmtVersion + .parse("2.2.3-SNAPSHOT") == Right(ScalafmtVersion(2, 2, 3, 0)) + ) + assert( + ScalafmtVersion.parse("2.0.0-RC1-SNAPSHOT") == Right( + ScalafmtVersion(2, 0, 0, 1) + ) + ) } test("fail on invalid versions") { @@ -51,6 +60,11 @@ class ScalafmtVersionSuite extends FunSuite { ScalafmtVersion .parse("2.1.0-RC1-M4") == Left(InvalidVersionException("2.1.0-RC1-M4")) ) + assert( + ScalafmtVersion.parse("2.0.0-RC1+metadata") == Left( + InvalidVersionException("2.0.0-RC1+metadata") + ) + ) } test("order versions") { From f14229d258e82e93f405fba84d6d7916e7efb9b4 Mon Sep 17 00:00:00 2001 From: tanishiking24 Date: Thu, 14 Nov 2019 22:02:35 +0900 Subject: [PATCH 3/3] Retrieve local snapshot version from git --- build.sbt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 84f5dbbae6..bc2ceb2423 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,12 @@ import Dependencies._ import sbtcrossproject.CrossPlugin.autoImport.crossProject -def localSnapshotVersion = "2.2.3-SNAPSHOT" + +def parseTagVersion: String = { + import scala.sys.process._ + // drop `v` prefix + "git describe --abbrev=0 --tags".!!.drop(1).trim +} +def localSnapshotVersion: String = s"$parseTagVersion-SNAPSHOT" def isCI = System.getenv("CI") != null def scala211 = "2.11.12"