Skip to content

Commit

Permalink
Fix CLI archiving and distribution (#260)
Browse files Browse the repository at this point in the history
The new automation pipeline uses ZIP Foundation to create archives of
the build products. Unfortunately, ZIP Foundation produces malformed
CRCs for the mockingbird binary executable (see
weichsel/ZIPFoundation#229). This change replaces ZIP Foundation with
the Unix zip command and fixes how the Mockingbird.zip archive is
inflated by the CLI launcher.
  • Loading branch information
andrewchang-bird authored Jan 10, 2022
1 parent 4269d57 commit ab0de2c
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Mockingbird.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
28719AF126B21CB100C38C2C /* MKBProperty.m in Sources */ = {isa = PBXBuildFile; fileRef = 28719AEF26B21CB100C38C2C /* MKBProperty.m */; };
28719AF326B22D1300C38C2C /* Stubbing+ObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28719AF226B22D1300C38C2C /* Stubbing+ObjC.swift */; };
28719AF526B23AB200C38C2C /* ObjectiveCTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28719AF426B23AB200C38C2C /* ObjectiveCTests.swift */; };
2873D49A27896DE7004523BC /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2873D49927896DE7004523BC /* Zip.swift */; };
287BB9CB26AE1578004014CA /* Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 287BB9CA26AE1577004014CA /* Mock.swift */; };
287BB9CD26AE15F0004014CA /* InvocationForwarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 287BB9CC26AE15F0004014CA /* InvocationForwarding.swift */; };
287C4F3B26A3547000A7E0D9 /* MKBClassMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 287C4F3926A3547000A7E0D9 /* MKBClassMock.h */; };
Expand Down Expand Up @@ -622,6 +623,7 @@
28719AEF26B21CB100C38C2C /* MKBProperty.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MKBProperty.m; sourceTree = "<group>"; };
28719AF226B22D1300C38C2C /* Stubbing+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stubbing+ObjC.swift"; sourceTree = "<group>"; };
28719AF426B23AB200C38C2C /* ObjectiveCTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectiveCTests.swift; sourceTree = "<group>"; };
2873D49927896DE7004523BC /* Zip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Zip.swift; sourceTree = "<group>"; };
287BB9CA26AE1577004014CA /* Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mock.swift; sourceTree = "<group>"; };
287BB9CC26AE15F0004014CA /* InvocationForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvocationForwarding.swift; sourceTree = "<group>"; };
287C4F3926A3547000A7E0D9 /* MKBClassMock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MKBClassMock.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1179,6 +1181,7 @@
285C8E16277AD76300DE525A /* SwiftPackage.swift */,
285C8E06277A7F9000DE525A /* XcodeBuild.swift */,
285C8E8B277C670300DE525A /* XcodeSelect.swift */,
2873D49927896DE7004523BC /* Zip.swift */,
);
path = Interop;
sourceTree = "<group>";
Expand Down Expand Up @@ -2440,6 +2443,7 @@
286DE653277EB78C0047B0F3 /* XcodeBuild.swift in Sources */,
286DE654277EB78C0047B0F3 /* XcodeSelect.swift in Sources */,
286DE655277EB7940047B0F3 /* FileManager+PosixPermissions.swift in Sources */,
2873D49A27896DE7004523BC /* Zip.swift in Sources */,
286DE656277EB7940047B0F3 /* Logging.swift in Sources */,
286DE657277EB7940047B0F3 /* Subprocess.swift in Sources */,
);
Expand Down
2 changes: 1 addition & 1 deletion MockingbirdFramework.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
'README.md',
'LICENSE.md',
'mockingbird',
'Scripts/Resources/CodesigningRequirements/*',
'Sources/MockingbirdAutomationCli/Resources/CodesigningRequirements/*',
'Sources/MockingbirdFramework/Info.plist',
]

