Skip to content

Commit

Permalink
Add support for SwiftPM binary artifacts (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch authored Jun 24, 2023
1 parent 55f114a commit acdaca4
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 21 deletions.
27 changes: 21 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.7
import PackageDescription

var dependencies: [Package.Dependency] = [
Expand All @@ -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"
)
Expand All @@ -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: [
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions Plugins/PeripheryCommandPlugin/PeripheryCommandPlugin.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
2 changes: 1 addition & 1 deletion scripts/Periphery.podspec.template
Original file line number Diff line number Diff line change
Expand Up @@ -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" => "[email protected]" }
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
15 changes: 15 additions & 0 deletions scripts/info.json.template
Original file line number Diff line number Diff line change
@@ -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"]
}
]
}
}
}
52 changes: 38 additions & 14 deletions scripts/release
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -19,22 +19,26 @@ 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

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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit acdaca4

Please sign in to comment.