Skip to content

Commit

Permalink
Add validation for pants_version format (#338)
Browse files Browse the repository at this point in the history
Implemented a check to ensure the 'pants_version' follows the
'major.minor.micro' format. This update raises a clear error message if
the version string does not meet the expected format, enhancing user
guidance and preventing configuration errors.

Fix #337
  • Loading branch information
Seaweed0112 authored Jan 5, 2024
1 parent 7691160 commit c24cbd4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
31 changes: 31 additions & 0 deletions package/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub(crate) fn run_integration_tests(
test_ignore_empty_pants_version_pants_sha(scie_pants_scie);

test_pants_from_pex_version(scie_pants_scie);
test_pants_from_bad_pex_version(scie_pants_scie);

let clone_root = create_tempdir()?;
test_use_in_repo_with_pants_script(scie_pants_scie, &clone_root);
Expand Down Expand Up @@ -460,6 +461,36 @@ fn test_pants_from_pex_version(scie_pants_scie: &Path) {
);
}

fn test_pants_from_bad_pex_version(scie_pants_scie: &Path) {
integration_test!(
"Verify the output of scie-pants is user-friendly if they provide an invalid pants version"
);

let tmpdir = create_tempdir().unwrap();

let pants_release = "2.18";
let pants_toml_content = format!(
r#"
[GLOBAL]
pants_version = "{pants_release}"
"#
);
let pants_toml = tmpdir.path().join("pants.toml");
write_file(&pants_toml, false, pants_toml_content).unwrap();

let err = execute(
Command::new(scie_pants_scie)
.arg("-V")
.current_dir(&tmpdir)
.stderr(Stdio::piped()),
)
.unwrap_err();

let error_text = err.to_string();
assert!(error_text.contains("Wasn't able to fetch the Pants PEX at"));
assert!(error_text.contains("Pants version format not recognized. Please add `.<patch_version>` to the end of the version. For example: `2.18` -> `2.18.0`"));
}

fn test_use_in_repo_with_pants_script(scie_pants_scie: &Path, clone_root: &TempDir) {
integration_test!("Verify scie-pants can be used as `pants` in a repo with the `pants` script");
// This verifies a fix for https://github.com/pantsbuild/scie-pants/issues/28.
Expand Down
8 changes: 7 additions & 1 deletion tools/src/scie_pants/install_pants.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,14 @@ def install_pants_from_pex(
try:
ptex.fetch_to_fp(pex_url, pants_pex.file)
except subprocess.CalledProcessError as e:
# if there's only one dot in version, specifically suggest adding the `.patch`)
suggestion = (
"Pants version format not recognized. Please add `.<patch_version>` to the end of the version. For example: `2.18` -> `2.18.0`.\n\n"
if version.base_version.count(".") < 2
else ""
)
fatal(
f"Wasn't able to fetch the Pants PEX at {pex_url}.\n\n"
f"Wasn't able to fetch the Pants PEX at {pex_url}.\n\n{suggestion}"
"Check to see if the URL is reachable (i.e. GitHub isn't down) and if"
f" {pex_name} asset exists within the release."
" If the asset doesn't exist it may be that this platform isn't yet supported."
Expand Down

0 comments on commit c24cbd4

Please sign in to comment.