Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.9.7] - 2025-11-08

### Fixed
- Version numbers in formulas now strip "v" prefix for proper Homebrew compliance

## [0.9.6] - 2025-11-08

### Added
Expand Down
14 changes: 12 additions & 2 deletions Sources/NnexKit/Formula/FormulaContentGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ public enum FormulaContentGenerator {
assetURL: String,
sha256: String
) -> String {
let sanitizedVersion = sanitizeVersion(version)
return """
class \(FormulaNameSanitizer.sanitizeFormulaName(name)) < Formula
desc "\(details)"
homepage "\(homepage)"
url "\(assetURL)"
sha256 "\(sha256)"
version "\(version)"
version "\(sanitizedVersion)"
license "\(license)"

def install
Expand Down Expand Up @@ -50,11 +51,12 @@ public enum FormulaContentGenerator {
let hasIntel = (intelURL?.isEmpty == false) && (intelSHA256?.isEmpty == false)

if hasArm && hasIntel {
let sanitizedVersion = sanitizeVersion(version)
return """
class \(FormulaNameSanitizer.sanitizeFormulaName(name)) < Formula
desc "\(details)"
homepage "\(homepage)"
version "\(version)"
version "\(sanitizedVersion)"
license "\(license)"

on_macos do
Expand Down Expand Up @@ -111,3 +113,11 @@ public enum FormulaContentGenerator {
}
}
}


// MARK: - Private Methods
private extension FormulaContentGenerator {
static func sanitizeVersion(_ version: String) -> String {
version.hasPrefix("v") ? String(version.dropFirst()) : version
}
}
70 changes: 70 additions & 0 deletions Tests/NnexKitTests/FormulaContentGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,73 @@ extension FormulaContentGeneratorTests {
#expect(urlLine?.starts(with: " url") == true)
}
}


// MARK: - Version Sanitization Tests
extension FormulaContentGeneratorTests {
@Test("Strips v prefix from version in single binary formula")
func stripsVPrefixFromVersionInSingleBinary() {
let content = FormulaContentGenerator.makeFormulaFileContent(
name: testName,
details: testDetails,
homepage: testHomepage,
license: testLicense,
version: "v1.0.0",
assetURL: testAssetURL,
sha256: testSHA256
)

#expect(content.contains("version \"1.0.0\""))
#expect(!content.contains("version \"v1.0.0\""))
}

@Test("Strips v prefix from version in multi-arch formula")
func stripsVPrefixFromVersionInMultiArch() {
let content = FormulaContentGenerator.makeFormulaFileContent(
name: testName,
details: testDetails,
homepage: testHomepage,
license: testLicense,
version: "v2.5.3",
armURL: testArmURL,
armSHA256: testArmSHA256,
intelURL: testIntelURL,
intelSHA256: testIntelSHA256
)

#expect(content.contains("version \"2.5.3\""))
#expect(!content.contains("version \"v2.5.3\""))
}

@Test("Preserves version without v prefix in single binary formula")
func preservesVersionWithoutVPrefixInSingleBinary() {
let content = FormulaContentGenerator.makeFormulaFileContent(
name: testName,
details: testDetails,
homepage: testHomepage,
license: testLicense,
version: "3.0.0",
assetURL: testAssetURL,
sha256: testSHA256
)

#expect(content.contains("version \"3.0.0\""))
}

@Test("Preserves version without v prefix in multi-arch formula")
func preservesVersionWithoutVPrefixInMultiArch() {
let content = FormulaContentGenerator.makeFormulaFileContent(
name: testName,
details: testDetails,
homepage: testHomepage,
license: testLicense,
version: "4.2.1",
armURL: testArmURL,
armSHA256: testArmSHA256,
intelURL: testIntelURL,
intelSHA256: testIntelSHA256
)

#expect(content.contains("version \"4.2.1\""))
}
}