Skip to content

Commit acdaca4

Browse files
authored
Add support for SwiftPM binary artifacts (#622)
1 parent 55f114a commit acdaca4

File tree

5 files changed

+90
-21
lines changed

5 files changed

+90
-21
lines changed

Package.swift

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.7
22
import PackageDescription
33

44
var dependencies: [Package.Dependency] = [
@@ -7,14 +7,13 @@ var dependencies: [Package.Dependency] = [
77
.package(url: "https://github.com/tadija/AEXML", from: "4.0.0"),
88
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
99
.package(url: "https://github.com/ileitch/swift-indexstore", from: "9.0.0"),
10-
.package(url: "https://github.com/peripheryapp/swift-syntax", .exact("1.0.2")),
11-
.package(url: "https://github.com/ileitch/swift-filename-matcher", from: "0.0.0")
10+
.package(url: "https://github.com/peripheryapp/swift-syntax", exact: "1.0.2"),
11+
.package(url: "https://github.com/ileitch/swift-filename-matcher", from: "0.0.0"),
1212
]
1313

1414
#if os(macOS)
1515
dependencies.append(
1616
.package(
17-
name: "XcodeProj",
1817
url: "https://github.com/tuist/xcodeproj",
1918
from: "8.0.0"
2019
)
@@ -37,6 +36,16 @@ var targets: [PackageDescription.Target] = [
3736
name: "Frontend",
3837
dependencies: frontendDependencies
3938
),
39+
// .plugin(
40+
// name: "PeripheryCommandPlugin",
41+
// capability: .command(
42+
// intent: .custom(verb: "periphery", description: "Detect unused code"),
43+
// permissions: []
44+
// ),
45+
// dependencies: [
46+
// .target(name: "PeripheryBinary", condition: .when(platforms: [.macOS])),
47+
// ]
48+
// ),
4049
.target(
4150
name: "PeripheryKit",
4251
dependencies: [
@@ -120,7 +129,12 @@ var targets: [PackageDescription.Target] = [
120129
.target(name: "PeripheryKit")
121130
],
122131
exclude: ["AccessibilityProject"]
123-
)
132+
),
133+
// .binaryTarget(
134+
// name: "PeripheryBinary",
135+
// url: "https://github.com/peripheryapp/Periphery/releases/download/124/periphery-124-macos.artifactbundle.zip",
136+
// checksum: ""
137+
// ),
124138
]
125139

126140
#if os(macOS)
@@ -157,7 +171,8 @@ let package = Package(
157171
name: "Periphery",
158172
platforms: [.macOS(.v12)],
159173
products: [
160-
.executable(name: "periphery", targets: ["Frontend"])
174+
.executable(name: "periphery", targets: ["Frontend"]),
175+
// .plugin(name: "PeripheryCommandPlugin", targets: ["PeripheryCommandPlugin"]),
161176
],
162177
dependencies: dependencies,
163178
targets: targets,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import PackagePlugin
2+
import Foundation
3+
4+
@main
5+
struct PeripheryCommandPlugin: CommandPlugin {
6+
func performCommand(
7+
context: PluginContext,
8+
arguments: [String]
9+
) throws {
10+
let tool = try context.tool(named: "periphery")
11+
let toolUrl = URL(fileURLWithPath: tool.path.string)
12+
let process = try Process.run(toolUrl, arguments: arguments)
13+
process.waitUntilExit()
14+
}
15+
}

scripts/Periphery.podspec.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Pod::Spec.new do |spec|
55
spec.homepage = "https://github.com/peripheryapp/periphery"
66
spec.license = { :type => 'MIT', :file => 'LICENSE.md' }
77
spec.author = { "Ian Leitch" => "[email protected]" }
8-
spec.source = { :http => "#{spec.homepage}/releases/download/#{spec.version}/periphery-v#{spec.version}.zip" }
8+
spec.source = { :http => "#{spec.homepage}/releases/download/#{spec.version}/periphery-#{spec.version}.zip" }
99
spec.preserve_paths = '*'
1010
end

scripts/info.json.template

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"artifacts": {
4+
"periphery": {
5+
"version": "__VERSION__",
6+
"type": "executable",
7+
"variants": [
8+
{
9+
"path": "periphery-__VERSION__-macos/bin/periphery",
10+
"supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"]
11+
}
12+
]
13+
}
14+
}
15+
}

scripts/release

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GREEN='\033[1;32m'
66
NC='\033[0m' # No Color
77

88
confirm () {
9-
green "\n$1 (y/n): "
9+
green "$1 (y/n): "
1010
read answer
1111

1212
if [ $answer != "y" ]
@@ -19,22 +19,26 @@ green () {
1919
printf "${GREEN}${1}${NC}"
2020
}
2121

22-
signature="Developer ID Application: Ian Leitch (8L8F8HSTR4)"
23-
password="@keychain:PeripheryNotarize"
24-
bundle_id="com.github.peripheryapp"
22+
codesign () {
23+
/usr/bin/codesign --force --options=runtime --sign "Developer ID Application: Ian Leitch (8L8F8HSTR4)" "$1"
24+
}
25+
26+
notarize () {
27+
xcrun notarytool submit --keychain-profile "PeripheryNotarize" --wait "$1"
28+
}
2529

2630
xcodebuild -version
2731

2832
printf "\nVersion: "
2933
read version
3034
printf "Got it: $version\n"
3135

32-
confirm "Continue?"
36+
confirm "\nContinue?"
3337

3438
cat scripts/Version.swift.template | sed s/__VERSION__/${version}/ > Sources/Frontend/Version.swift
3539
cat scripts/Periphery.podspec.template | sed s/__VERSION__/${version}/ > Periphery.podspec
3640

37-
echo -e "\nUpdate CHANGELOG.md and verify changes."
41+
echo -e "\nUpdate CHANGELOG.md"
3842
confirm "Continue?"
3943

4044
bin_path=$(make show_bin_path)
@@ -46,19 +50,39 @@ cp "$bin_path" .release/
4650
cp LICENSE.md .release/
4751
cp scripts/release_notes.md.template .release/release_notes.md
4852

49-
# Archive
53+
# Codesign
5054
cd .release
51-
codesign --force --options=runtime --sign "$signature" periphery
52-
zip_filename="periphery-v${version}.zip"
55+
codesign periphery
56+
57+
# Archive
58+
zip_filename="periphery-${version}.zip"
5359
zip "${zip_filename}" periphery LICENSE.md
54-
codesign --force --options=runtime --sign "$signature" "${zip_filename}"
55-
xcrun altool --notarize-app --primary-bundle-id "${bundle_id}" --password "${password}" --file "${zip_filename}"
60+
codesign "${zip_filename}"
5661

57-
echo "Checksum:"
62+
echo "\n${zip_filename} checksum:"
5863
sha256=$( shasum -a 256 ${zip_filename} | awk '{print $1}' )
5964
echo ${sha256}
6065

61-
echo -e "\nWait for notarization approval: xcrun altool --notarization-history 0 -p \"$password\""
66+
# Artifact bundle
67+
artifactbundle_zip_filename="periphery-${version}-macos.artifactbundle.zip"
68+
cat ../scripts/info.json.template | sed s/__VERSION__/${version}/ > info.json
69+
mkdir -p "periphery-${version}-macos/bin"
70+
cp periphery "periphery-${version}-macos/bin"
71+
zip "${artifactbundle_zip_filename}" LICENSE.md info.json "periphery-${version}-macos/bin/periphery"
72+
codesign "${artifactbundle_zip_filename}"
73+
74+
echo "\n${artifactbundle_zip_filename} checksum:"
75+
artifactbundle_sha256=$( shasum -a 256 ${artifactbundle_zip_filename} | awk '{print $1}' )
76+
echo ${artifactbundle_sha256}
77+
78+
echo -e "\nUpdate Package.swift"
79+
confirm "Continue?"
80+
81+
# Notarize
82+
notarize "${zip_filename}"
83+
notarize "${artifactbundle_zip_filename}"
84+
85+
echo -e "\nVerify changes"
6286
confirm "Continue?"
6387

6488
# GitHub
@@ -75,7 +99,7 @@ cat release_notes.md
7599
echo
76100

77101
cd ..
78-
hub release create "${version}" -a .release/periphery-v${version}.zip -F .release/release_notes.md
102+
gh release create -F .release/release_notes.md "${version}" ".release/${zip_filename}" ".release/${artifactbundle_zip_filename}"
79103

80104
# HomeBrew
81105
cd ../homebrew-periphery

0 commit comments

Comments
 (0)