Skip to content

Commit 14dd6aa

Browse files
authored
Fix SwiftPM plugins (#1732)
* fix: SwiftPM plugins * fix: SwiftPM plugins Added swiftlint command line plugin * fix: SwiftPM plugins Try makefile for CI runs * fix: SwiftPM plugins Try makefile for CI runs * fix: SwiftPM plugins Try swiftlint bin from SwiftPM * fix: SwiftPM plugins Resolve spm before running danger lint * fix: SwiftPM plugins Resolve spm before running danger lint * fix: SwiftPM plugins Changelog * fix: SwiftPM plugins Test failures reporting on CI * fix: SwiftPM plugins Test failures reporting on CI * fix: SwiftPM plugins Test failures reporting on CI * fix: SwiftPM plugins Revert failing code * fix: SwiftPM plugins Revert failing code * fix: SwiftPM plugins Cleanup unused files * fix: SwiftPM plugins Makefile setup for git hooks
1 parent cdc2cec commit 14dd6aa

13 files changed

Lines changed: 105 additions & 47 deletions

File tree

.github/workflows/ci_pr_example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
with:
1515
fetch-depth: 10
1616
- name: Build and run example project
17-
run: ./build.sh example
17+
run: make build_example

.github/workflows/ci_pr_framework.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ jobs:
1212
- name: Checkout the Git repository
1313
uses: actions/checkout@v2
1414
- name: Build framework
15-
run: ./build.sh framework
15+
run: make framework

.github/workflows/ci_pr_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ jobs:
1212
- name: Checkout the Git repository
1313
uses: actions/checkout@v2
1414
- name: Build and run tests
15-
run: ./build.sh tests
15+
run: make test

.github/workflows/danger.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ on:
66

77
jobs:
88
danger:
9-
name: Run Danger
10-
runs-on: macos-latest
9+
name: Run Danger
10+
runs-on: macos-12
11+
env:
12+
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app/Contents/Developer
1113
steps:
1214
- name: Checkout the Git repository
1315
uses: actions/checkout@v2
1416
with:
1517
fetch-depth: 100
1618
token: ${{ secrets.GITHUB_TOKEN }}
1719
ref: ${{ github.event.pull_request.head.ref }}
20+
- name: Resolve SwiftPM dependencies
21+
run: rm -rf ".build" && swift package clean && swift package resolve
1822
- name: Run build script
1923
run: gem install bundler && bundle install && bundle exec danger --fail-on-errors=true
2024
env:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa
1111
### Fixed
1212

1313
- Fixed iOS 13 deprecation warnings [#1730](https://github.com/MessageKit/MessageKit/pull/1730) by [@kaspik](https://github.com/Kaspik)
14+
- SwiftPM plugins setup [#1732](https://github.com/MessageKit/MessageKit/pull/1732) by [@martinpucik](https://github.com/martinpucik)
1415

1516
## 4.0.0
1617

Dangerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ if git.lines_of_code > 1000
5151
end
5252

5353
swiftlint.config_file = '.swiftlint.yml'
54-
swiftlint.binary_path = 'bin/swiftlint'
54+
swiftlint.binary_path = '.build/artifacts/messagekit/SwiftLintBinary.artifactbundle/swiftlint-0.47.1-macos/bin/swiftlint'
5555
swiftlint.lint_files inline_mode:true, fail_on_error:true
Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#!/bin/bash
2-
31
# MIT License
42
#
5-
# Copyright (c) 2017-2020 MessageKit
3+
# Copyright (c) 2017-2022 MessageKit
64
#
75
# Permission is hereby granted, free of charge, to any person obtaining a copy
86
# of this software and associated documentation files (the "Software"), to deal
@@ -22,44 +20,29 @@
2220
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2321
# SOFTWARE.
2422

25-
set -e
26-
function trap_handler {
27-
echo -e "\n\nOh no! You walked directly into the slavering fangs of a lurking grue!"
28-
echo "**** You have died ****"
29-
exit 255
30-
}
31-
trap trap_handler INT TERM EXIT
32-
33-
MODE="$1"
23+
.SHELLFLAGS = -ec
24+
.SHELL = /bin/bash
3425

35-
if [ "$MODE" = "tests" -o "$MODE" = "all" ]; then
36-
echo "Running MessageKit tests."
37-
set -o pipefail && xcodebuild test -scheme MessageKit -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 11" | xcpretty -c
38-
success="1"
39-
fi
26+
test:
27+
@echo "Running MessageKit tests."
28+
@set -o pipefail && xcodebuild test -scheme MessageKit -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 11" | xcpretty -c
4029

41-
if [ "$MODE" = "framework" -o "$MODE" = "all" ]; then
42-
echo "Building MessageKit Framework."
43-
set -o pipefail && xcodebuild build -scheme MessageKit -destination "platform=iOS Simulator,name=iPhone 11" | xcpretty -c
44-
success="1"
45-
fi
30+
framework:
31+
@echo "Building MessageKit Framework."
32+
@set -o pipefail && xcodebuild build -scheme MessageKit -destination "platform=iOS Simulator,name=iPhone 11" | xcpretty -c
4633

47-
if [ "$MODE" = "example" -o "$MODE" = "all" ]; then
48-
echo "Building & testing MessageKit Example app."
49-
cd Example
50-
set -o pipefail && xcodebuild build analyze -scheme ChatExample -destination "platform=iOS Simulator,name=iPhone 11" CODE_SIGNING_REQUIRED=NO | xcpretty -c
51-
success="1"
52-
fi
34+
build_example:
35+
@echo "Building & testing MessageKit Example app."
36+
@cd Example && set -o pipefail && xcodebuild build analyze -scheme ChatExample -destination "platform=iOS Simulator,name=iPhone 11" CODE_SIGNING_REQUIRED=NO | xcpretty -c
5337

54-
if [ "$MODE" = "swiftformat" ]; then
55-
echo "Running Swiftformat ..."
56-
set -o pipefail && swift package --allow-writing-to-package-directory format-source-code --file .
57-
success="1"
58-
fi
38+
format:
39+
@swift package --allow-writing-to-package-directory format-source-code --file .
5940

60-
if [ "$success" = "1" ]; then
61-
trap - EXIT
62-
exit 0
63-
fi
41+
lint:
42+
@swift package --disable-sandbox lint
6443

65-
echo "Unrecognised mode '$MODE'."
44+
setup:
45+
@mkdir -p .git/hooks
46+
@rm -f .git/hooks/pre-commit
47+
@cp ./Scripts/pre-commit ./.git/hooks
48+
@chmod +x .git/hooks/pre-commit

Package.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let package = Package(
4242
path: "Sources",
4343
exclude: ["Supporting/Info.plist", "Supporting/MessageKit.h"],
4444
swiftSettings: [SwiftSetting.define("IS_SPM")],
45-
plugins: ["SwiftLintPlugin", "SwiftFormatPlugin"]
45+
plugins: ["SwiftLintPlugin"]
4646
),
4747
.testTarget(name: "MessageKitTests", dependencies: ["MessageKit"]),
4848

@@ -58,6 +58,16 @@ let package = Package(
5858
capability: .buildTool(),
5959
dependencies: ["SwiftLintBinary"]
6060
),
61+
.plugin(
62+
name: "SwiftLintCommandPlugin",
63+
capability: .command(
64+
intent: .custom(
65+
verb: "lint",
66+
description: "Lint Swift source files"
67+
)
68+
),
69+
dependencies: ["SwiftLintBinary"]
70+
),
6171

6272
.binaryTarget(
6373
name: "swiftformat",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2017-2022 MessageKit
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
21+
import Foundation
22+
import PackagePlugin
23+
24+
// MARK: - SwiftLintCommandPlugin
25+
26+
@main
27+
struct SwiftLintCommandPlugin: CommandPlugin {
28+
func performCommand(context: PackagePlugin.PluginContext, arguments _: [String]) async throws {
29+
let swiftLintTool = try context.tool(named: "swiftlint")
30+
let swiftLintPath = URL(fileURLWithPath: swiftLintTool.path.string)
31+
32+
let swiftLintArgs = [
33+
"lint",
34+
"--path", context.package.directory.string,
35+
"--config", context.package.directory.string + "/.swiftlint.yml",
36+
"--strict",
37+
]
38+
39+
let task = try Process.run(swiftLintPath, arguments: swiftLintArgs)
40+
task.waitUntilExit()
41+
42+
if task.terminationStatus == 0 || task.terminationStatus == 2 {
43+
// no-op
44+
} else {
45+
throw CommandError.unknownError(exitCode: task.terminationStatus)
46+
}
47+
}
48+
}
49+
50+
// MARK: - CommandError
51+
52+
enum CommandError: Error {
53+
case unknownError(exitCode: Int32)
54+
}

Scripts/pre-commit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do
4+
swift package --allow-writing-to-package-directory format-source-code --file "${line}";
5+
git add "$line";
6+
done

0 commit comments

Comments
 (0)