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

Package specific releases #652

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions src/config/components/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum ArtifactSystem {
pub struct ArtifactsConfig {
pub auto: bool,
pub cargo_dist: bool,
pub package_specific_releases: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is a good addition, I would change the name, maybe to match_package_names (seems more immediately obvious to me what it does that way). Also adding it to the docs reference page would be nice, but no worries, I can also do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about the naming either, I'll get those updates made a bit later today. Thanks for the quick response!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed these changes, also added a doc entry but feel free to tweaks as needed!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually ill fix that clippy

pub package_managers: PackageManagersConfig,
pub hidden: Vec<String>,
}
Expand Down Expand Up @@ -83,6 +84,13 @@ pub struct ArtifactsLayer {
///
/// We default this to true if we find `[workspace.metadata.dist]` in your Cargo.toml
pub cargo_dist: Option<bool>,
/// Whether to only show releases that contain the project name in their tag name
///
/// This is useful if you have multiple projects in the same repo and want to only
/// show releases for that specific project on the generated project page.
///
/// This defaults to false.
pub package_specific_releases: Option<bool>,
/// Snippets saying how to install your project using various package-managers
///
/// These are grouped into "preferred" and "additional"
Expand Down Expand Up @@ -130,6 +138,7 @@ impl Default for ArtifactsConfig {
ArtifactsConfig {
auto: false,
cargo_dist: false,
package_specific_releases: false,
package_managers: PackageManagersConfig::default(),
hidden: vec![],
}
Expand All @@ -142,12 +151,15 @@ impl ApplyLayer for ArtifactsConfig {
let ArtifactsLayer {
auto,
cargo_dist,
package_specific_releases,
package_managers,
hidden,
} = layer;

self.auto.apply_val(auto);
self.cargo_dist.apply_val(cargo_dist);
self.package_specific_releases
.apply_val(package_specific_releases);
self.package_managers.apply_val_layer(package_managers);
// In the future this might want to be `extend`
self.hidden.apply_val(hidden);
Expand Down
26 changes: 24 additions & 2 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ impl Context {
project_config,
artifacts_config,
))?;
Ok(Self::with_releases(None, releases, artifacts_config))
Ok(Self::with_releases(
None,
releases,
artifacts_config,
project_config,
))
}
/// Get releases using github
pub fn new_github(
Expand All @@ -63,7 +68,12 @@ impl Context {
artifacts_config,
))?;
}
Ok(Self::with_releases(Some(repo), releases, artifacts_config))
Ok(Self::with_releases(
Some(repo),
releases,
artifacts_config,
project_config,
))
}

/// Get the latest release, if it exists
Expand Down Expand Up @@ -100,6 +110,7 @@ impl Context {
repo: Option<GithubRepo>,
releases: Vec<Release>,
artifacts_config: Option<&ArtifactsConfig>,
project_config: &ProjectConfig,
) -> Self {
// Walk through all the releases (from newest to oldest) to find the latest ones
//
Expand All @@ -116,6 +127,17 @@ impl Context {
let mut latest_prerelease = None;

for (idx, release) in releases.iter().enumerate() {
// If we're using package-specific releases, we want to skip any releases
// which tag name doesn't contain the project name
if artifacts_config
.map(|a| a.package_specific_releases)
.unwrap_or(false)
{
if !release.source.version_tag().contains(&project_config.name) {
continue;
}
}

// Make note of whether anything has artifacts
if release.has_installers() {
has_artifacts = true;
Expand Down