diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d33c42a..7b1f7f8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,33 +1,10 @@ -name: CI +name: Main on: push: - branches: [main, versions] - pull_request: branches: [main] jobs: - cancel-previous-runs: - runs-on: ubuntu-latest - - steps: - - name: Cancel previous runs of this workflow on same branch - uses: rokroskar/workflow-run-cleanup-action@v0.2.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - anylint: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Install AnyLint - run: brew tap Flinesoft/AnyLint https://github.com/Flinesoft/AnyLint.git && brew install anylint - - - name: Run AnyLint - run: anylint - test-linux: runs-on: ubuntu-latest diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..19021c0 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,45 @@ +name: Pull Request + +on: + pull_request: + branches: [main] + +jobs: + cancel-previous-runs: + runs-on: ubuntu-latest + + steps: + - name: Cancel previous runs of this workflow on same branch + uses: rokroskar/workflow-run-cleanup-action@v0.2.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + anylint: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install AnyLint + run: brew tap Flinesoft/AnyLint https://github.com/Flinesoft/AnyLint.git && brew install anylint + + - name: Run AnyLint + run: anylint + + test-linux: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: swift test -v --enable-test-discovery + + test-macos: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: swift test -v --enable-code-coverage diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b005ab..56babd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se ## [Unreleased] ### Added -- YAML-based configuration file. Supportts `FilePaths` and `FileContents` as well as `CustomScripts` for full feature parity with previous Swift-based configuration file. +- YAML-based configuration file. Supports `FilePaths` and `FileContents` as well as `CustomScripts` for full feature parity with previous Swift-based configuration file. Author: [Cihat Gündüz](https://github.com/Jeehut) ### Changed - Migrated from jakeheis/SwiftCLI to apple/swift-argument-parser for improved reliability & reduced maintenance. @@ -31,7 +31,7 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se ### Removed - Swift-based configuration file support removed in favor of YAML-based configuration. All features supported via the Swift file still supported via YAML file. See README.md for more details. Parameters were not renamed to keep migration simple. Author: [Cihat Gündüz](https://github.com/Jeehut) -- Support for Swift versions below 5.5 was dropped to make use of the latest improvements in concurrency & SwiftPM plugin system. Use version `0.8.2` if you need to stay on lower Swift versions. +- Support for Swift versions below 5.4 was dropped to make use of the latest improvements in Swift & SwiftPM. Use version `0.8.2` if you need to stay on lower Swift versions. Author: [Cihat Gündüz](https://github.com/Jeehut) ### Fixed - Issues with paths due to Swift scripting not being as easy to use now fixed by moving over to YAML-based configuration. For custom scripts, responsibility is moved to the user side by allowing to specify the exact command to run. diff --git a/LICENSE b/LICENSE index b1efe33..0f84aa7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Flinesoft (alias Cihat Gündüz) +Copyright (c) 2020-2021 Flinesoft (alias Cihat Gündüz) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Package.swift b/Package.swift index dfa877d..8bebfe8 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.5 +// swift-tools-version:5.3 import PackageDescription let package = Package( @@ -44,7 +44,7 @@ let package = Package( .product(name: "OrderedCollections", package: "swift-collections"), ] ), - .executableTarget( + .target( name: "Commands", dependencies: [ "Checkers", diff --git a/Sources/Checkers/Helpers/FilesSearch.swift b/Sources/Checkers/Helpers/FilesSearch.swift index 54e193a..0a47633 100644 --- a/Sources/Checkers/Helpers/FilesSearch.swift +++ b/Sources/Checkers/Helpers/FilesSearch.swift @@ -33,6 +33,7 @@ public final class FilesSearch { excludeFilters: excludeFilters ) + // AnyLint.skipHere: IfAsGuard if let cachedFilePaths: [String] = cachedFilePaths[searchOptions] { return cachedFilePaths } diff --git a/Sources/Commands/AnyLint.swift b/Sources/Commands/AnyLint.swift index 7f2556f..18059c1 100644 --- a/Sources/Commands/AnyLint.swift +++ b/Sources/Commands/AnyLint.swift @@ -1,7 +1,6 @@ import Foundation import ArgumentParser -@main /// The entry point of the toot, defines the `anylint` primary command. Sets up any sub commands like `init` or `lint`. struct AnyLint: ParsableCommand { static var configuration: CommandConfiguration = .init( diff --git a/Sources/Commands/main.swift b/Sources/Commands/main.swift new file mode 100644 index 0000000..dba66a6 --- /dev/null +++ b/Sources/Commands/main.swift @@ -0,0 +1,5 @@ +import ArgumentParser + +// TODO: [cg_2021-08-15] remove in favor of `@main` in AnyLint struct once GitHub has macos-11 available: +// https://github.com/actions/virtual-environments/issues/2486 +AnyLint.main() diff --git a/Sources/Core/Severity.swift b/Sources/Core/Severity.swift index cca08aa..a1c07ad 100644 --- a/Sources/Core/Severity.swift +++ b/Sources/Core/Severity.swift @@ -1,5 +1,4 @@ import Foundation -import AppKit /// Defines the severity of a lint check. public enum Severity: String, CaseIterable, Codable { diff --git a/lint.swift b/lint.swift index 4265c8a..cb0499a 100755 --- a/lint.swift +++ b/lint.swift @@ -1,5 +1,5 @@ #!/usr/local/bin/swift-sh -import AnyLint // . +import AnyLint // @Flinesoft import Utility import ShellOut // @JohnSundell @@ -440,49 +440,6 @@ try Lint.logSummaryAndExit(arguments: CommandLine.arguments) { ] ) - // MARK: LinuxMainUpToDate - try Lint.customCheck(checkInfo: "LinuxMainUpToDate: The tests in Tests/LinuxMain.swift should be up-to-date.") { checkInfo in - var violations: [Violation] = [] - - let linuxMainFilePath = "Tests/LinuxMain.swift" - let linuxMainContentsBeforeRegeneration = try! String(contentsOfFile: linuxMainFilePath) - - let sourceryDirPath = ".sourcery" - let testsDirPath = "Tests/\(projectName)Tests" - let stencilFilePath = "\(sourceryDirPath)/LinuxMain.stencil" - let generatedLinuxMainFilePath = "\(sourceryDirPath)/LinuxMain.generated.swift" - - let sourceryInstallPath = try? shellOut(to: "which", arguments: ["sourcery"]) - guard sourceryInstallPath != nil else { - log.message( - "Skipped custom check \(checkInfo) – requires Sourcery to be installed, download from: https://github.com/krzysztofzablocki/Sourcery", - level: .warning - ) - return [] - } - - try! shellOut(to: "sourcery", arguments: ["--sources", testsDirPath, "--templates", stencilFilePath, "--output", sourceryDirPath]) - let linuxMainContentsAfterRegeneration = try! String(contentsOfFile: generatedLinuxMainFilePath) - - // move generated file to LinuxMain path to update its contents - try! shellOut(to: "mv", arguments: [generatedLinuxMainFilePath, linuxMainFilePath]) - - if linuxMainContentsBeforeRegeneration != linuxMainContentsAfterRegeneration { - violations.append( - Violation( - checkInfo: checkInfo, - filePath: linuxMainFilePath, - appliedAutoCorrection: AutoCorrection( - before: linuxMainContentsBeforeRegeneration, - after: linuxMainContentsAfterRegeneration - ) - ) - ) - } - - return violations - } - // MARK: Logger try Lint.checkFileContents( checkInfo: "Logger: Don't use `print` – use `log.message` instead.",