Skip to content

Commit

Permalink
tests: enable brew style in linters
Browse files Browse the repository at this point in the history
This adds a `brew style` linter to make sure that our generated Homebrew
formulas will pass Homebrew's `brew style` for users who have enabled Homebrew's
default CI setup for their taps. I've also ensured our snapshots contain the
auto-restyled copies after `brew style --fix` is run.

This required one stylistic change: the hashmap for binary aliases would
violate the line length lint, and unfortunately Rubocop's line length autoformatter
was consistently getting the formatting wrong. This instead (ab)uses the fact that
JSON hashmaps have a compatible syntax to Ruby 1.9+ hashmaps so long as symbols
are the keys - and we were already using symbolized keys. The resulting hashmap
is slightly strange-looking by Ruby standards, since symbolized keys usually aren't
quoted, but Rubocop isn't mad about it.
  • Loading branch information
mistydemeo committed Aug 21, 2024
1 parent a663e04 commit d8130cf
Show file tree
Hide file tree
Showing 38 changed files with 368 additions and 37 deletions.
2 changes: 1 addition & 1 deletion cargo-dist/templates/installer/homebrew.rb.j2
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class {{ formula_class }} < Formula
{%- endfor %}
{%- endif %}

BINARY_ALIASES = {{ inner.bin_aliases }}
BINARY_ALIASES = {{ inner.bin_aliases | tojson(indent=2) | indent(2) }}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
3 changes: 3 additions & 0 deletions cargo-dist/tests/gallery/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ impl DistResult {
// If we have shellcheck, check our shell script
app.shellcheck(ctx)?;

// If we have Homebrew, check our Homebrew installers
app.brew_style(ctx)?;

// If we have PsScriptAnalyzer, check our powershell script
app.psanalyzer(ctx)?;
}
Expand Down
48 changes: 48 additions & 0 deletions cargo-dist/tests/gallery/dist/homebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,52 @@ impl AppResult {
}
Ok(())
}

pub fn brew_style(&self, ctx: &TestContext<Tools>) -> Result<()> {
// only do this if the formula exists
let Some(formula_path) = &self.homebrew_installer_path else {
return Ok(());
};

// Only do this if Homebrew is installed
let Some(homebrew) = &ctx.tools.homebrew else {
return Ok(());
};

// Homebrew fails to guess that this is a formula
// file if it's not in a path named Formula,
// so we need to put the formula in a temp path
// to hint it correctly.
// (We could also skip individual lints via
// --except-cop on the `brew style` CLI, but that's
// a bit too much of a game of whack a mole.)
let temp_root = temp_dir::TempDir::new().unwrap();
let formula_temp_root = temp_root.path().join("Formula");
std::fs::create_dir(&formula_temp_root).unwrap();
let formula_temp_path = formula_temp_root.join(formula_path.file_name().unwrap());
std::fs::copy(formula_path, &formula_temp_path).unwrap();

let output = homebrew.output(|cmd| {
cmd.arg("style")
// This style nit is valid, but only shows up
// in the case no homepage was specified. It's
// expected that a user might see this one, and
// we don't want to fail ourselves on it.
// We add FormulaAuditStrict because that's the
// default exclusion, and adding anything to
// --except-cops overrides it.
.arg("--except-cops")
.arg("FormulaAudit/Homepage,FormulaAuditStrict")
// Applying --fix will ensure that fixable
// style issues won't be treated as errors.
.arg("--fix")
.arg(&formula_temp_path)
})?;

if !output.status.success() {
eprintln!("{}", String::from_utf8_lossy(&output.stdout));
return Err(miette!("brew style found issues"));
}
Ok(())
}
}
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/akaikatana_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ class AkaikatanaRepack < Formula
end
license "GPL-2.0-or-later"

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,28 @@ class AkaikatanaRepack < Formula
end
license "GPL-2.0-or-later"

