From acdaca4a794dc492650b04bdb4c3e0f8e27eb5cc Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Sat, 24 Jun 2023 12:33:34 -0400 Subject: [PATCH] Add support for SwiftPM binary artifacts (#622) --- Package.swift | 27 +++++++--- .../PeripheryCommandPlugin.swift | 15 ++++++ scripts/Periphery.podspec.template | 2 +- scripts/info.json.template | 15 ++++++ scripts/release | 52 ++++++++++++++----- 5 files changed, 90 insertions(+), 21 deletions(-) create mode 100644 Plugins/PeripheryCommandPlugin/PeripheryCommandPlugin.swift create mode 100644 scripts/info.json.template diff --git a/Package.swift b/Package.swift index b8e64d6db..10ffbb53a 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.5 +// swift-tools-version:5.7 import PackageDescription var dependencies: [Package.Dependency] = [ @@ -7,14 +7,13 @@ var dependencies: [Package.Dependency] = [ .package(url: "https://github.com/tadija/AEXML", from: "4.0.0"), .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"), .package(url: "https://github.com/ileitch/swift-indexstore", from: "9.0.0"), - .package(url: "https://github.com/peripheryapp/swift-syntax", .exact("1.0.2")), - .package(url: "https://github.com/ileitch/swift-filename-matcher", from: "0.0.0") + .package(url: "https://github.com/peripheryapp/swift-syntax", exact: "1.0.2"), + .package(url: "https://github.com/ileitch/swift-filename-matcher", from: "0.0.0"), ] #if os(macOS) dependencies.append( .package( - name: "XcodeProj", url: "https://github.com/tuist/xcodeproj", from: "8.0.0" ) @@ -37,6 +36,16 @@ var targets: [PackageDescription.Target] = [ name: "Frontend", dependencies: frontendDependencies ), + // .plugin( + // name: "PeripheryCommandPlugin", + // capability: .command( + // intent: .custom(verb: "periphery", description: "Detect unused code"), + // permissions: [] + // ), + // dependencies: [ + // .target(name: "PeripheryBinary", condition: .when(platforms: [.macOS])), + // ] + // ), .target( name: "PeripheryKit", dependencies: [ @@ -120,7 +129,12 @@ var targets: [PackageDescription.Target] = [ .target(name: "PeripheryKit") ], exclude: ["AccessibilityProject"] - ) + ), +// .binaryTarget( +// name: "PeripheryBinary", +// url: "https://github.com/peripheryapp/Periphery/releases/download/124/periphery-124-macos.artifactbundle.zip", +// checksum: "" +// ), ] #if os(macOS) @@ -157,7 +171,8 @@ let package = Package( name: "Periphery", platforms: [.macOS(.v12)], products: [ - .executable(name: "periphery", targets: ["Frontend"]) + .executable(name: "periphery", targets: ["Frontend"]), + // .plugin(name: "PeripheryCommandPlugin", targets: ["PeripheryCommandPlugin"]), ], dependencies: dependencies, targets: targets, diff --git a/Plugins/PeripheryCommandPlugin/PeripheryCommandPlugin.swift b/Plugins/PeripheryCommandPlugin/PeripheryCommandPlugin.swift new file mode 100644 index 000000000..931543aae --- /dev/null +++ b/Plugins/PeripheryCommandPlugin/PeripheryCommandPlugin.swift @@ -0,0 +1,15 @@ +import PackagePlugin +import Foundation + +@main +struct PeripheryCommandPlugin: CommandPlugin { + func performCommand( + context: PluginContext, + arguments: [String] + ) throws { + let tool = try context.tool(named: "periphery") + let toolUrl = URL(fileURLWithPath: tool.path.string) + let process = try Process.run(toolUrl, arguments: arguments) + process.waitUntilExit() + } +} diff --git a/scripts/Periphery.podspec.template b/scripts/Periphery.podspec.template index a37b6f7c2..3223b9e74 100644 --- a/scripts/Periphery.podspec.template +++ b/scripts/Periphery.podspec.template @@ -5,6 +5,6 @@ Pod::Spec.new do |spec| spec.homepage = "https://github.com/peripheryapp/periphery" spec.license = { :type => 'MIT', :file => 'LICENSE.md' } spec.author = { "Ian Leitch" => "ian@leitch.io" } - spec.source = { :http => "#{spec.homepage}/releases/download/#{spec.version}/periphery-v#{spec.version}.zip" } + spec.source = { :http => "#{spec.homepage}/releases/download/#{spec.version}/periphery-#{spec.version}.zip" } spec.preserve_paths = '*' end diff --git a/scripts/info.json.template b/scripts/info.json.template new file mode 100644 index 000000000..11e0c9c69 --- /dev/null +++ b/scripts/info.json.template @@ -0,0 +1,15 @@ +{ + "schemaVersion": "1.0", + "artifacts": { + "periphery": { + "version": "__VERSION__", + "type": "executable", + "variants": [ + { + "path": "periphery-__VERSION__-macos/bin/periphery", + "supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"] + } + ] + } + } +} diff --git a/scripts/release b/scripts/release index f085b439d..40fd45456 100755 --- a/scripts/release +++ b/scripts/release @@ -6,7 +6,7 @@ GREEN='\033[1;32m' NC='\033[0m' # No Color confirm () { - green "\n$1 (y/n): " + green "$1 (y/n): " read answer if [ $answer != "y" ] @@ -19,9 +19,13 @@ green () { printf "${GREEN}${1}${NC}" } -signature="Developer ID Application: Ian Leitch (8L8F8HSTR4)" -password="@keychain:PeripheryNotarize" -bundle_id="com.github.peripheryapp" +codesign () { + /usr/bin/codesign --force --options=runtime --sign "Developer ID Application: Ian Leitch (8L8F8HSTR4)" "$1" +} + +notarize () { + xcrun notarytool submit --keychain-profile "PeripheryNotarize" --wait "$1" +} xcodebuild -version @@ -29,12 +33,12 @@ printf "\nVersion: " read version printf "Got it: $version\n" -confirm "Continue?" +confirm "\nContinue?" cat scripts/Version.swift.template | sed s/__VERSION__/${version}/ > Sources/Frontend/Version.swift cat scripts/Periphery.podspec.template | sed s/__VERSION__/${version}/ > Periphery.podspec -echo -e "\nUpdate CHANGELOG.md and verify changes." +echo -e "\nUpdate CHANGELOG.md" confirm "Continue?" bin_path=$(make show_bin_path) @@ -46,19 +50,39 @@ cp "$bin_path" .release/ cp LICENSE.md .release/ cp scripts/release_notes.md.template .release/release_notes.md -# Archive +# Codesign cd .release -codesign --force --options=runtime --sign "$signature" periphery -zip_filename="periphery-v${version}.zip" +codesign periphery + +# Archive +zip_filename="periphery-${version}.zip" zip "${zip_filename}" periphery LICENSE.md -codesign --force --options=runtime --sign "$signature" "${zip_filename}" -xcrun altool --notarize-app --primary-bundle-id "${bundle_id}" --password "${password}" --file "${zip_filename}" +codesign "${zip_filename}" -echo "Checksum:" +echo "\n${zip_filename} checksum:" sha256=$( shasum -a 256 ${zip_filename} | awk '{print $1}' ) echo ${sha256} -echo -e "\nWait for notarization approval: xcrun altool --notarization-history 0 -p \"$password\"" +# Artifact bundle +artifactbundle_zip_filename="periphery-${version}-macos.artifactbundle.zip" +cat ../scripts/info.json.template | sed s/__VERSION__/${version}/ > info.json +mkdir -p "periphery-${version}-macos/bin" +cp periphery "periphery-${version}-macos/bin" +zip "${artifactbundle_zip_filename}" LICENSE.md info.json "periphery-${version}-macos/bin/periphery" +codesign "${artifactbundle_zip_filename}" + +echo "\n${artifactbundle_zip_filename} checksum:" +artifactbundle_sha256=$( shasum -a 256 ${artifactbundle_zip_filename} | awk '{print $1}' ) +echo ${artifactbundle_sha256} + +echo -e "\nUpdate Package.swift" +confirm "Continue?" + +# Notarize +notarize "${zip_filename}" +notarize "${artifactbundle_zip_filename}" + +echo -e "\nVerify changes" confirm "Continue?" # GitHub @@ -75,7 +99,7 @@ cat release_notes.md echo cd .. -hub release create "${version}" -a .release/periphery-v${version}.zip -F .release/release_notes.md +gh release create -F .release/release_notes.md "${version}" ".release/${zip_filename}" ".release/${artifactbundle_zip_filename}" # HomeBrew cd ../homebrew-periphery