diff --git a/CHANGELOG.md b/CHANGELOG.md index 0244a2e45..31a19a23d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,11 @@ #### Enhancements -* None. +* The `SwiftLintPlugin` SwiftPM plugin now uses a prebuilt binary on + macOS. + [Tony Arnold](https://github.com/tonyarnold) + [JP Simard](https://github.com/jpsim) + [#4558](https://github.com/realm/SwiftLint/issues/4558) #### Bug Fixes diff --git a/Makefile b/Makefile index 49fd285a6..cfb29c79f 100644 --- a/Makefile +++ b/Makefile @@ -132,8 +132,6 @@ bazel_release: bazel build :release mv bazel-bin/bazel.tar.gz bazel-bin/bazel.tar.gz.sha256 . -release: clean bazel_release package portable_zip spm_artifactbundle_macos zip_linux_release - docker_image: docker build --platform linux/amd64 --force-rm --tag swiftlint . @@ -160,7 +158,7 @@ docs: get_version: @echo "$(VERSION_STRING)" -push_version: +release: ifneq ($(strip $(shell git status --untracked-files=no --porcelain 2>/dev/null)),) $(error git state is not clean) endif @@ -168,6 +166,12 @@ endif $(eval NEW_VERSION := $(shell echo $(NEW_VERSION_AND_NAME) | sed 's/:.*//' )) @sed -i '' 's/## Main/## $(NEW_VERSION_AND_NAME)/g' CHANGELOG.md @sed 's/__VERSION__/$(NEW_VERSION)/g' tools/Version.swift.template > Source/SwiftLintFramework/Models/Version.swift + make clean + make bazel_release + make package + make portable_zip + make spm_artifactbundle_macos + ./tools/update-artifact-bundle.sh "$(NEW_VERSION)" git commit -a -m "release $(NEW_VERSION)" git tag -a $(NEW_VERSION) -m "$(NEW_VERSION_AND_NAME)" git push origin HEAD diff --git a/Package.swift b/Package.swift index e05447886..962f15c54 100644 --- a/Package.swift +++ b/Package.swift @@ -3,8 +3,10 @@ import PackageDescription #if os(macOS) private let addCryptoSwift = false +private let binaryPlugin = true #else private let addCryptoSwift = true +private let binaryPlugin = false #endif let frameworkDependencies: [Target.Dependency] = [ @@ -39,7 +41,7 @@ let package = Package( name: "SwiftLintPlugin", capability: .buildTool(), dependencies: [ - .target(name: "swiftlint") + .target(name: binaryPlugin ? "SwiftLintBinary" : "swiftlint") ] ), .executableTarget( @@ -98,5 +100,10 @@ let package = Package( "SwiftLintTestHelpers" ] ), + .binaryTarget( + name: "SwiftLintBinary", + url: "https://github.com/realm/SwiftLint/releases/download/0.50.1/SwiftLintBinary-macos.artifactbundle.zip", + checksum: "487c57b5a39b80d64a20a2d052312c3f5ff1a4ea28e3cf5556e43c5b9a184c0c" + ) ] ) diff --git a/Plugins/SwiftLintPlugin/Path+Helpers.swift b/Plugins/SwiftLintPlugin/Path+Helpers.swift index 5ddc7355e..0698dc600 100644 --- a/Plugins/SwiftLintPlugin/Path+Helpers.swift +++ b/Plugins/SwiftLintPlugin/Path+Helpers.swift @@ -1,16 +1,42 @@ import Foundation import PackagePlugin +#if os(Linux) +import Glibc +#else +import Darwin +#endif + extension Path { /// Scans the receiver, then all of its parents looking for a configuration file with the name ".swiftlint.yml". /// /// - returns: Path to the configuration file, or nil if one cannot be found. func firstConfigurationFileInParentDirectories() -> Path? { let defaultConfigurationFileName = ".swiftlint.yml" - let proposedDirectory = sequence(first: self, next: { $0.removingLastComponent() }).first { path in + let proposedDirectory = sequence( + first: self, + next: { path in + guard path.stem.count > 1 else { + // Check we're not at the root of this filesystem, as `removingLastComponent()` + // will continually return the root from itself. + return nil + } + + return path.removingLastComponent() + } + ).first { path in let potentialConfigurationFile = path.appending(subpath: defaultConfigurationFileName) - return FileManager.default.isReadableFile(atPath: potentialConfigurationFile.string) + return potentialConfigurationFile.isAccessible() } return proposedDirectory?.appending(subpath: defaultConfigurationFileName) } + + /// Safe way to check if the file is accessible from within the current process sandbox. + private func isAccessible() -> Bool { + let result = string.withCString { pointer in + access(pointer, R_OK) + } + + return result == 0 + } } diff --git a/Plugins/SwiftLintPlugin/SwiftLintPlugin.swift b/Plugins/SwiftLintPlugin/SwiftLintPlugin.swift index 51d597f28..c0b860c68 100644 --- a/Plugins/SwiftLintPlugin/SwiftLintPlugin.swift +++ b/Plugins/SwiftLintPlugin/SwiftLintPlugin.swift @@ -22,6 +22,7 @@ struct SwiftLintPlugin: BuildToolPlugin { let swiftlint = try context.tool(named: "swiftlint") var arguments: [String] = [ "lint", + "--quiet", "--cache-path", "\(context.pluginWorkDirectory)" ] @@ -67,6 +68,7 @@ extension SwiftLintPlugin: XcodeBuildToolPlugin { let swiftlint = try context.tool(named: "swiftlint") var arguments: [String] = [ "lint", + "--quiet", "--cache-path", "\(context.pluginWorkDirectory)" ] diff --git a/Releasing.md b/Releasing.md index af43ec4ec..1f492ab09 100644 --- a/Releasing.md +++ b/Releasing.md @@ -7,18 +7,16 @@ For SwiftLint contributors, follow these steps to cut a release: * FabricSoftenerRule * Top Loading * Fresh Out Of The Dryer -1. Push new version: `make push_version "0.2.0: Tumble Dry"` 1. Make sure you have the latest stable Xcode version installed and `xcode-select`ed. -1. Create the pkg installer, framework zip, portable zip, - macos artifactbundle zip, and Linux zip: - `make release` +1. Release new version: `make release "0.2.0: Tumble Dry"` +1. Wait for the Docker CI job to finish then run: `make zip_linux_release` 1. Create a GitHub release: https://github.com/realm/SwiftLint/releases/new * Specify the tag you just pushed from the dropdown. * Set the release title to the new version number & release name. * Add the changelog section to the release description text box. * Upload the bazel tarball & SHA-256 signature, pkg installer, - framework zip, portable zip, macos artifactbundle zip, and Linux zip + portable zip, macos artifactbundle zip, and Linux zip you just built to the GitHub release binaries. * Click "Publish release". 1. Publish to Homebrew and CocoaPods trunk: `make publish` diff --git a/tools/update-artifact-bundle.sh b/tools/update-artifact-bundle.sh new file mode 100755 index 000000000..f02ce3f81 --- /dev/null +++ b/tools/update-artifact-bundle.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -euo pipefail + +readonly version="$1" +readonly artifactbundle="SwiftLintBinary-macos.artifactbundle.zip" +readonly checksum="$(shasum -a 256 "$artifactbundle" | cut -d " " -f1 | xargs)" + +sed -i '' \ + "s/.*\/releases\/download\/.*/ url: \"https:\/\/github.com\/realm\/SwiftLint\/releases\/download\/$version\/SwiftLintBinary-macos\.artifactbundle\.zip\",/g" \ + Package.swift + +sed -i '' \ + "s/.*checksum.*/ checksum: \"$checksum\",/g" \ + Package.swift