Use a binary target for the build tool plugin (#4603)

* Use a binary target for the build tool plugin

* Merge `push_version` and `release` make commands

Instead of running `make push_version "0.2.0: Tumble Dry"` and then
`make release`, now run `make release "0.2.0: Tumble Dry"`, which will
build the release artifacts and update/push the new version to GitHub.

This allows the artifacts to use the new version, update the artifact
bundle checksum in the package manifest, then tag the release.

The Releasing.md instructions were updated to reflect this new workflow.

* Add `SwiftLintSourcePlugin` source plugin for SwiftPM

* Add changelog entry

* Remove SwiftLintSourcePlugin for now

* Build from Source on Linux

* Use a lower-level method of checking if a file is accessible

This shouldn’t trigger sandbox violations, I hope…

* Prevent an infinite recursion of the filesystem root

* Remove unnecessary logging

* Quieten the output so that Xcode only prints violations

* Break up comment to avoid line length warning

* Fix capitalization of Glibc import

Co-authored-by: JP Simard <jp@jpsim.com>
This commit is contained in:
Tony Arnold 2022-11-30 10:10:47 +11:00 committed by GitHub
parent 9cb1069090
commit ab143685a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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"
)
]
)

View File

@ -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
}
}

View File

@ -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)"
]

View File

@ -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`

15
tools/update-artifact-bundle.sh Executable file
View File

@ -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