BINARY_ALIASES = {"aarch64-apple-darwin": {"akextract": ["akextract-link"]}, "x86_64-apple-darwin": {"akextract": ["akextract-link"]}, "x86_64-pc-windows-gnu": {"akextract.exe": ["akextract-link.exe"]}, "x86_64-unknown-linux-gnu": {"akextract": ["akextract-link"]}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {
"akextract": [
"akextract-link"
]
},
"x86_64-apple-darwin": {
"akextract": [
"akextract-link"
]
},
"x86_64-pc-windows-gnu": {
"akextract.exe": [
"akextract-link.exe"
]
},
"x86_64-unknown-linux-gnu": {
"akextract": [
"akextract-link"
]
}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
35 changes: 34 additions & 1 deletion cargo-dist/tests/snapshots/akaikatana_two_bin_aliases.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,40 @@ class AkaikatanaRepack < Formula
end
license "GPL-2.0-or-later"

BINARY_ALIASES = {"aarch64-apple-darwin": {"akextract": ["akextract-link"], "akmetadata": ["akmetadata-link"]}, "x86_64-apple-darwin": {"akextract": ["akextract-link"], "akmetadata": ["akmetadata-link"]}, "x86_64-pc-windows-gnu": {"akextract.exe": ["akextract-link.exe"], "akmetadata.exe": ["akmetadata-link.exe"]}, "x86_64-unknown-linux-gnu": {"akextract": ["akextract-link"], "akmetadata": ["akmetadata-link"]}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {
"akextract": [
"akextract-link"
],
"akmetadata": [
"akmetadata-link"
]
},
"x86_64-apple-darwin": {
"akextract": [
"akextract-link"
],
"akmetadata": [
"akmetadata-link"
]
},
"x86_64-pc-windows-gnu": {
"akextract.exe": [
"akextract-link.exe"
],
"akmetadata.exe": [
"akmetadata-link.exe"
]
},
"x86_64-unknown-linux-gnu": {
"akextract": [
"akextract-link"
],
"akmetadata": [
"akmetadata-link"
]
}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/akaikatana_updaters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ class AkaikatanaRepack < Formula
end
license "GPL-2.0-or-later"

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_abyss.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
23 changes: 22 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_alias.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,28 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {"axolotlsay": ["axolotlsay-link"]}, "x86_64-apple-darwin": {"axolotlsay": ["axolotlsay-link"]}, "x86_64-pc-windows-gnu": {"axolotlsay.exe": ["axolotlsay-link.exe"]}, "x86_64-unknown-linux-gnu": {"axolotlsay": ["axolotlsay-link"]}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {
"axolotlsay": [
"axolotlsay-link"
]
},
"x86_64-apple-darwin": {
"axolotlsay": [
"axolotlsay-link"
]
},
"x86_64-pc-windows-gnu": {
"axolotlsay.exe": [
"axolotlsay-link.exe"
]
},
"x86_64-unknown-linux-gnu": {
"axolotlsay": [
"axolotlsay-link"
]
}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,32 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {"nosuchbin": ["axolotlsay-link1", "axolotlsay-link2"]}, "x86_64-apple-darwin": {"nosuchbin": ["axolotlsay-link1", "axolotlsay-link2"]}, "x86_64-pc-windows-gnu": {"nosuchbin.exe": ["axolotlsay-link1.exe", "axolotlsay-link2.exe"]}, "x86_64-unknown-linux-gnu": {"nosuchbin": ["axolotlsay-link1", "axolotlsay-link2"]}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {
"nosuchbin": [
"axolotlsay-link1",
"axolotlsay-link2"
]
},
"x86_64-apple-darwin": {
"nosuchbin": [
"axolotlsay-link1",
"axolotlsay-link2"
]
},
"x86_64-pc-windows-gnu": {
"nosuchbin.exe": [
"axolotlsay-link1.exe",
"axolotlsay-link2.exe"
]
},
"x86_64-unknown-linux-gnu": {
"nosuchbin": [
"axolotlsay-link1",
"axolotlsay-link2"
]
}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,12 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_build_setup_steps.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_custom_formula.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class AxolotlBrew < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
14 changes: 12 additions & 2 deletions cargo-dist/tests/snapshots/axolotlsay_generic_workspace_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,12 @@ class AxolotlsayJs < Formula
end
license "MIT-or-Apache2.0"

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down Expand Up @@ -2796,7 +2801,12 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
7 changes: 6 additions & 1 deletion cargo-dist/tests/snapshots/axolotlsay_homebrew_packages.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ class Axolotlsay < Formula
end
license any_of: ["MIT", "Apache-2.0"]

BINARY_ALIASES = {"aarch64-apple-darwin": {}, "x86_64-apple-darwin": {}, "x86_64-pc-windows-gnu": {}, "x86_64-unknown-linux-gnu": {}}
BINARY_ALIASES = {
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"x86_64-pc-windows-gnu": {},
"x86_64-unknown-linux-gnu": {}
}

def target_triple
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
Expand Down
Loading

0 comments on commit d8130cf

Please sign in to comment.