Expand Down
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ if ProcessInfo.processInfo.environment["MKB_BUILD_EXECUTABLES"] != "1" {
"MockingbirdAutomation",
"MockingbirdCommon",
"PathKit",
"ZIPFoundation",
]),
.target(
name: "MockingbirdAutomation",
Expand Down
13 changes: 13 additions & 0 deletions Sources/MockingbirdAutomation/Interop/Zip.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation
import PathKit

public enum Zip {
public static func deflate(input: Path, output: Path) throws {
try Subprocess("zip", [
"-r", // Recursive
"-X", // No extra file attributes e.g. '_MACOSX'
output.absolute().string,
input.lastComponent,
], workingDirectory: input.parent()).run()
}
}
7 changes: 2 additions & 5 deletions Sources/MockingbirdAutomationCli/Commands/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ArgumentParser
import Foundation
import MockingbirdAutomation
import PathKit
import ZIPFoundation

struct Build: ParsableCommand {
static var configuration = CommandConfiguration(
Expand Down Expand Up @@ -49,10 +48,8 @@ struct Build: ParsableCommand {

try? destination.delete()
try destination.parent().mkpath()
try FileManager().zipItem(at: stagingPath.url,
to: destination.url,
shouldKeepParent: items.count > 1,
compressionMethod: .deflate)
try Zip.deflate(input: items.count == 1 ? items[0].path : stagingPath,
output: destination)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/MockingbirdAutomationCli/Commands/BuildCli.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension Build {

@Option(help: "File path containing the designated requirement for codesigning.")
var requirements: String =
"./Sources/MockingbirdAutomation/Resources/CodesigningRequirements/mockingbird.txt"
"./Sources/MockingbirdAutomationCli/Resources/CodesigningRequirements/mockingbird.txt"

@OptionGroup()
var globalOptions: Options
Expand Down
2 changes: 1 addition & 1 deletion Sources/MockingbirdAutomationCli/Commands/Configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Configure: ParsableCommand {
])

enum Constants {
static let resourcesPath = Path("./Sources/MockingbirdAutomation/Resources")
static let resourcesPath = Path("./Sources/MockingbirdAutomationCli/Resources")
static let projectPath = Path("./Mockingbird.xcodeproj")
}

Expand Down
27 changes: 15 additions & 12 deletions mockingbird
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@ function getVersion {
readonly version="${MKB_VERSION:-"$(getVersion)"}"
echo "Using Mockingbird v${version}"

readonly binDir="bin/${version}"
readonly executable="${binDir}/mockingbird"
readonly binDir="bin"
readonly executable="${binDir}/${version}/mockingbird"
mkdir -p "${binDir}"

if [[ ! -x "${executable}" ]]; then
readonly archiveName='Mockingbird.zip'
curlOpts=( --progress-bar --location --output "${binDir}/${archiveName}" )
readonly archiveName='Mockingbird'
readonly archiveFileName="${archiveName}.zip"
curlOpts=( --progress-bar --location --output "${binDir}/${archiveFileName}" )
if [[ -n "${GH_ACCESS_TOKEN+x}" ]]; then
curlOpts+=( --header "Authorization: token ${GH_ACCESS_TOKEN}" )
fi

# Download
readonly artifactsUrl="${MKB_ARTIFACTS_URL:-https://github.com/birdrides/mockingbird/releases/download/<VERSION>/<FILE>}"
readonly downloadUrl="$(echo "${artifactsUrl}" | sed -n "s|<VERSION>|${version}|p" | sed -n "s|<FILE>|${archiveName}|p")"
echo "Downloading Mockingbird from ${downloadUrl} into ${binDir}"
readonly downloadUrl="$(echo "${artifactsUrl}" | sed "s|<VERSION>|${version}|" | sed "s|<FILE>|${archiveFileName}|")"
echo "Downloading Mockingbird from ${downloadUrl} into ${binDir}/${version}"
curl "${curlOpts[@]}" "${downloadUrl}"

# Extract
unzip -oq "${binDir}/${archiveName}" -d "${binDir}"
rm "${binDir}/${archiveName}"

unzip -oq "${binDir}/${archiveFileName}" -d "${binDir}"
rm "${binDir}/${archiveFileName}"
rm -rf "${binDir}/${version}"
mv -f "${binDir}/${archiveName}" "${binDir}/${version}"

# Verify
if [[ "${MKB_NO_VERIFY:-}" -ne 1 ]]; then
if xcrun codesign -vv -R Scripts/Resources/CodesigningRequirements/mockingbird.txt "${executable}"; then
if xcrun codesign -vv -R Sources/MockingbirdAutomationCli/Resources/CodesigningRequirements/mockingbird.txt "${executable}"; then
echo '✅ Verified the code signature'
else
echo -e '\033[1;31merror:\033[0m The downloaded binary does not have a valid code signature. Set `MKB_NO_VERIFY=1` to bypass this error at your own risk.'
Expand Down

0 comments on commit ab0de2c

Please sign in to comment.