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: update axoupdater, fetch known-good version #1598

Merged
merged 3 commits into from
Dec 18, 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
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ axoproject = { version = "=0.26.1", path = "axoproject", default-features = fals

# first-party deps
axocli = { version = "0.2.0" }
axoupdater = { version = "0.8.1" }
axoupdater = { version = "0.8.2" }
axotag = "0.2.0"
axoasset = { version = "1.2.0", features = ["json-serde", "toml-serde", "toml-edit", "yaml-serde", "compression", "remote"] }
axoprocess = { version = "0.2.0" }
Expand Down
9 changes: 9 additions & 0 deletions cargo-dist/src/config/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ pub struct DistMetadata {
#[serde(skip_serializing_if = "Option::is_none")]
pub install_updater: Option<bool>,

/// Whether to always use the latest axoupdater instead of a known-good version
#[serde(skip_serializing_if = "Option::is_none")]
pub always_use_latest_updater: Option<bool>,

/// Whether artifacts/installers for this app should be displayed in release bodies
#[serde(skip_serializing_if = "Option::is_none")]
pub display: Option<bool>,
Expand Down Expand Up @@ -533,6 +537,7 @@ impl DistMetadata {
bin_aliases: _,
tag_namespace: _,
install_updater: _,
always_use_latest_updater: _,
github_releases_repo: _,
github_releases_submodule_path: _,
display: _,
Expand Down Expand Up @@ -634,6 +639,7 @@ impl DistMetadata {
bin_aliases,
tag_namespace,
install_updater,
always_use_latest_updater,
github_releases_repo,
github_releases_submodule_path,
display,
Expand Down Expand Up @@ -818,6 +824,9 @@ impl DistMetadata {
if install_updater.is_none() {
*install_updater = workspace_config.install_updater;
}
if always_use_latest_updater.is_none() {
*always_use_latest_updater = workspace_config.always_use_latest_updater;
}
if display.is_none() {
*display = workspace_config.display;
}
Expand Down
5 changes: 4 additions & 1 deletion cargo-dist/src/config/v0_to_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl DistMetadata {
bin_aliases,
tag_namespace,
install_updater,
always_use_latest_updater,
display,
display_name,
package_libraries,
Expand Down Expand Up @@ -314,7 +315,8 @@ impl DistMetadata {
|| install_success_msg.is_some()
|| install_libraries.is_some()
|| bin_aliases.is_some()
|| install_updater.is_some();
|| install_updater.is_some()
|| always_use_latest_updater.is_some();
let installer_layer = needs_installer_layer.then_some(InstallerLayer {
common: CommonInstallerLayer {
install_path,
Expand All @@ -329,6 +331,7 @@ impl DistMetadata {
shell: shell_installer_layer,
pkg: pkg_installer_layer,
updater: install_updater,
always_use_latest_updater,
});

// publish
Expand Down
18 changes: 17 additions & 1 deletion cargo-dist/src/config/v1/installers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use shell::*;
pub struct WorkspaceInstallerConfig {
/// Whether to install an updater program alongside the software
pub updater: bool,
/// Whether to always use the latest version instead of a known-good version
pub always_use_latest_updater: bool,
}
/// package installer config (final)
#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -58,6 +60,8 @@ pub struct InstallerConfigInheritable {
pub pkg: Option<PkgInstallerLayer>,
/// Whether to install an updater program alongside the software
pub updater: bool,
/// Whether to always use the latest version instead of a fixed version
pub always_use_latest_updater: bool,
}

/// installer config (raw from file)
Expand All @@ -82,6 +86,9 @@ pub struct InstallerLayer {
/// Whether to install an updater program alongside the software
#[serde(skip_serializing_if = "Option::is_none")]
pub updater: Option<bool>,
/// Whether to always use the latest updater version instead of a fixed version
#[serde(skip_serializing_if = "Option::is_none")]
pub always_use_latest_updater: Option<bool>,
}
impl InstallerConfigInheritable {
/// defaults for a workspace
Expand All @@ -103,6 +110,7 @@ impl InstallerConfigInheritable {
shell: None,
pkg: None,
updater: false,
always_use_latest_updater: false,
}
}
/// apply inheritance to and get final workspace config
Expand All @@ -113,6 +121,7 @@ impl InstallerConfigInheritable {
let Self {
// global
updater,
always_use_latest_updater,
// local-only
common: _,
homebrew: _,
Expand All @@ -123,7 +132,10 @@ impl InstallerConfigInheritable {
pkg: _,
} = self;

WorkspaceInstallerConfig { updater }
WorkspaceInstallerConfig {
updater,
always_use_latest_updater,
}
}
/// apply inheritance to get final package config
pub fn apply_inheritance_for_package(
Expand All @@ -141,6 +153,7 @@ impl InstallerConfigInheritable {
pkg,
// global-only
updater: _,
always_use_latest_updater: _,
} = self;
let homebrew = homebrew.map(|homebrew| {
let mut default =
Expand Down Expand Up @@ -201,6 +214,7 @@ impl ApplyLayer for InstallerConfigInheritable {
shell,
pkg,
updater,
always_use_latest_updater,
}: Self::Layer,
) {
self.common.apply_layer(common);
Expand All @@ -211,6 +225,8 @@ impl ApplyLayer for InstallerConfigInheritable {
self.shell.apply_bool_layer(shell);
self.pkg.apply_bool_layer(pkg);
self.updater.apply_val(updater);
self.always_use_latest_updater
.apply_val(always_use_latest_updater);
}
}

Expand Down
9 changes: 9 additions & 0 deletions cargo-dist/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ fn get_new_dist_metadata(
bin_aliases: None,
tag_namespace: None,
install_updater: None,
always_use_latest_updater: None,
display: None,
display_name: None,
package_libraries: None,
Expand Down Expand Up @@ -951,6 +952,7 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
hosting,
tag_namespace,
install_updater,
always_use_latest_updater,
display,
display_name,
github_release,
Expand Down Expand Up @@ -1340,6 +1342,13 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
*install_updater,
);

apply_optional_value(
table,
"always-use-latest-updater",
"# Whether to always use the latest updater instead of a specific known-good version\n",
*always_use_latest_updater,
);

apply_optional_value(
table,
"display",
Expand Down
22 changes: 18 additions & 4 deletions cargo-dist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,34 @@ fn run_build_step(
Ok(())
}

const AXOUPDATER_ASSET_ROOT: &str =
"https://github.com/axodotdev/axoupdater/releases/latest/download";
const AXOUPDATER_ASSET_ROOT: &str = "https://github.com/axodotdev/axoupdater/releases";
const AXOUPDATER_MINIMUM_VERSION: &str = "0.7.0";

fn axoupdater_latest_asset_root() -> String {
format!("{AXOUPDATER_ASSET_ROOT}/latest/download")
}

fn axoupdater_asset_root() -> String {
format!("{AXOUPDATER_ASSET_ROOT}/download/v{}", axoupdater::VERSION)
}

/// Fetches an installer executable and installs it in the expected target path.
pub fn fetch_updater(dist_graph: &DistGraph, updater: &UpdaterStep) -> DistResult<()> {
let ext = if updater.target_triple.is_windows() {
".zip"
} else {
".tar.xz"
};

let asset_root = if updater.use_latest {
axoupdater_latest_asset_root()
} else {
axoupdater_asset_root()
};

let expected_url = format!(
"{AXOUPDATER_ASSET_ROOT}/axoupdater-cli-{}{ext}",
updater.target_triple
"{}/axoupdater-cli-{}{ext}",
asset_root, updater.target_triple
);

let handle = tokio::runtime::Handle::current();
Expand Down
14 changes: 11 additions & 3 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ pub struct UpdaterStep {
pub target_triple: TripleName,
/// The file this should produce
pub target_filename: Utf8PathBuf,
/// Whether to use the latest release instead of a fixed version
pub use_latest: bool,
}

/// A kind of symbols (debuginfo)
Expand Down Expand Up @@ -802,7 +804,10 @@ pub struct ExtraArtifactImpl {

/// An updater executable
#[derive(Clone, Debug)]
pub struct UpdaterImpl {}
pub struct UpdaterImpl {
/// Whether to use the latest or a specific known-good version
pub use_latest: bool,
}

/// A file containing a Software Bill Of Materials
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -1811,7 +1816,9 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
file_path: target_path.to_owned(),
required_binaries: FastMap::new(),
archive: None,
kind: ArtifactKind::Updater(UpdaterImpl {}),
kind: ArtifactKind::Updater(UpdaterImpl {
use_latest: self.inner.config.installers.always_use_latest_updater,
}),
checksum: None,
is_global: false,
}
Expand Down Expand Up @@ -2739,11 +2746,12 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
ArtifactKind::ExtraArtifact(_) => {
// compute_extra_builds handles this
}
ArtifactKind::Updater(_) => {
ArtifactKind::Updater(UpdaterImpl { use_latest }) => {
build_steps.push(BuildStep::Updater(UpdaterStep {
// There should only be one triple per artifact
target_triple: artifact.target_triples.first().unwrap().to_owned(),
target_filename: artifact.file_path.to_owned(),
use_latest: *use_latest,
}))
}
ArtifactKind::SBOM(_) => {
Expand Down
1 change: 1 addition & 0 deletions cargo-dist/tests/integration-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ unix-archive = ".tar.gz"
windows-archive = ".tar.gz"
npm-scope ="@axodotdev"
install-updater = true
always-use-latest-updater = true

[package.metadata.wix]
upgrade-guid = "B36177BE-EA4D-44FB-B05C-EDDABDAA95CA"
Expand Down
Loading