diff --git a/.github/workflows/gha_pull_request.yml b/.github/workflows/gha_pull_request.yml new file mode 100644 index 0000000..4416380 --- /dev/null +++ b/.github/workflows/gha_pull_request.yml @@ -0,0 +1,38 @@ +name: Pull Request + +on: + pull_request: + branches: [ master ] + +jobs: + danger: + runs-on: ubuntu-latest + name: "🚫 Run Danger" + steps: + - uses: actions/checkout@v1 + - run: npm install -g danger + - run: swift run danger-swift ci -c release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_SWIFT_GITHUB_TOKEN }} + LINUX_SOURCEKIT_LIB_PATH: /usr/share/swift/usr/lib + + linux: + runs-on: ubuntu-latest + name: "🐧 Linux Test & Verify" + steps: + - uses: actions/checkout@v1 + - run: npm install -g danger + - run: swift test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + macos: + runs-on: macos-11 + name: " MacOS Test & Verify" + steps: + - uses: actions/checkout@v1 + - run: npm install -g danger + - run: swift test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 330d167..acdb555 100644 --- a/.gitignore +++ b/.gitignore @@ -1,90 +1,6 @@ -# Xcode -# -# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore - -## User settings -xcuserdata/ - -## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) -*.xcscmblueprint -*.xccheckout - -## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) -build/ -DerivedData/ -*.moved-aside -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 - -## Obj-C/Swift specific -*.hmap - -## App packaging -*.ipa -*.dSYM.zip -*.dSYM - -## Playgrounds -timeline.xctimeline -playground.xcworkspace - -# Swift Package Manager -# -# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. -# Packages/ -# Package.pins -# Package.resolved -# *.xcodeproj -# -# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata -# hence it is not needed unless you have added a package configuration file to your project -# .swiftpm - -.build/ - -# CocoaPods -# -# We recommend against adding the Pods directory to your .gitignore. However -# you should judge for yourself, the pros and cons are mentioned at: -# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control -# -# Pods/ -# -# Add this line if you want to avoid checking in source code from the Xcode workspace -# *.xcworkspace - -# Carthage -# -# Add this line if you want to avoid checking in source code from Carthage dependencies. -# Carthage/Checkouts - -Carthage/Build/ - -# Accio dependency management -Dependencies/ -.accio/ - -# fastlane -# -# It is recommended to not store the screenshots in the git repo. -# Instead, use fastlane to re-generate the screenshots whenever they are needed. -# For more information about the recommended setup visit: -# https://docs.fastlane.tools/best-practices/source-control/#source-control - -fastlane/report.xml -fastlane/Preview.html -fastlane/screenshots/**/*.png -fastlane/test_output - -# Code Injection -# -# After new code Injection tools there's a generated folder /iOSInjectionProject -# https://github.com/johnno1962/injectionforxcode - -iOSInjectionProject/ +.DS_Store +/.build +build +/.swiftpm +/Packages +/*.xcodeproj diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..37c2d99 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +5.4 diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..a730e48 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,17 @@ +included: + - Sources + - Tests +excluded: + - Tests/**/XCTestManifests.swift # auto generated file +identifier_name: + excluded: + - ci + - id + - pr +line_length: + warning: 150 # Default 120 + error: 300 # Default 200 + ignores_comments: true + ignores_urls: true +disabled_rules: + - trailing_comma diff --git a/Dangerfile.swift b/Dangerfile.swift new file mode 100644 index 0000000..4f04985 --- /dev/null +++ b/Dangerfile.swift @@ -0,0 +1,39 @@ +import Danger +import Foundation + +let danger = Danger() + +if danger.git.createdFiles.count + danger.git.modifiedFiles.count - danger.git.deletedFiles.count > 300 { + warn("Big PR, try to keep changes smaller if you can") +} + +let swiftFilesWithCopyright = danger.git.createdFiles.filter { + $0.fileType == .swift && danger.utils.readFile($0).contains("// Created by") +} + +if swiftFilesWithCopyright.isEmpty == false { + let files = swiftFilesWithCopyright.joined(separator: ", ") + warn("In DangerSwiftCommitLint we don't include copyright headers, found them in: \(files)") +} + +let filesToLint = (danger.git.modifiedFiles + danger.git.createdFiles) + .filter { URL(fileURLWithPath: $0).pathExtension == "swift" } + +SwiftLint.lint(.files(filesToLint), inline: true) + +// Only run GitHub related checks when GitHub dsl is available. This allows `danger-swift local` to work. +guard let github = danger.github else { + warn("Unable to parse GitHub DSL response, the GitHub related checks will be skipped. (i.e. running `danger-swift local`).") + exit(0) +} + +// These checks only happen on a PR +let foundWIPMessageInTitle = github.pullRequest.title.contains("Work In Progress") + || github.pullRequest.title.contains("WIP") +let foundWIPLabel = github.issue.labels.contains { + $0.name.contains("Work In Progress") +} + +if foundWIPMessageInTitle || foundWIPLabel { + warn("PR is classed as Work in Progress") +} diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..06d602b --- /dev/null +++ b/Package.resolved @@ -0,0 +1,151 @@ +{ + "object": { + "pins": [ + { + "package": "Komondor", + "repositoryURL": "https://github.com/shibapm/Komondor", + "state": { + "branch": null, + "revision": "1bb467ad7ad57e94af82d73fa0fe063cb0b8ddd5", + "version": "1.1.0" + } + }, + { + "package": "Logger", + "repositoryURL": "https://github.com/shibapm/Logger", + "state": { + "branch": null, + "revision": "53c3ecca5abe8cf46697e33901ee774236d94cce", + "version": "0.2.3" + } + }, + { + "package": "OctoKit", + "repositoryURL": "https://github.com/nerdishbynature/octokit.swift", + "state": { + "branch": null, + "revision": "9521cdff919053868ab13cd08a228f7bc1bde2a9", + "version": "0.11.0" + } + }, + { + "package": "PackageConfig", + "repositoryURL": "https://github.com/shibapm/PackageConfig.git", + "state": { + "branch": null, + "revision": "bf90dc69fa0792894b08a0b74cf34029694ae486", + "version": "0.13.0" + } + }, + { + "package": "RequestKit", + "repositoryURL": "https://github.com/nerdishbynature/RequestKit.git", + "state": { + "branch": null, + "revision": "fd5e9e99aada7432170366c9e95967011ce13bad", + "version": "2.4.0" + } + }, + { + "package": "Rocket", + "repositoryURL": "https://github.com/shibapm/Rocket", + "state": { + "branch": null, + "revision": "51a77ce5fa66c42715c14dcc542c01cd7a60fb27", + "version": "1.2.0" + } + }, + { + "package": "ShellOut", + "repositoryURL": "https://github.com/JohnSundell/ShellOut.git", + "state": { + "branch": null, + "revision": "e1577acf2b6e90086d01a6d5e2b8efdaae033568", + "version": "2.3.0" + } + }, + { + "package": "SourceKitten", + "repositoryURL": "https://github.com/jpsim/SourceKitten.git", + "state": { + "branch": null, + "revision": "7f4be006fe73211b0fd9666c73dc2f2303ffa756", + "version": "0.31.0" + } + }, + { + "package": "danger-swift", + "repositoryURL": "https://github.com/danger/swift", + "state": { + "branch": null, + "revision": "f743dd1ed76f4ae99a39f5a7acb4cfd60c6aaa71", + "version": "3.11.0" + } + }, + { + "package": "swift-argument-parser", + "repositoryURL": "https://github.com/apple/swift-argument-parser.git", + "state": { + "branch": null, + "revision": "9564d61b08a5335ae0a36f789a7d71493eacadfc", + "version": "0.3.2" + } + }, + { + "package": "SwiftFormat", + "repositoryURL": "https://github.com/nicklockwood/SwiftFormat", + "state": { + "branch": null, + "revision": "a9bdfd2548ebe518a693a5c6341d27c42b7e7a0a", + "version": "0.48.11" + } + }, + { + "package": "SwiftLint", + "repositoryURL": "https://github.com/realm/SwiftLint", + "state": { + "branch": null, + "revision": "180d94132758dd183124ab1e63d6aa8e10023ec2", + "version": "0.43.1" + } + }, + { + "package": "SwiftShell", + "repositoryURL": "https://github.com/kareman/SwiftShell", + "state": { + "branch": null, + "revision": "a6014fe94c3dbff0ad500e8da4f251a5d336530b", + "version": "5.1.0-beta.1" + } + }, + { + "package": "SwiftyTextTable", + "repositoryURL": "https://github.com/scottrhoyt/SwiftyTextTable.git", + "state": { + "branch": null, + "revision": "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3", + "version": "0.9.0" + } + }, + { + "package": "SWXMLHash", + "repositoryURL": "https://github.com/drmohundro/SWXMLHash.git", + "state": { + "branch": null, + "revision": "9183170d20857753d4f331b0ca63f73c60764bf3", + "version": "5.0.2" + } + }, + { + "package": "Version", + "repositoryURL": "https://github.com/mxcl/Version", + "state": { + "branch": null, + "revision": "200046c93f6d5d78a6d72bfd9c0b27a95e9c0a2b", + "version": "1.2.0" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..47d7b0a --- /dev/null +++ b/Package.swift @@ -0,0 +1,50 @@ +// swift-tools-version:5.4 + +import PackageDescription + +let package = Package( + name: "DangerSwiftCommitLint", + products: [ + .library(name: "DangerSwiftCommitLint", targets: ["DangerSwiftCommitLint"]), + .library(name: "DangerDeps", type: .dynamic, targets: ["DangerDependencies"]), // dev + ], + dependencies: [ + .package(name: "danger-swift", url: "https://github.com/danger/swift", from: "3.0.0"), + // Dev dependencies. + .package(url: "https://github.com/shibapm/Komondor", from: "1.0.0"), // dev + .package(url: "https://github.com/shibapm/Rocket", from: "1.2.0"), // dev + .package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.48.0"), // dev + .package(url: "https://github.com/realm/SwiftLint", from: "0.43.0"), // dev + ], + targets: [ + .target(name: "DangerDependencies", dependencies: [.product(name: "Danger", package: "danger-swift")]), // dev + .target(name: "DangerSwiftCommitLint", dependencies: [.product(name: "Danger", package: "danger-swift")]), + .testTarget( + name: "DangerSwiftCommitLintTests", + dependencies: [ + "DangerSwiftCommitLint", + .product(name: "DangerFixtures", package: "danger-swift"), + ] + ), + ] +) + +#if canImport(PackageConfig) + import PackageConfig + + let config = PackageConfiguration([ + "komondor": [ + "pre-commit": [ + "swift test --generate-linuxmain", + "swift run swiftformat .", + "swift run swiftlint autocorrect --path Sources/", + "git add .", + ], + ], + "rocket": [ + "after": [ + "push", + ], + ], + ]).write() +#endif diff --git a/Sources/DangerDependencies/Fake.swift b/Sources/DangerDependencies/Fake.swift new file mode 100644 index 0000000..d39a25d --- /dev/null +++ b/Sources/DangerDependencies/Fake.swift @@ -0,0 +1 @@ +// Intentionally left empty diff --git a/Sources/DangerSwiftCommitLint/DangerSwiftCommitLint.swift b/Sources/DangerSwiftCommitLint/DangerSwiftCommitLint.swift new file mode 100644 index 0000000..e225d34 --- /dev/null +++ b/Sources/DangerSwiftCommitLint/DangerSwiftCommitLint.swift @@ -0,0 +1,4 @@ +import Danger +import Foundation + +final class DangerSwiftCommitLint {} diff --git a/Tests/DangerSwiftCommitLintTests/DangerSwiftCommitLintTests.swift b/Tests/DangerSwiftCommitLintTests/DangerSwiftCommitLintTests.swift new file mode 100644 index 0000000..ee9b114 --- /dev/null +++ b/Tests/DangerSwiftCommitLintTests/DangerSwiftCommitLintTests.swift @@ -0,0 +1,6 @@ +@testable import DangerSwiftCommitLint +import XCTest + +final class DangerSwiftCommitLintTests: XCTestCase { + func testDummy() {} +} diff --git a/Tests/DangerSwiftCommitLintTests/XCTestManifests.swift b/Tests/DangerSwiftCommitLintTests/XCTestManifests.swift new file mode 100644 index 0000000..4b735f8 --- /dev/null +++ b/Tests/DangerSwiftCommitLintTests/XCTestManifests.swift @@ -0,0 +1,18 @@ +#if !canImport(ObjectiveC) + import XCTest + + extension DangerSwiftCommitLintTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__DangerSwiftCommitLintTests = [ + ("testDummy", testDummy), + ] + } + + public func __allTests() -> [XCTestCaseEntry] { + [ + testCase(DangerSwiftCommitLintTests.__allTests__DangerSwiftCommitLintTests), + ] + } +#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..dad82b0 --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,8 @@ +import XCTest + +import DangerSwiftCommitLintTests + +var tests = [XCTestCaseEntry]() +tests += DangerSwiftCommitLintTests.__allTests() + +XCTMain(tests)