Skip to content

Commit

Permalink
Fix SwiftPM plugins (MessageKit#1732)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
martinpucik authored Jul 31, 2022
1 parent cdc2cec commit 14dd6aa
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_pr_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
with:
fetch-depth: 10
- name: Build and run example project
run: ./build.sh example
run: make build_example
2 changes: 1 addition & 1 deletion .github/workflows/ci_pr_framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- name: Checkout the Git repository
uses: actions/checkout@v2
- name: Build framework
run: ./build.sh framework
run: make framework
2 changes: 1 addition & 1 deletion .github/workflows/ci_pr_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- name: Checkout the Git repository
uses: actions/checkout@v2
- name: Build and run tests
run: ./build.sh tests
run: make test
8 changes: 6 additions & 2 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ on:

jobs:
danger:
name: Run Danger
runs-on: macos-latest
name: Run Danger
runs-on: macos-12
env:
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app/Contents/Developer
steps:
- name: Checkout the Git repository
uses: actions/checkout@v2
with:
fetch-depth: 100
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Resolve SwiftPM dependencies
run: rm -rf ".build" && swift package clean && swift package resolve
- name: Run build script
run: gem install bundler && bundle install && bundle exec danger --fail-on-errors=true
env:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa
### Fixed

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

## 4.0.0

Expand Down
2 changes: 1 addition & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ if git.lines_of_code > 1000
end

swiftlint.config_file = '.swiftlint.yml'
swiftlint.binary_path = 'bin/swiftlint'
swiftlint.binary_path = '.build/artifacts/messagekit/SwiftLintBinary.artifactbundle/swiftlint-0.47.1-macos/bin/swiftlint'
swiftlint.lint_files inline_mode:true, fail_on_error:true
59 changes: 21 additions & 38 deletions build.sh → Makefile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash

# MIT License
#
# Copyright (c) 2017-2020 MessageKit
# Copyright (c) 2017-2022 MessageKit
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,44 +20,29 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

set -e
function trap_handler {
echo -e "\n\nOh no! You walked directly into the slavering fangs of a lurking grue!"
echo "**** You have died ****"
exit 255
}
trap trap_handler INT TERM EXIT

MODE="$1"
.SHELLFLAGS = -ec
.SHELL = /bin/bash

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

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

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

if [ "$MODE" = "swiftformat" ]; then
echo "Running Swiftformat ..."
set -o pipefail && swift package --allow-writing-to-package-directory format-source-code --file .
success="1"
fi
format:
@swift package --allow-writing-to-package-directory format-source-code --file .

if [ "$success" = "1" ]; then
trap - EXIT
exit 0
fi
lint:
@swift package --disable-sandbox lint

echo "Unrecognised mode '$MODE'."
setup:
@mkdir -p .git/hooks
@rm -f .git/hooks/pre-commit
@cp ./Scripts/pre-commit ./.git/hooks
@chmod +x .git/hooks/pre-commit
12 changes: 11 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let package = Package(
path: "Sources",
exclude: ["Supporting/Info.plist", "Supporting/MessageKit.h"],
swiftSettings: [SwiftSetting.define("IS_SPM")],
plugins: ["SwiftLintPlugin", "SwiftFormatPlugin"]
plugins: ["SwiftLintPlugin"]
),
.testTarget(name: "MessageKitTests", dependencies: ["MessageKit"]),

Expand All @@ -58,6 +58,16 @@ let package = Package(
capability: .buildTool(),
dependencies: ["SwiftLintBinary"]
),
.plugin(
name: "SwiftLintCommandPlugin",
capability: .command(
intent: .custom(
verb: "lint",
description: "Lint Swift source files"
)
),
dependencies: ["SwiftLintBinary"]
),

.binaryTarget(
name: "swiftformat",
Expand Down
54 changes: 54 additions & 0 deletions Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// MIT License
//
// Copyright (c) 2017-2022 MessageKit
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import Foundation
import PackagePlugin

// MARK: - SwiftLintCommandPlugin

@main
struct SwiftLintCommandPlugin: CommandPlugin {
func performCommand(context: PackagePlugin.PluginContext, arguments _: [String]) async throws {
let swiftLintTool = try context.tool(named: "swiftlint")
let swiftLintPath = URL(fileURLWithPath: swiftLintTool.path.string)

let swiftLintArgs = [
"lint",
"--path", context.package.directory.string,
"--config", context.package.directory.string + "/.swiftlint.yml",
"--strict",
]

let task = try Process.run(swiftLintPath, arguments: swiftLintArgs)
task.waitUntilExit()

if task.terminationStatus == 0 || task.terminationStatus == 2 {
// no-op
} else {
throw CommandError.unknownError(exitCode: task.terminationStatus)
}
}
}

// MARK: - CommandError

enum CommandError: Error {
case unknownError(exitCode: Int32)
}
6 changes: 6 additions & 0 deletions Scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do
swift package --allow-writing-to-package-directory format-source-code --file "${line}";
git add "$line";
done
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ extension MessagesViewController {
/// when `animated` is `TRUE` or before the `completion` block executes
/// when `animated` is `FALSE`
/// - completion: A completion block to execute after the insertion/deletion
@objc open func setTypingIndicatorViewHidden(
@objc
open func setTypingIndicatorViewHidden(
_ isHidden: Bool,
animated: Bool,
whilePerforming updates: (() -> Void)? = nil,
Expand Down
Binary file removed bin/swiftlint
Binary file not shown.
1 change: 0 additions & 1 deletion bin/swiftlint.version.txt

This file was deleted.

0 comments on commit 14dd6aa

Please sign in to comment.