feat: Add package version detection for sbt projects (#3274)
This commit is contained in:
parent
77182a9a22
commit
1109fd6997
|
@ -2239,6 +2239,7 @@ package, and shows its current version. The module currently supports `npm`, `ni
|
||||||
- [**Meson**](https://mesonbuild.com/) - The `meson` package version is extracted from the `meson.build` present
|
- [**Meson**](https://mesonbuild.com/) - The `meson` package version is extracted from the `meson.build` present
|
||||||
- [**Shards**](https://crystal-lang.org/reference/the_shards_command/index.html) - The `shards` package version is extracted from the `shard.yml` present
|
- [**Shards**](https://crystal-lang.org/reference/the_shards_command/index.html) - The `shards` package version is extracted from the `shard.yml` present
|
||||||
- [**V**](https://vlang.io) - The `vlang` package version is extracted from the `v.mod` present
|
- [**V**](https://vlang.io) - The `vlang` package version is extracted from the `v.mod` present
|
||||||
|
- [**SBT**](https://scala-sbt.org) - The `sbt` package version is extracted from the `build.sbt` present in the current directory
|
||||||
|
|
||||||
> ⚠️ The version being shown is that of the package whose source code is in your
|
> ⚠️ The version being shown is that of the package whose source code is in your
|
||||||
> current directory, not your package manager.
|
> current directory, not your package manager.
|
||||||
|
|
|
@ -197,6 +197,13 @@ fn get_vpkg_version(context: &Context, config: &PackageConfig) -> Option<String>
|
||||||
format_version(raw_version, config.version_format)
|
format_version(raw_version, config.version_format)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_sbt_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
||||||
|
let file_contents = utils::read_file(context.current_dir.join("build.sbt")).ok()?;
|
||||||
|
let re = Regex::new(r"(?m)^(.*/)*\s*version\s*:=\s*.(?P<version>[\d\.]+)").unwrap();
|
||||||
|
let caps = re.captures(&file_contents)?;
|
||||||
|
format_version(&caps["version"], config.version_format)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_cargo_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
fn get_cargo_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
||||||
let file_contents = utils::read_file(&context.current_dir.join("Cargo.toml")).ok()?;
|
let file_contents = utils::read_file(&context.current_dir.join("Cargo.toml")).ok()?;
|
||||||
|
|
||||||
|
@ -249,6 +256,7 @@ fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
||||||
get_shard_version,
|
get_shard_version,
|
||||||
get_vmod_version,
|
get_vmod_version,
|
||||||
get_vpkg_version,
|
get_vpkg_version,
|
||||||
|
get_sbt_version,
|
||||||
];
|
];
|
||||||
|
|
||||||
package_version_fn.iter().find_map(|f| f(context, config))
|
package_version_fn.iter().find_map(|f| f(context, config))
|
||||||
|
@ -1091,6 +1099,39 @@ Module {
|
||||||
project_dir.close()
|
project_dir.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_extract_sbt_version() -> io::Result<()> {
|
||||||
|
let config_name = "build.sbt";
|
||||||
|
let config_content = "\
|
||||||
|
name := \"starship\"
|
||||||
|
version := \"1.2.3\"
|
||||||
|
scalaVersion := \"2.13.7\"
|
||||||
|
|
||||||
|
assembly / assemblyMergeStrategy := {
|
||||||
|
case PathList(\"META-INF\", _ @ _*) => MergeStrategy.discard
|
||||||
|
case _ => MergeStrategy.first
|
||||||
|
}
|
||||||
|
";
|
||||||
|
let project_dir = create_project_dir()?;
|
||||||
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
||||||
|
expect_output(&project_dir, Some("v1.2.3"), None);
|
||||||
|
project_dir.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_extract_sbt_version_thisbuild() -> io::Result<()> {
|
||||||
|
let config_name = "build.sbt";
|
||||||
|
let config_content = "\
|
||||||
|
name := \"starship\"
|
||||||
|
ThisBuild / version := \"1.2.3\"
|
||||||
|
scalaVersion := \"2.13.7\"
|
||||||
|
";
|
||||||
|
let project_dir = create_project_dir()?;
|
||||||
|
fill_config(&project_dir, config_name, Some(config_content))?;
|
||||||
|
expect_output(&project_dir, Some("v1.2.3"), None);
|
||||||
|
project_dir.close()
|
||||||
|
}
|
||||||
|
|
||||||
fn create_project_dir() -> io::Result<TempDir> {
|
fn create_project_dir() -> io::Result<TempDir> {
|
||||||
tempfile::tempdir()
|
tempfile::tempdir()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue