From ab0de2c3eec7f31bb08ffe937c5da54b5001c5d3 Mon Sep 17 00:00:00 2001 From: Andrew Chang <47129469+andrewchang-bird@users.noreply.github.com> Date: Mon, 10 Jan 2022 09:52:38 -1000 Subject: [PATCH] Fix CLI archiving and distribution (#260) 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. --- Mockingbird.xcodeproj/project.pbxproj | 4 +++ MockingbirdFramework.podspec | 2 +- Package.swift | 1 - .../MockingbirdAutomation/Interop/Zip.swift | 13 +++++++++ .../Commands/Build.swift | 7 ++--- .../Commands/BuildCli.swift | 2 +- .../Commands/Configure.swift | 2 +- .../CodesigningRequirements/README.md | 0 .../CodesigningRequirements/mockingbird.txt | 0 .../MockingbirdAutomation.xcscheme | 0 .../MockingbirdAutomationCli.xcscheme | 0 .../XcodeSchemes/MockingbirdCli.xcscheme | 0 .../XcodeSchemes/MockingbirdCommon.xcscheme | 0 .../MockingbirdFramework.xcscheme | 0 .../MockingbirdGenerator.xcscheme | 0 .../XcodeSchemes/MockingbirdTests.xcscheme | 0 .../MockingbirdTestsHost.xcscheme | 0 .../Resources/XcodeSchemes/README.md | 0 mockingbird | 27 ++++++++++--------- 19 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 Sources/MockingbirdAutomation/Interop/Zip.swift rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/CodesigningRequirements/README.md (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/CodesigningRequirements/mockingbird.txt (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/XcodeSchemes/MockingbirdAutomation.xcscheme (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/XcodeSchemes/MockingbirdAutomationCli.xcscheme (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/XcodeSchemes/MockingbirdCli.xcscheme (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/XcodeSchemes/MockingbirdCommon.xcscheme (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/XcodeSchemes/MockingbirdFramework.xcscheme (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/XcodeSchemes/MockingbirdGenerator.xcscheme (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/XcodeSchemes/MockingbirdTests.xcscheme (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/XcodeSchemes/MockingbirdTestsHost.xcscheme (100%) rename Sources/{MockingbirdAutomation => MockingbirdAutomationCli}/Resources/XcodeSchemes/README.md (100%) diff --git a/Mockingbird.xcodeproj/project.pbxproj b/Mockingbird.xcodeproj/project.pbxproj index 99df3043..acd6da31 100644 --- a/Mockingbird.xcodeproj/project.pbxproj +++ b/Mockingbird.xcodeproj/project.pbxproj @@ -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 */; }; @@ -622,6 +623,7 @@ 28719AEF26B21CB100C38C2C /* MKBProperty.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MKBProperty.m; sourceTree = ""; }; 28719AF226B22D1300C38C2C /* Stubbing+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stubbing+ObjC.swift"; sourceTree = ""; }; 28719AF426B23AB200C38C2C /* ObjectiveCTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectiveCTests.swift; sourceTree = ""; }; + 2873D49927896DE7004523BC /* Zip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Zip.swift; sourceTree = ""; }; 287BB9CA26AE1577004014CA /* Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mock.swift; sourceTree = ""; }; 287BB9CC26AE15F0004014CA /* InvocationForwarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvocationForwarding.swift; sourceTree = ""; }; 287C4F3926A3547000A7E0D9 /* MKBClassMock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MKBClassMock.h; sourceTree = ""; }; @@ -1179,6 +1181,7 @@ 285C8E16277AD76300DE525A /* SwiftPackage.swift */, 285C8E06277A7F9000DE525A /* XcodeBuild.swift */, 285C8E8B277C670300DE525A /* XcodeSelect.swift */, + 2873D49927896DE7004523BC /* Zip.swift */, ); path = Interop; sourceTree = ""; @@ -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 */, ); diff --git a/MockingbirdFramework.podspec b/MockingbirdFramework.podspec index 7cdc3659..444d204c 100644 --- a/MockingbirdFramework.podspec +++ b/MockingbirdFramework.podspec @@ -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', ] diff --git a/Package.swift b/Package.swift index 9fe205aa..5e32848c 100644 --- a/Package.swift +++ b/Package.swift @@ -89,7 +89,6 @@ if ProcessInfo.processInfo.environment["MKB_BUILD_EXECUTABLES"] != "1" { "MockingbirdAutomation", "MockingbirdCommon", "PathKit", - "ZIPFoundation", ]), .target( name: "MockingbirdAutomation", diff --git a/Sources/MockingbirdAutomation/Interop/Zip.swift b/Sources/MockingbirdAutomation/Interop/Zip.swift new file mode 100644 index 00000000..1365f24b --- /dev/null +++ b/Sources/MockingbirdAutomation/Interop/Zip.swift @@ -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() + } +} diff --git a/Sources/MockingbirdAutomationCli/Commands/Build.swift b/Sources/MockingbirdAutomationCli/Commands/Build.swift index 6ee57d7b..618df86e 100644 --- a/Sources/MockingbirdAutomationCli/Commands/Build.swift +++ b/Sources/MockingbirdAutomationCli/Commands/Build.swift @@ -2,7 +2,6 @@ import ArgumentParser import Foundation import MockingbirdAutomation import PathKit -import ZIPFoundation struct Build: ParsableCommand { static var configuration = CommandConfiguration( @@ -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) } } diff --git a/Sources/MockingbirdAutomationCli/Commands/BuildCli.swift b/Sources/MockingbirdAutomationCli/Commands/BuildCli.swift index 9e952864..f9bce409 100644 --- a/Sources/MockingbirdAutomationCli/Commands/BuildCli.swift +++ b/Sources/MockingbirdAutomationCli/Commands/BuildCli.swift @@ -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 diff --git a/Sources/MockingbirdAutomationCli/Commands/Configure.swift b/Sources/MockingbirdAutomationCli/Commands/Configure.swift index 8af8e9f9..abd8df18 100644 --- a/Sources/MockingbirdAutomationCli/Commands/Configure.swift +++ b/Sources/MockingbirdAutomationCli/Commands/Configure.swift @@ -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") } diff --git a/Sources/MockingbirdAutomation/Resources/CodesigningRequirements/README.md b/Sources/MockingbirdAutomationCli/Resources/CodesigningRequirements/README.md similarity index 100% rename from Sources/MockingbirdAutomation/Resources/CodesigningRequirements/README.md rename to Sources/MockingbirdAutomationCli/Resources/CodesigningRequirements/README.md diff --git a/Sources/MockingbirdAutomation/Resources/CodesigningRequirements/mockingbird.txt b/Sources/MockingbirdAutomationCli/Resources/CodesigningRequirements/mockingbird.txt similarity index 100% rename from Sources/MockingbirdAutomation/Resources/CodesigningRequirements/mockingbird.txt rename to Sources/MockingbirdAutomationCli/Resources/CodesigningRequirements/mockingbird.txt diff --git a/Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdAutomation.xcscheme b/Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdAutomation.xcscheme similarity index 100% rename from Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdAutomation.xcscheme rename to Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdAutomation.xcscheme diff --git a/Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdAutomationCli.xcscheme b/Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdAutomationCli.xcscheme similarity index 100% rename from Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdAutomationCli.xcscheme rename to Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdAutomationCli.xcscheme diff --git a/Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdCli.xcscheme b/Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdCli.xcscheme similarity index 100% rename from Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdCli.xcscheme rename to Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdCli.xcscheme diff --git a/Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdCommon.xcscheme b/Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdCommon.xcscheme similarity index 100% rename from Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdCommon.xcscheme rename to Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdCommon.xcscheme diff --git a/Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdFramework.xcscheme b/Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdFramework.xcscheme similarity index 100% rename from Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdFramework.xcscheme rename to Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdFramework.xcscheme diff --git a/Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdGenerator.xcscheme b/Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdGenerator.xcscheme similarity index 100% rename from Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdGenerator.xcscheme rename to Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdGenerator.xcscheme diff --git a/Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdTests.xcscheme b/Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdTests.xcscheme similarity index 100% rename from Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdTests.xcscheme rename to Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdTests.xcscheme diff --git a/Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdTestsHost.xcscheme b/Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdTestsHost.xcscheme similarity index 100% rename from Sources/MockingbirdAutomation/Resources/XcodeSchemes/MockingbirdTestsHost.xcscheme rename to Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/MockingbirdTestsHost.xcscheme diff --git a/Sources/MockingbirdAutomation/Resources/XcodeSchemes/README.md b/Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/README.md similarity index 100% rename from Sources/MockingbirdAutomation/Resources/XcodeSchemes/README.md rename to Sources/MockingbirdAutomationCli/Resources/XcodeSchemes/README.md diff --git a/mockingbird b/mockingbird index d564b620..8e1fef0b 100755 --- a/mockingbird +++ b/mockingbird @@ -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//}" - readonly downloadUrl="$(echo "${artifactsUrl}" | sed -n "s||${version}|p" | sed -n "s||${archiveName}|p")" - echo "Downloading Mockingbird from ${downloadUrl} into ${binDir}" + readonly downloadUrl="$(echo "${artifactsUrl}" | sed "s||${version}|" | sed "s||${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.'