Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(verhandle): properly provide versioned semantics #72

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions axoupdater-cli/src/bin/axoupdater/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ struct CliArgs {
/// Installs the specified version instead of the latest version
#[clap(long)]
version: Option<String>,

/// Allows prereleases when just updating to "latest"
#[clap(long)]
prerelease: bool,
}

fn real_main(cli: &CliApp<CliArgs>) -> Result<(), miette::Report> {
Expand All @@ -26,16 +30,16 @@ fn real_main(cli: &CliApp<CliArgs>) -> Result<(), miette::Report> {
let mut updater = AxoUpdater::new_for_updater_executable()?;
updater.load_receipt()?;

if let Some(version) = &cli.config.tag {
updater.configure_version_specifier(axoupdater::UpdateRequest::SpecificTag(
version.to_owned(),
));
}
if let Some(version) = &cli.config.version {
updater.configure_version_specifier(axoupdater::UpdateRequest::SpecificVersion(
version.to_owned(),
));
}
let specifier = if let Some(tag) = &cli.config.tag {
axoupdater::UpdateRequest::SpecificTag(tag.clone())
} else if let Some(version) = &cli.config.version {
axoupdater::UpdateRequest::SpecificVersion(version.clone())
} else if cli.config.prerelease {
axoupdater::UpdateRequest::LatestMaybePrerelease
} else {
axoupdater::UpdateRequest::Latest
};
updater.configure_version_specifier(specifier);

if let Some(result) = updater.run_sync()? {
eprintln!("New release {} installed!", result.new_version)
Expand Down
60 changes: 60 additions & 0 deletions axoupdater-cli/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,66 @@ fn test_upgrade() -> std::io::Result<()> {
Ok(())
}

#[test]
fn test_upgrade_allow_prerelease() -> std::io::Result<()> {
let tempdir = TempDir::new()?;
let bindir_path = &tempdir.path().join("bin");
let bindir = Utf8Path::from_path(bindir_path).unwrap();
std::fs::create_dir_all(bindir)?;

let base_version = "0.2.115";

let url = axolotlsay_tarball_path(base_version);

let mut response = reqwest::blocking::get(url)
.unwrap()
.error_for_status()
.unwrap();

let compressed_path =
Utf8PathBuf::from_path_buf(tempdir.path().join("axolotlsay.tar.gz")).unwrap();
let mut contents = vec![];
response.read_to_end(&mut contents)?;
std::fs::write(&compressed_path, contents)?;

// Write the receipt for the updater to use
write_receipt(base_version, &bindir.to_path_buf())?;

LocalAsset::untar_gz_all(&compressed_path, bindir).unwrap();

// Now install our copy of the updater instead of the one axolotlsay came with
let updater_path = bindir.join(format!("axolotlsay-update{EXE_SUFFIX}"));
std::fs::copy(BIN, &updater_path)?;

let mut updater = Cmd::new(&updater_path, "run updater");
updater.env("AXOUPDATER_CONFIG_PATH", bindir);
updater.arg("--prerelease");
// We'll do that manually
updater.check(false);
let result = updater.output();
assert!(result.is_ok());
let res = result.unwrap();
let output_stdout = String::from_utf8(res.stdout).unwrap();
let output_stderr = String::from_utf8(res.stderr).unwrap();

// Now let's check the version we just updated to
let new_axolotlsay_path = &bindir.join(format!("axolotlsay{EXE_SUFFIX}"));
assert!(
new_axolotlsay_path.exists(),
"update result was\nstdout\n{}\nstderr\n{}",
output_stdout,
output_stderr
);
let mut new_axolotlsay = Cmd::new(new_axolotlsay_path, "version test");
new_axolotlsay.arg("--version");
let output = new_axolotlsay.output().unwrap();
let stderr_string = String::from_utf8(output.stdout).unwrap();
assert!(stderr_string.starts_with("axolotlsay "));
assert_ne!(stderr_string, format!("axolotlsay {}\n", base_version));

Ok(())
}

// A similar test to the one above, but it upgrades to a specific version
// instead of whatever's latest.
#[test]
Expand Down
1 change: 1 addition & 0 deletions axoupdater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ axoasset = { version = "0.9.1", default-features = false, features = [
"json-serde",
] }
axoprocess = "0.2.0"
axotag = { version = "0.2.0" }
camino = { version = "1.1.6", features = ["serde1"] }
homedir = "0.2.1"
serde = "1.0.197"
Expand Down
Loading
Loading