Skip to content

Commit

Permalink
🚀 Version 6.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoverbruggen committed Nov 24, 2023
2 parents 8790b30 + da41673 commit ff61d8c
Show file tree
Hide file tree
Showing 20 changed files with 969 additions and 40 deletions.
27 changes: 15 additions & 12 deletions PHP Monitor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0336CAAF2B0D0CDA009A1034 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
03E36FE628D9219000636F7F /* ActiveShell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveShell.swift; sourceTree = "<group>"; };
5420395826135DC100FB00FA /* PreferencesVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesVC.swift; sourceTree = "<group>"; };
5420395E2613607600FB00FA /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2267,6 +2268,7 @@
de,
"pt-PT",
Base,
fr,
);
mainGroup = C41C1B2A22B0097F00E7CF16;
packageReferences = (
Expand Down Expand Up @@ -3247,6 +3249,7 @@
C4FC8D442A4981BC00FBBD16 /* nl */,
C4DD662A2A4A1B4E00D6A731 /* de */,
C4622F572A7593CB0016F8FB /* pt-PT */,
0336CAAF2B0D0CDA009A1034 /* fr */,
);
name = Localizable.strings;
sourceTree = "<group>";
Expand Down Expand Up @@ -3520,7 +3523,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1346;
CURRENT_PROJECT_VERSION = 1350;
DEAD_CODE_STRIPPING = YES;
DEBUG = YES;
DEVELOPMENT_TEAM = 8M54J5J787;
Expand All @@ -3533,7 +3536,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.4;
MARKETING_VERSION = 6.2.1;
MARKETING_VERSION = 6.2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -3551,7 +3554,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1346;
CURRENT_PROJECT_VERSION = 1350;
DEAD_CODE_STRIPPING = YES;
DEBUG = NO;
DEVELOPMENT_TEAM = 8M54J5J787;
Expand All @@ -3564,7 +3567,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.4;
MARKETING_VERSION = 6.2.1;
MARKETING_VERSION = 6.2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -3791,7 +3794,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1346;
CURRENT_PROJECT_VERSION = 1350;
DEAD_CODE_STRIPPING = YES;
DEBUG = NO;
DEVELOPMENT_TEAM = 8M54J5J787;
Expand All @@ -3804,7 +3807,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.4;
MARKETING_VERSION = 6.2.1;
MARKETING_VERSION = 6.2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.dev;
PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME) DEV";
Expand Down Expand Up @@ -3907,7 +3910,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1346;
CURRENT_PROJECT_VERSION = 1350;
DEAD_CODE_STRIPPING = YES;
DEBUG = YES;
DEVELOPMENT_TEAM = 8M54J5J787;
Expand All @@ -3920,7 +3923,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.4;
MARKETING_VERSION = 6.2.1;
MARKETING_VERSION = 6.2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.dev;
PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME) DEV";
Expand Down Expand Up @@ -4023,7 +4026,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1346;
CURRENT_PROJECT_VERSION = 1350;
DEAD_CODE_STRIPPING = YES;
DEBUG = YES;
DEVELOPMENT_TEAM = 8M54J5J787;
Expand All @@ -4036,7 +4039,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.4;
MARKETING_VERSION = 6.2.1;
MARKETING_VERSION = 6.2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap;
PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME) EAP";
Expand Down Expand Up @@ -4204,7 +4207,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1346;
CURRENT_PROJECT_VERSION = 1350;
DEAD_CODE_STRIPPING = YES;
DEBUG = NO;
DEVELOPMENT_TEAM = 8M54J5J787;
Expand All @@ -4217,7 +4220,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.4;
MARKETING_VERSION = 6.2.1;
MARKETING_VERSION = 6.2.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap;
PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME) EAP";
Expand Down
39 changes: 35 additions & 4 deletions phpmon/Common/PHP/PHP Version/PhpEnvironments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,36 @@ class PhpEnvironments {
/**
Determine which PHP version the `php` formula is aliased to.
*/
func determinePhpAlias() async {
@MainActor func determinePhpAlias() async {
let brewPhpAlias = await Shell.pipe("\(Paths.brew) info php --json").out

self.homebrewPackage = try! JSONDecoder().decode(
[HomebrewPackage].self,
from: brewPhpAlias.data(using: .utf8)!
).first!

Log.info("[BREW] On your system, the `php` formula means version \(homebrewPackage.version)!")
PhpEnvironments.brewPhpAlias = self.homebrewPackage.version
Log.info("[BREW] On your system, the `php` formula means version \(homebrewPackage.version).")

// Check if that version actually corresponds to an older version
let phpConfigExecutablePath = "\(Paths.optPath)/php/bin/php-config"
if FileSystem.fileExists(phpConfigExecutablePath) {
let longVersionString = Command.execute(
path: phpConfigExecutablePath,
arguments: ["--version"],
trimNewlines: false
).trimmingCharacters(in: .whitespacesAndNewlines)

if let version = try? VersionNumber.parse(longVersionString) {
PhpEnvironments.brewPhpAlias = version.short
if version.short != homebrewPackage.version {
Log.info("[BREW] An older version of `php` is actually installed (\(version.short)).")
}
} else {
Log.warn("Could not determine the actual version of the php binary; assuming Homebrew is correct.")
PhpEnvironments.brewPhpAlias = homebrewPackage.version
}
}
}

// MARK: - Properties
Expand Down Expand Up @@ -77,7 +98,12 @@ class PhpEnvironments {

As such, we take that information from Homebrew.
*/
static var brewPhpAlias: String {
static var brewPhpAlias: String = ""

/**
It's possible for the alias to be newer than the actual installed version of PHP.
*/
static var homebrewBrewPhpAlias: String {
if PhpEnvironments.shared.homebrewPackage == nil { return "8.2" }

return PhpEnvironments.shared.homebrewPackage.version
Expand Down Expand Up @@ -144,7 +170,12 @@ class PhpEnvironments {

// Avoid inserting a duplicate
if !supportedVersions.contains(phpAlias) && FileSystem.fileExists("\(Paths.optPath)/php/bin/php") {
supportedVersions.insert(phpAlias)
let phpAliasInstall = PhpInstallation(phpAlias)
// Before inserting, ensure that the actual output matches the alias
// if that isn't the case, our formula remains out-of-date
if !phpAliasInstall.missingBinary {
supportedVersions.insert(phpAlias)
}
}

availablePhpVersions = Array(supportedVersions)
Expand Down
6 changes: 6 additions & 0 deletions phpmon/Common/PHP/PhpInstallation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class PhpInstallation {

var versionNumber: VersionNumber

var missingBinary: Bool = false

var isHealthy: Bool = true

/**
Expand All @@ -35,6 +37,10 @@ class PhpInstallation {
// The parser should always work, or the string has to be very unusual.
// If so, the app SHOULD crash, so that the users report what's up.
self.versionNumber = try! VersionNumber.parse(longVersionString)
} else {
// Keep track that the `php-config` binary is missing; this often means there's a mismatch between
// the `php` version alias and the actual installed version (e.g. you haven't upgraded `php`)
missingBinary = true
}

if FileSystem.fileExists(phpExecutablePath) {
Expand Down
6 changes: 3 additions & 3 deletions phpmon/Common/Testables/TestableConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public struct TestableConfiguration: Codable {
: .fake(.binary),
"/opt/homebrew/Cellar/php/\(version.long)/bin/php-config"
: .fake(.binary),
"/opt/homebrew/etc/php/\(version.short)/php-fpm.d/www.conf"
: .fake(.text),
// "/opt/homebrew/etc/php/\(version.short)/php-fpm.d/www.conf"
// : .fake(.text),
"/opt/homebrew/etc/php/\(version.short)/php-fpm.d/valet-fpm.conf"
: .fake(.text),
"/opt/homebrew/etc/php/\(version.short)/php.ini"
Expand Down Expand Up @@ -94,7 +94,7 @@ public struct TestableConfiguration: Codable {
/opt/homebrew/etc/php/\(version.short)/conf.d/php-memory-limits.ini,
"""
} else {

self.shellOutput["sudo /opt/homebrew/bin/brew services stop php@\(version.short)"] = .instant("")
self.shellOutput["ls /opt/homebrew/opt | grep php@"] =
BatchFakeShellOutput.instant(
self.secondaryPhpVersions
Expand Down
4 changes: 2 additions & 2 deletions phpmon/Domain/Integrations/Homebrew/Brew.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class Brew {
/// Each formula for each PHP version that can be installed.
public static let phpVersionFormulae = [
"8.4": "shivammathur/php/[email protected]",
"8.3": "shivammathur/php/php@8.3", // TODO: when [email protected] lands in stable, update this
"8.3": "[email protected]",
"8.2": "[email protected]",
"8.1": "[email protected]",
"8.0": "[email protected]",
"8.0": "shivammathur/php/[email protected]",
"7.4": "shivammathur/php/[email protected]",
"7.3": "shivammathur/php/[email protected]",
"7.2": "shivammathur/php/[email protected]",
Expand Down
23 changes: 21 additions & 2 deletions phpmon/Domain/Integrations/Homebrew/BrewFormula.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

struct BrewFormula {
struct BrewFormula: Equatable {
/// Name of the formula.
let name: String

Expand Down Expand Up @@ -48,6 +48,25 @@ struct BrewFormula {
return upgradeVersion != nil
}

/// Whether this formula alias is different.
var hasUpgradedFormulaAlias: Bool {
return self.shortVersion == PhpEnvironments.homebrewBrewPhpAlias
&& PhpEnvironments.homebrewBrewPhpAlias != PhpEnvironments.brewPhpAlias
}

var unavailableAfterUpgrade: Bool {
if installedVersion == nil || upgradeVersion == nil {
return false
}

if let installed = try? VersionNumber.parse(self.installedVersion!),
let upgrade = try? VersionNumber.parse(self.upgradeVersion!) {
return upgrade.short != installed.short
}

return false
}

/// The associated Homebrew folder with this PHP formula.
var homebrewFolder: String {
let resolved = name
Expand All @@ -60,7 +79,7 @@ struct BrewFormula {
/// The short version associated with this formula, if installed.
var shortVersion: String? {
guard let version = self.installedVersion else {
return nil
return self.displayName.replacingOccurrences(of: "PHP ", with: "")
}

return VersionNumber.make(from: version)?.short ?? nil
Expand Down
8 changes: 6 additions & 2 deletions phpmon/Domain/Integrations/Homebrew/BrewFormulaeHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension HandlesBrewFormulae {
public func refreshPhpVersions(loadOutdated: Bool) async {
let items = await loadPhpVersions(loadOutdated: loadOutdated)
Task { @MainActor in
await PhpEnvironments.shared.determinePhpAlias()
Brew.shared.formulae.phpVersions = items
}
}
Expand All @@ -43,7 +44,8 @@ class BrewFormulaeHandler: HandlesBrewFormulae {
}

return Brew.phpVersionFormulae.map { (version, formula) in
let fullVersion = PhpEnvironments.shared.cachedPhpInstallations[version]?.versionNumber.text
let fullVersion = PhpEnvironments.shared.cachedPhpInstallations[version]?
.versionNumber.text

var upgradeVersion: String?

Expand All @@ -53,13 +55,15 @@ class BrewFormulaeHandler: HandlesBrewFormulae {
})?.current_version
}

return BrewFormula(
let formula = BrewFormula(
name: formula,
displayName: "PHP \(version)",
installedVersion: fullVersion,
upgradeVersion: upgradeVersion,
prerelease: Constants.ExperimentalPhpVersions.contains(version)
)

return formula
}.sorted { $0.displayName > $1.displayName }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,22 @@ class InstallAndUpgradeCommand: BrewCommand {
description: "PHP Monitor is preparing Homebrew..."
))

// Try to run all upgrade and installation operations
try await self.upgradePackages(onProgress)
try await self.installPackages(onProgress)
let unavailable = upgrading.first(where: { formula in
formula.unavailableAfterUpgrade
})

// Make sure the tap is installed
try await self.checkPhpTap(onProgress)

if unavailable == nil {
// Try to run all upgrade and installation operations
try await self.upgradePackages(onProgress)
try await self.installPackages(onProgress)
} else {
// Simply upgrade `php` to the latest version
try await self.upgradeMainPhpFormula(unavailable!, onProgress)
await PhpEnvironments.shared.determinePhpAlias()
}

// Re-check the installed versions
await PhpEnvironments.detectPhpVersions()
Expand All @@ -55,6 +68,39 @@ class InstallAndUpgradeCommand: BrewCommand {
await self.completedOperations(onProgress)
}

private func upgradeMainPhpFormula(
_ unavailable: BrewFormula,
_ onProgress: @escaping (BrewCommandProgress) -> Void
) async throws {
// Determine which version was previously available (that will become unavailable)
guard let short = try? VersionNumber
.parse(unavailable.installedVersion!).short else {
return
}

// Upgrade the main formula
let command = """
export HOMEBREW_NO_INSTALL_CLEANUP=true; \
\(Paths.brew) upgrade php;
\(Paths.brew) install php@\(short);
"""

// Run the upgrade command
try await run(command, onProgress)
}

private func checkPhpTap(_ onProgress: @escaping (BrewCommandProgress) -> Void) async throws {
if !BrewDiagnostics.installedTaps.contains("shivammathur/php") {
let command = "brew tap shivammathur/php"
try await run(command, onProgress)
}

if !BrewDiagnostics.installedTaps.contains("shivammathur/extensions") {
let command = "brew tap shivammathur/extensions"
try await run(command, onProgress)
}
}

private func upgradePackages(_ onProgress: @escaping (BrewCommandProgress) -> Void) async throws {
// If no upgrades are needed, early exit
if self.upgrading.isEmpty {
Expand Down
Loading

0 comments on commit ff61d8c

Please sign in to comment.