Skip to content

Commit

Permalink
Merge pull request #527 from Gankra/art-true
Browse files Browse the repository at this point in the history
feat(auto-config): make artifact autodetect configurable
  • Loading branch information
ashleygwilliams authored Jul 14, 2023
2 parents 877c450 + 307b92b commit 1678d4d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
33 changes: 32 additions & 1 deletion src/config/components/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum ArtifactSystem {
/// Info about downloadable artifacts / installers / package-managers (complete version)
#[derive(Debug)]
pub struct ArtifactsConfig {
pub auto: bool,
pub cargo_dist: bool,
pub package_managers: PackageManagersConfig,
pub hidden: Vec<String>,
Expand All @@ -44,6 +45,32 @@ pub struct ArtifactsConfig {
/// Setting for downloadable artifacts, installers, and package-managers
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct ArtifactsLayer {
/// Whether to enable auto-detection of artifacts/installers in your Github Releases
///
/// This allows us to look at the assets listed in a Github Release and use their
/// names to guess their platforms and what they're for.
///
/// If `cargo_dist` is also enabled, that data source will be preferred over this one
/// for the assets that cargo-dist knows about, as it should presumably be more reliable.
///
/// Artifact auto-detection currently includes the following concepts:
///
/// * **platforms**: if an artifact name contains a [rust target triple][triple] then we will
/// assume it's specific to that platform. Otherwise we will infer platform using extension
/// (with rules like "ps1 scripts are for windows, sh scripts are for unix").
/// * **archives**: if a platform-specific artifact name ends with an archive format
/// (.tar.*, .zip .7z, .rar...) then we will assume it contains the binaries
/// for that platform and recommend its download accordingly.
/// * **scripts**: if an artifact name contains "install" and ends with ".sh" or ".ps1"
/// we will assume it's an install script and generate an appropriate `curl | sh` for
/// it (`irm | iex` for ps1)
/// * **bundles**: if an artifact name ends with a known format for some kind of
/// installer/bundle we will recommend its download at a higher priority, assuming
/// this is a very good way to install your app. This includes ".msi", ".app", ".dmg",
/// ".deb", ".rpm", ".pkg.tar.*", ".flatpak", and ".snap".
///
/// [triple]: https://doc.rust-lang.org/nightly/rustc/platform-support.html
pub auto: Option<bool>,
/// Whether to enable cargo-dist integration
///
/// If enabled, we will check every GitHub Release of your project for a dist-manifest.json
Expand Down Expand Up @@ -100,6 +127,7 @@ pub struct ArtifactsLayer {
impl Default for ArtifactsConfig {
fn default() -> Self {
ArtifactsConfig {
auto: false,
cargo_dist: false,
package_managers: PackageManagersConfig::default(),
hidden: vec![],
Expand All @@ -111,10 +139,13 @@ impl ApplyLayer for ArtifactsConfig {
fn apply_layer(&mut self, layer: Self::Layer) {
// This is intentionally written slightly cumbersome to make you update this
let ArtifactsLayer {
auto,
cargo_dist,
package_managers,
hidden,
} = layer;

self.auto.apply_val(auto);
self.cargo_dist.apply_val(cargo_dist);
self.package_managers.apply_val_layer(package_managers);
// In the future this might want to be `extend`
Expand All @@ -124,6 +155,6 @@ impl ApplyLayer for ArtifactsConfig {

impl ArtifactsConfig {
pub fn has_some(&self) -> bool {
self.cargo_dist || !self.package_managers.is_empty()
self.cargo_dist || self.auto || !self.package_managers.is_empty()
}
}
11 changes: 4 additions & 7 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,16 @@ where
if let Some(this) = self {
this.apply_layer(val);
} else {
// If self is None, then
// If self is None, then a previous layer completely disabled this.
// For now we respect that and drop this request completely.
}
}
Some(BoolOr::Bool(false)) => {
// Disable this setting
*self = None;
}
None | Some(BoolOr::Bool(true)) => {
// Do nothing, use the previous value
//
// (Arguably "true" should mean something like Some(default)
// but that's already the default and we don't want to clobber
// other layers if they have an opinion.)
Some(BoolOr::Bool(true)) | None => {
// Do nothing, no opinion
}
}
}
Expand Down

0 comments on commit 1678d4d

Please sign in to comment.