Skip to content

Commit

Permalink
Merge pull request #1509 from axodotdev/cargo-dist-url-override
Browse files Browse the repository at this point in the history
Add a `dist_url_override` config key
  • Loading branch information
fasterthanlime authored Nov 6, 2024
2 parents 6d2e441 + f8e0688 commit f53dd6d
Show file tree
Hide file tree
Showing 69 changed files with 4,734 additions and 800 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
# we specify bash to get pipefail; it guards against the `curl` command
# failing. otherwise `sh` won't catch that `curl` returned non-0
shell: bash
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.24.0-prerelease.2/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.24.1/cargo-dist-installer.sh | sh"
- name: Cache dist
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -122,7 +122,8 @@ jobs:
with:
submodules: recursive
- name: Install dist
run: ${{ matrix.install_dist }}
shell: ${{ matrix.install_dist.shell }}
run: ${{ matrix.install_dist.run }}
# Get the dist-manifest
- name: Fetch local artifacts
uses: actions/download-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

43 changes: 38 additions & 5 deletions cargo-dist-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ pub struct GithubMatrixEntry {
#[serde(skip_serializing_if = "Option::is_none")]
pub runner: Option<GithubRunner>,
/// Expression to execute to install dist
#[serde(skip_serializing_if = "Option::is_none")]
pub install_dist: Option<String>,
pub install_dist: GhaRunStep,
/// Expression to execute to install cargo-auditable
pub install_cargo_auditable: GhaRunStep,
/// Arguments to pass to dist
#[serde(skip_serializing_if = "Option::is_none")]
pub dist_args: Option<String>,
Expand All @@ -317,9 +318,41 @@ pub struct GithubMatrixEntry {
/// what cache provider to use
#[serde(skip_serializing_if = "Option::is_none")]
pub cache_provider: Option<String>,
/// Expression to execute to install cargo-auditable
#[serde(skip_serializing_if = "Option::is_none")]
pub install_cargo_auditable: Option<String>,
}

/// A GitHub Actions "run" step, either bash or powershell
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
// this mirrors GHA's structure, see
// * <https://serde.rs/enum-representations.html>
// * <https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell>
#[serde(tag = "shell", content = "run")]
pub enum GhaRunStep {
/// see [`DashScript`]
#[serde(rename = "sh")]
Dash(DashScript),
/// see [`PowershellScript`]
#[serde(rename = "pwsh")]
Powershell(PowershellScript),
}

impl From<DashScript> for GhaRunStep {
fn from(bash: DashScript) -> Self {
Self::Dash(bash)
}
}

impl From<PowershellScript> for GhaRunStep {
fn from(powershell: PowershellScript) -> Self {
Self::Powershell(powershell)
}
}

declare_strongly_typed_string! {
/// A bit of shell script (that can run with `/bin/sh`), ran on CI runners. Can be multi-line.
pub struct DashScript => &DashScriptRef;

/// A bit of powershell script, ran on CI runners. Can be multi-line.
pub struct PowershellScript => &PowershellScriptRef;
}

/// Type of job to run on pull request
Expand Down
61 changes: 55 additions & 6 deletions cargo-dist-schema/src/snapshots/cargo_dist_schema__emit.snap

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

1 change: 1 addition & 0 deletions cargo-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ lazy_static.workspace = true
current_platform.workspace = true
color-backtrace.workspace = true
backtrace.workspace = true
schemars.workspace = true

[dev-dependencies]
insta.workspace = true
Expand Down
74 changes: 28 additions & 46 deletions cargo-dist/src/backend/ci/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use axoasset::{LocalAsset, SourceFile};
use axoprocess::Cmd;
use camino::{Utf8Path, Utf8PathBuf};
use cargo_dist_schema::{
GithubMatrix, GithubMatrixEntry, GithubRunner, GithubRunnerRef, TargetTriple, TargetTripleRef,
GhaRunStep, GithubMatrix, GithubMatrixEntry, GithubRunner, GithubRunnerRef, TargetTriple,
TargetTripleRef,
};
use serde::{Deserialize, Serialize};
use tracing::warn;
Expand All @@ -24,28 +25,30 @@ use crate::{
DistError, DistGraph, SortedMap, SortedSet,
};

use super::{
CargoAuditableInstallStrategy, DistInstallSettings, DistInstallStrategy, InstallStrategy,
};

#[cfg(not(windows))]
const GITHUB_CI_DIR: &str = ".github/workflows/";
#[cfg(windows)]
const GITHUB_CI_DIR: &str = r".github\workflows\";
const GITHUB_CI_FILE: &str = "release.yml";

/// Info about running dist in Github CI
///
/// THESE FIELDS ARE LOAD-BEARING because they're used in the templates.
#[derive(Debug, Serialize)]
pub struct GithubCiInfo {
/// Cached path to github CI workflows dir
#[serde(skip_serializing)]
pub github_ci_workflow_dir: Utf8PathBuf,
/// Version of rust toolchain to install (deprecated)
pub rust_version: Option<String>,
/// expression to use for installing dist via shell script
pub install_dist_sh: String,
/// expression to use for installing dist via powershell script
pub install_dist_ps1: String,
/// expression to use for installing cargo-auditable via shell script
pub install_cargo_auditable_sh: String,
/// expression to use for installing cargo-auditable via powershell script
pub install_cargo_auditable_ps1: String,
/// How to install dist when "coordinating" (plan, global build, etc.)
pub dist_install_for_coordinator: GhaRunStep,
/// Our install strategy for dist itself
pub dist_install_strategy: DistInstallStrategy,
/// Whether to fail-fast
pub fail_fast: bool,
/// Whether to cache builds
Expand Down Expand Up @@ -223,11 +226,13 @@ impl GithubCiInfo {
dependencies.append(&mut release.config.builds.system_dependencies.clone());
}

// Get the platform-specific installation methods
let install_dist_sh = super::install_dist_sh_for_version(dist_version);
let install_dist_ps1 = super::install_dist_ps1_for_version(dist_version);
let install_cargo_auditable_sh = super::install_cargo_auditable_sh_latest();
let install_cargo_auditable_ps1 = super::install_cargo_auditable_ps1_latest();
let dist_install_strategy = (DistInstallSettings {
version: dist_version,
url_override: dist.config.dist_url_override.as_deref(),
})
.install_strategy();
let cargo_auditable_install_strategy = CargoAuditableInstallStrategy;

let hosting_providers = dist
.hosting
.as_ref()
Expand Down Expand Up @@ -255,8 +260,8 @@ impl GithubCiInfo {
cache_provider: cache_provider_for_runner(global_runner),
runner: Some(global_runner.to_owned()),
dist_args: Some("--artifacts=global".into()),
install_dist: Some(install_dist_sh.clone()),
install_cargo_auditable: Some(install_cargo_auditable_sh.clone()),
install_dist: dist_install_strategy.dash(),
install_cargo_auditable: cargo_auditable_install_strategy.dash(),
packages_install: None,
};

Expand Down Expand Up @@ -311,13 +316,9 @@ impl GithubCiInfo {
};
for (runner, targets) in local_runs {
use std::fmt::Write;
let install_dist =
install_package_for_targets(&targets, &install_dist_sh, &install_dist_ps1);
let install_cargo_auditable = install_package_for_targets(
&targets,
&install_cargo_auditable_sh,
&install_cargo_auditable_ps1,
);
let install_dist = dist_install_strategy.for_targets(&targets);
let install_cargo_auditable = cargo_auditable_install_strategy.for_targets(&targets);

let mut dist_args = String::from("--artifacts=local");
for target in &targets {
write!(dist_args, " --target={target}").unwrap();
Expand All @@ -327,8 +328,8 @@ impl GithubCiInfo {
cache_provider: cache_provider_for_runner(&runner),
runner: Some(runner),
dist_args: Some(dist_args),
install_dist: Some(install_dist.to_owned()),
install_cargo_auditable: Some(install_cargo_auditable.to_owned()),
install_dist: install_dist.to_owned(),
install_cargo_auditable: install_cargo_auditable.to_owned(),
packages_install: package_install_for_targets(&targets, &dependencies),
});
}
Expand All @@ -351,10 +352,8 @@ impl GithubCiInfo {
github_ci_workflow_dir,
tag_namespace,
rust_version,
install_dist_sh,
install_dist_ps1,
install_cargo_auditable_sh,
install_cargo_auditable_ps1,
dist_install_for_coordinator: dist_install_strategy.dash(),
dist_install_strategy,
fail_fast,
cache_builds,
build_local_artifacts,
Expand Down Expand Up @@ -638,23 +637,6 @@ fn github_runner_for_target(
}
}

/// Select the (dist-produced) installer approach for a given Github Runner
fn install_package_for_targets<'a>(
targets: &'a [&'a TargetTripleRef],
install_sh: &'a str,
install_ps1: &'a str,
) -> &'a str {
for target in targets {
if target.is_linux() || target.is_apple() {
return install_sh;
} else if target.is_windows() {
return install_ps1;
}
}

unreachable!("internal error: unknown target triple!?")
}

fn brewfile_from(packages: &[String]) -> String {
let brewfile_lines: Vec<String> = packages
.iter()
Expand Down
Loading

0 comments on commit f53dd6d

Please sign in to comment.