feat(package): Add support for Ansible Galaxy (#6905)

This commit is contained in:
-k
2025-08-17 10:52:52 -07:00
committed by GitHub
parent 6886ad082c
commit 07778a8452
2 changed files with 25 additions and 1 deletions
+2 -1
View File
@@ -3558,7 +3558,7 @@ Arch = "Arch is the best! "
The `package` module is shown when the current directory is the repository for a
package, and shows its current version. The module currently supports `npm`, `nimble`, `cargo`,
`poetry`, `python`, `composer`, `gradle`, `julia`, `mix`, `helm`, `shards`, `daml` and `dart` packages.
`poetry`, `python`, `composer`, `gradle`, `julia`, `mix`, `helm`, `shards`, `galaxy`, `daml` and `dart` packages.
- [**npm**](https://docs.npmjs.com/cli/commands/npm) The `npm` package version is extracted from the `package.json` present
in the current directory
@@ -3577,6 +3577,7 @@ package, and shows its current version. The module currently supports `npm`, `ni
- [**Maven**](https://maven.apache.org/) - The `maven` package version is extracted from the `pom.xml` present in the current directory
- [**Meson**](https://mesonbuild.com/) - The `meson` package version is extracted from the `meson.build` present in the current directory
- [**Shards**](https://crystal-lang.org/reference/the_shards_command/index.html) - The `shards` package version is extracted from the `shard.yml` present in the current directory
- [**Galaxy**](https://galaxy.ansible.com/) - The `galaxy` package version is extracted from the `galaxy.yml` present in the current directory
- [**V**](https://vlang.io) - The `vlang` package version is extracted from the `v.mod` present in the current directory
- [**SBT**](https://scala-sbt.org) - The `sbt` package version is extracted from the `build.sbt` present in the current directory
- [**Daml**](https://www.digitalasset.com/developers) - The `daml` package version is extracted from the `daml.yaml` present in the current directory
+23
View File
@@ -343,6 +343,14 @@ fn get_rlang_version(context: &Context, config: &PackageConfig) -> Option<String
format_version(&caps["version"], config.version_format)
}
fn get_galaxy_version(context: &Context, config: &PackageConfig) -> Option<String> {
let file_contents = context.read_file_from_pwd("galaxy.yml")?;
let data = yaml_rust2::YamlLoader::load_from_str(&file_contents).ok()?;
let raw_version = data.first()?["version"].as_str()?;
format_version(raw_version, config.version_format)
}
fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
let package_version_fn: Vec<fn(&Context, &PackageConfig) -> Option<String>> = vec![
get_cargo_version,
@@ -365,6 +373,7 @@ fn get_version(context: &Context, config: &PackageConfig) -> Option<String> {
get_daml_project_version,
get_dart_pub_version,
get_rlang_version,
get_galaxy_version,
];
package_version_fn.iter().find_map(|f| f(context, config))
@@ -1547,6 +1556,20 @@ Title: Starship
expect_output(&project_dir, Some("v1.0.0"), None);
project_dir.close()
}
#[test]
fn test_ansible_galaxy_version() -> io::Result<()> {
let config_name = "galaxy.yml";
let config_content = "namespace: starfleet\nname: starship\nversion: 1.2.3\n".to_string();
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> {
tempfile::tempdir()
}