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(tag-namespace): add tag-namespace config #779

Merged
merged 2 commits into from
Feb 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
9 changes: 9 additions & 0 deletions book/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,15 @@ The syntax must be a valid rustup toolchain like "1.60.0" or "stable" (should no
If you delete the key, generate won't explicitly setup a toolchain, so whatever's on the machine will be used (with things like rust-toolchain.toml behaving as normal). Before being deprecated the default was to `rustup update stable`, but this is no longer the case.


### tag-namespace

> since 0.10.0

Example: `tag-namespace = "some-prefix"`

Setting `tag-name = "owo"` will change the tag matching expression we put in your github ci, to require the tag to start with "owo" for cargo-dist to care about it. This can be useful for situations where you have several things with different tag/release workflows in the same workspace. It also renames `release.yaml` to `owo-release.yml` to make it clear it's just one of many release workflows.


### tap

> since 0.2.0
Expand Down
13 changes: 12 additions & 1 deletion cargo-dist/src/backend/ci/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub struct GithubCiInfo {
pub ssldotcom_windows_sign: Option<ProductionMode>,
/// what hosting provider we're using
pub hosting_providers: Vec<HostingStyle>,
/// whether to prefix release.yml and the tag pattern
pub tag_namespace: Option<String>,
}

impl GithubCiInfo {
Expand All @@ -81,6 +83,7 @@ impl GithubCiInfo {
let dispatch_releases = dist.dispatch_releases;
let create_release = dist.create_release;
let ssldotcom_windows_sign = dist.ssldotcom_windows_sign.clone();
let tag_namespace = dist.tag_namespace.clone();
let mut dependencies = SystemDependencies::default();

// Figure out what builds we need to do
Expand Down Expand Up @@ -153,6 +156,7 @@ impl GithubCiInfo {
}

GithubCiInfo {
tag_namespace,
rust_version,
install_dist_sh,
install_dist_ps1,
Expand All @@ -178,7 +182,14 @@ impl GithubCiInfo {

fn github_ci_path(&self, dist: &DistGraph) -> camino::Utf8PathBuf {
let ci_dir = dist.workspace_dir.join(GITHUB_CI_DIR);
ci_dir.join(GITHUB_CI_FILE)
// If tag-namespace is set, apply the prefix to the filename to emphasize it's
// just one of many workflows in this project
let prefix = self
.tag_namespace
.as_deref()
.map(|p| format!("{p}-"))
.unwrap_or_default();
ci_dir.join(format!("{prefix}{GITHUB_CI_FILE}"))
}

/// Generate the requested configuration and returns it as a string.
Expand Down
10 changes: 10 additions & 0 deletions cargo-dist/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ pub struct DistMetadata {
/// Custom GitHub runners, mapped by triple target
#[serde(skip_serializing_if = "Option::is_none")]
pub github_custom_runners: Option<HashMap<String, String>>,

/// a prefix to add to the release.yml and tag pattern so that
/// cargo-dist can co-exist with other release workflows in complex workspaces
#[serde(skip_serializing_if = "Option::is_none")]
pub tag_namespace: Option<String>,
}

impl DistMetadata {
Expand Down Expand Up @@ -371,6 +376,7 @@ impl DistMetadata {
hosting: _,
extra_artifacts: _,
github_custom_runners: _,
tag_namespace: _,
} = self;
if let Some(include) = include {
for include in include {
Expand Down Expand Up @@ -425,6 +431,7 @@ impl DistMetadata {
hosting,
extra_artifacts,
github_custom_runners,
tag_namespace,
} = self;

// Check for global settings on local packages
Expand Down Expand Up @@ -493,6 +500,9 @@ impl DistMetadata {
if post_announce_jobs.is_some() {
warn!("package.metadata.dist.post-announce-jobs is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if tag_namespace.is_some() {
warn!("package.metadata.dist.tag-namespace is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}

// Merge non-global settings
if installers.is_none() {
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 @@ -262,6 +262,7 @@ fn get_new_dist_metadata(
hosting: None,
extra_artifacts: None,
github_custom_runners: None,
tag_namespace: None,
}
};

Expand Down Expand Up @@ -792,6 +793,7 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
ssldotcom_windows_sign,
msvc_crt_static,
hosting,
tag_namespace,
extra_artifacts: _,
github_custom_runners: _,
} = &meta;
Expand Down Expand Up @@ -1036,6 +1038,13 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
hosting.as_ref(),
);

apply_optional_value(
table,
"tag-namespace",
"# A prefix git tags must include for cargo-dist to care about them\n",
tag_namespace.as_ref(),
);

// Finalize the table
table
.decor_mut()
Expand Down
5 changes: 5 additions & 0 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ pub struct DistGraph {
pub github_custom_runners: HashMap<String, String>,
/// LIES ALL LIES
pub local_builds_are_lies: bool,
/// Prefix git tags must include to be picked up (also renames release.yml)
pub tag_namespace: Option<String>,
}

/// Info about artifacts should be hosted
Expand Down Expand Up @@ -713,6 +715,7 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
build_local_artifacts,
dispatch_releases,
ssldotcom_windows_sign,
tag_namespace,
// Partially Processed elsewhere
//
// FIXME?: this is the last vestige of us actually needing to keep workspace_metadata
Expand Down Expand Up @@ -785,6 +788,7 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
let msvc_crt_static = msvc_crt_static.unwrap_or(true);
let local_builds_are_lies = artifact_mode == ArtifactMode::Lies;
let ssldotcom_windows_sign = ssldotcom_windows_sign.clone();
let tag_namespace = tag_namespace.clone();

let mut packages_with_mismatched_features = vec![];
// Compute/merge package configs
Expand Down Expand Up @@ -944,6 +948,7 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
ssldotcom_windows_sign,
desired_cargo_dist_version,
desired_rust_toolchain,
tag_namespace,
tools,
local_builds_are_lies,
templates,
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/templates/ci/github_ci.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ on:
{{%- else %}}
push:
tags:
- '**[0-9]+.[0-9]+.[0-9]+*'
- '{{%- if tag_namespace %}}{{{ tag_namespace | safe }}}{{%- endif %}}**[0-9]+.[0-9]+.[0-9]+*'
{{%- endif %}}
{{%- if pr_run_mode != "skip" %}}
pull_request:
Expand Down
18 changes: 16 additions & 2 deletions cargo-dist/tests/gallery/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,17 @@ impl<'a> TestContext<'a, Tools> {
}
/// Run 'cargo dist generate' and return paths to various files that were generated
pub fn cargo_dist_generate(&self, test_name: &str) -> Result<GenerateResult> {
let github_ci_path = Utf8Path::new(".github/workflows/release.yml").to_owned();
self.cargo_dist_generate_prefixed(test_name, "")
}
/// Run 'cargo dist generate' and return paths to various files that were generated
/// (also apply a prefix to the github filename)
pub fn cargo_dist_generate_prefixed(
&self,
test_name: &str,
prefix: &str,
) -> Result<GenerateResult> {
let ci_file_name = format!("{prefix}release.yml");
let github_ci_path = Utf8Path::new(".github/workflows/").join(ci_file_name);
let wxs_path = Utf8Path::new("wix/main.wxs").to_owned();
// Delete files if they already exist
if github_ci_path.exists() {
Expand Down Expand Up @@ -582,9 +592,13 @@ impl GenerateResult {
// in one test (necessitating rerunning it multiple times or passing special flags to get all the changes)
let mut snapshots = String::new();

eprintln!("{:?}", self.github_ci_path);
append_snapshot_file(
&mut snapshots,
"github-ci.yml",
self.github_ci_path
.as_deref()
.and_then(|p| p.file_name())
.unwrap_or_default(),
self.github_ci_path.as_deref(),
)?;

Expand Down
29 changes: 28 additions & 1 deletion cargo-dist/tests/integration-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,34 @@ dispatch-releases = true
// Run generate to make sure stuff is up to date before running other commands
let ci_result = ctx.cargo_dist_generate(test_name)?;
let ci_snap = ci_result.check_all()?;
//rr Do usual build+plan checks
// Do usual build+plan checks
let main_result = ctx.cargo_dist_build_and_plan(test_name)?;
let main_snap = main_result.check_all(ctx, ".cargo/bin/")?;
// snapshot all
main_snap.join(ci_snap).snap();
Ok(())
})
}

#[test]
fn axolotlsay_tag_namespace() -> Result<(), miette::Report> {
let test_name = _function_name!();
AXOLOTLSAY.run_test(|ctx| {
let dist_version = ctx.tools.cargo_dist.version().unwrap();
ctx.patch_cargo_toml(format!(r#"
[workspace.metadata.dist]
cargo-dist-version = "{dist_version}"
installers = []
targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "aarch64-apple-darwin"]
ci = ["github"]
tag-namespace = "owo"
"#
))?;

// Run generate to make sure stuff is up to date before running other commands
let ci_result = ctx.cargo_dist_generate_prefixed(test_name, "owo-")?;
let ci_snap = ci_result.check_all()?;
// Do usual build+plan checks
let main_result = ctx.cargo_dist_build_and_plan(test_name)?;
let main_snap = main_result.check_all(ctx, ".cargo/bin/")?;
// snapshot all
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/akaikatana_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ try {
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/akaikatana_musl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ download_binary_and_run_installer "$@" || exit 1
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ try {
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/axolotlsay_abyss.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ maybeInstall(true).then(run);
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ maybeInstall(true).then(run);
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/axolotlsay_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ maybeInstall(true).then(run);
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ expression: self.payload
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/axolotlsay_dispatch.snap
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ expression: self.payload
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/axolotlsay_dispatch_abyss.snap
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ expression: self.payload
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ expression: self.payload
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ maybeInstall(true).then(run);
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/axolotlsay_musl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1988,7 +1988,7 @@ maybeInstall(true).then(run);
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ maybeInstall(true).then(run);
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ maybeInstall(true).then(run);
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/tests/snapshots/axolotlsay_no_locals.snap
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ expression: self.payload
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ expression: self.payload
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ try {
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ try {
"linkage": []
}

================ github-ci.yml ================
================ release.yml ================
# Copyright 2022-2023, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
Expand Down
Loading