Skip to content

Commit

Permalink
Avoid storing 0.0.0-dev into package.yaml (#11805)
Browse files Browse the repository at this point in the history
Storing `0.0.0-dev` into `package.yaml` makes little sense:
- no two _development version_ are the same
- there is no way to _download_ `0.0.0-dev` version via `ensoup`
- regular releases refuse to process `0.0.0-dev` projects

Better to avoid storing such _development version_ at all.
  • Loading branch information
JaroslavTulach authored Dec 9, 2024
1 parent a666ef0 commit 3e23e72
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@ lazy val pkg = (project in file("lib/scala/pkg"))
(`editions` / Compile / exportedModule).value,
(`semver` / Compile / exportedModule).value,
(`scala-yaml` / Compile / exportedModule).value,
(`scala-libs-wrapper` / Compile / exportedModule).value
(`scala-libs-wrapper` / Compile / exportedModule).value,
(`version-output` / Compile / exportedModule).value
)
)
.dependsOn(editions)
Expand Down
1 change: 1 addition & 0 deletions lib/scala/pkg/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
requires org.apache.commons.compress;
requires org.enso.editions;
requires org.enso.semver;
requires org.enso.version.output;
requires org.enso.scala.yaml;
// For io.circe
requires org.enso.scala.wrapper;
Expand Down
15 changes: 14 additions & 1 deletion lib/scala/pkg/src/main/scala/org/enso/pkg/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.enso.semver.SemVer
import org.enso.editions.{EditionName, Editions}
import org.enso.pkg.validation.NameValidation
import org.enso.scala.yaml.{YamlDecoder, YamlEncoder}
import org.enso.version.BuildVersion
import org.yaml.snakeyaml.{DumperOptions, Yaml}
import org.yaml.snakeyaml.error.YAMLException
import org.yaml.snakeyaml.nodes.{MappingNode, Node}
Expand Down Expand Up @@ -114,7 +115,19 @@ case class Config(

/** Converts the configuration into a YAML representation. */
def toYaml: String = {
val node = implicitly[YamlEncoder[Config]].encode(this)
val config: Config = this
val noDevEdition: Config =
if (
config.edition.exists(
_.parent
.exists(p => p.toString == BuildVersion.defaultDevEnsoVersion())
)
) {
config.copy(edition = None)
} else {
config
}
val node = implicitly[YamlEncoder[Config]].encode(noDevEdition)
val dumperOptions = new DumperOptions()
dumperOptions.setIndent(2)
dumperOptions.setPrettyFlow(true)
Expand Down
20 changes: 20 additions & 0 deletions lib/scala/pkg/src/test/scala/org/enso/pkg/ConfigSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ class ConfigSpec
parsed.edition shouldBe empty
}

"persist normal edition" in {
val parsed = Config.fromYaml("name: fooBar\nedition: 2024.4.2").get
parsed.name shouldEqual "fooBar"
parsed.normalizedName shouldEqual None
parsed.moduleName shouldEqual "FooBar"

val ser = parsed.toYaml
ser shouldEqual "name: fooBar\nnamespace: local\nedition: 2024.4.2\n"
}

"don't persist dev edition" in {
val parsed = Config.fromYaml("name: fooBar\nedition: 0.0.0-dev").get
parsed.name shouldEqual "fooBar"
parsed.normalizedName shouldEqual None
parsed.moduleName shouldEqual "FooBar"

val ser = parsed.toYaml
ser shouldEqual "name: fooBar\nnamespace: local\n"
}

"correctly de-serialize and serialize back the shortened edition syntax " +
"if there are no overrides" in {
val config =
Expand Down

0 comments on commit 3e23e72

Please sign in to comment.