Add Dangerfile.swift

Signed-off-by: Joseph Mattello <mail@joemattiello.com>
This commit is contained in:
Joseph Mattello
2022-12-30 17:14:26 -05:00
committed by Joe Mattiello
parent 17640fe6cf
commit 977a452605
5 changed files with 384 additions and 0 deletions

13
.github/workflows/danger.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
name: "Danger Swift"
on: [pull_request]
jobs:
build:
name: Danger JS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Danger Swift
uses: danger/swift@2.0.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2
.gitignore vendored
View File

@@ -35,6 +35,8 @@ xcuserdata
## AppCode specific
.idea/
.build
Payload/
SideStore.ipa
Dependencies/.*-prebuilt-fetch-*

137
Dangerfile.swift Normal file
View File

@@ -0,0 +1,137 @@
import Danger
import Foundation
// import SwiftLint
let danger = Danger()
// fileImport: DangerfileExtensions/ChangelogCheck.swift
// checkChangelog()
// Add a CHANGELOG entry for app changes
let hasChangelog = danger.git.modifiedFiles.contains("Changelog.md")
let isTrivial = (danger.github.pullRequest.body + danger.github.pullRequest.title).contains("#trivial")
if (!hasChangelog && !isTrivial) {
warn("Please add a changelog entry for your changes.")
}
// PR Too large
if danger.git.createdFiles.count + danger.git.modifiedFiles.count - danger.git.deletedFiles.count > 600 {
warn("Big PR, try to keep changes smaller if you can")
}
// Check copyright
let swiftFilesWithCopyright = danger.git.createdFiles.filter {
$0.fileType == .swift
&& danger.utils.readFile($0).contains("// Created by")
}
if !swiftFilesWithCopyright.isEmpty {
let files = swiftFilesWithCopyright.joined(separator: ", ")
warn("In Danger JS we don't include copyright headers, found them in: \(files)")
}
// # This is swiftlint plugin. More info: https://github.com/ashfurrow/danger-swiftlint
// #
// # This lints all Swift files and leave comments in PR if
// # there is any issue with linting
let filesToLint = (danger.git.modifiedFiles + danger.git.createdFiles) // .filter { !$0.contains("Documentation/") }
SwiftLint.lint(.files(filesToLint), inline: true)
// Support running via `danger local`
if danger.github != nil {
// These checks only happen on a PR
if danger.github.pullRequest.title.contains("WIP") {
warn("PR is classed as Work in Progress")
}
}
if github.pr_title.contains("WIP") {
warn("PR is classed as Work in Progress")
}
if git.commits.any {
return $0.message.contains("Merge branch '\(github.branch_for_base)'")
} {
fail("Please rebase to get rid of the merge commits in this PR ")
}
if github.pr_body.length > 1000 {
warn("PR body is too long")
}
if github.pr_body.length < 5 {
fail("PR body is too short")
}
let has_app_changes = !git.modified_files.any { $0.contains("AltStore") }
let has_altstorecore_changes = !git.modified_files.any { $0.contains("AltStoreCore") }
// let has_support_test_changes = !git.modified_files.any { $0.contains("AltStoreCore
// Tests") }
// let has_library_changes = !git.modified_files.any { $0.contains("PVLibrary") }
// let has_library_test_changes = !git.modified_files.any { $0.contains("PVLibrary Tests") }
// If changes are more than 10 lines of code, tests need to be updated too
// if (has_core_changes && !has_core_test_changes) ||
// (has_coreui_changes && !has_coreui_test_changes)) &&
// git.lines_of_code > 10 {
// fail("Tests were not updated", sticky: false)
// }
// Info.plist file shouldn't change often. Leave warning if it changes.
let is_plist_change = git.modified_files.any { $0.contains("Info.plist") }
if !is_plist_change
// warn "A Plist was changed"
warn("Plist changed, don't forget to localize your plist values")
end
// gemfile_updated = !git.modified_files.grep(/Gemfile$/).empty?
// # Leave warning, if Gemfile changes
// if gemfile_updated
// warn "The `Gemfile` was updated"
// end
// import xcodebuild
// xcodebuild.json_file = "./fastlane/reports/xcpretty-json-formatter-results.json"
// xcodebuild.parse_warnings() // returns number of warnings
// xcodebuild.parse_errors() // returns number of errors
// // xcodebuild.parse_errors(errors: danger.github.pull_request.body)
// xcodebuild.parse_tests() // returns number of test failures
// xcodebuild.perfect_build() // returns a bool indicating if the build was perfect
func checkSwiftVersions() {
SwiftChecks.check(
files: [
VersionFile(
path: "./\(projectName).xcodeproj/project.pbxproj",
interpreter: .regex("SWIFT_VERSION = (.*);")
),
VersionFile(
path: "./\(projectName).podspec",
interpreter: .regex("\\.swift_version\\s*=\\s*\"(.*)\"")
),
],
versionKind: "Swift"
)
}
func checkProjectVersions() {
SwiftChecks.check(
fileProviders: [
InfoPlistFileProvider(
discoveryMethod: .searchDirectory("./Sources", fileNames: ["Info.plist"]),
plistKey: .versionNumber,
projectFilePath: "./\(projectName).xcodeproj"
),
],
files: [
VersionFile(path: "./\(projectName).podspec", interpreter: .regex("\\.version\\s*=\\s*\"(.*)\"")),
],
versionKind: "framework"
)
}
// checkProjectVersions()
// checkSwiftVersions

130
Package.resolved Normal file
View File

@@ -0,0 +1,130 @@
{
"pins" : [
{
"identity" : "collectionconcurrencykit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git",
"state" : {
"revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95",
"version" : "0.2.0"
}
},
{
"identity" : "logger",
"kind" : "remoteSourceControl",
"location" : "https://github.com/shibapm/Logger",
"state" : {
"revision" : "53c3ecca5abe8cf46697e33901ee774236d94cce",
"version" : "0.2.3"
}
},
{
"identity" : "octokit.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nerdishbynature/octokit.swift",
"state" : {
"revision" : "f762f1566f7cd0e683b9329f169c28ab6ef993cc",
"version" : "0.12.0"
}
},
{
"identity" : "requestkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nerdishbynature/RequestKit.git",
"state" : {
"revision" : "8b0258ea2a4345cbcac90509b764faacea12efb0",
"version" : "3.2.1"
}
},
{
"identity" : "sourcekitten",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/SourceKitten.git",
"state" : {
"revision" : "fc12c0f182c5cf80781dd933b17a82eb98bd7c61",
"version" : "0.33.1"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "fddd1c00396eed152c45a46bea9f47b98e59301d",
"version" : "1.2.0"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state" : {
"revision" : "f29e2014f6230cf7d5138fc899da51c7f513d467",
"version" : "1.10.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "a2d31e8880224f5a619f24bf58c122836faf99ff"
}
},
{
"identity" : "swiftformat",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nicklockwood/SwiftFormat",
"state" : {
"revision" : "34cd9dd87b78048ce0d623a9153f9bf260ad6590",
"version" : "0.50.7"
}
},
{
"identity" : "swiftlint",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Realm/SwiftLint",
"state" : {
"branch" : "main",
"revision" : "470d471e5100240d160b644ffba8ed6485c891e2"
}
},
{
"identity" : "swiftytexttable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/scottrhoyt/SwiftyTextTable.git",
"state" : {
"revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
"version" : "0.9.0"
}
},
{
"identity" : "swxmlhash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/drmohundro/SWXMLHash.git",
"state" : {
"revision" : "4d0f62f561458cbe1f732171e625f03195151b60",
"version" : "7.0.1"
}
},
{
"identity" : "version",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mxcl/Version",
"state" : {
"revision" : "1fe824b80d89201652e7eca7c9252269a1d85e25",
"version" : "2.0.1"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams.git",
"state" : {
"revision" : "01835dc202670b5bb90d07f3eae41867e9ed29f6",
"version" : "5.0.1"
}
}
],
"version" : 2
}

102
Package.swift Normal file
View File

@@ -0,0 +1,102 @@
// swift-tools-version:5.6
import PackageDescription
// Version number can be found in Source/Danger/Danger.swift
// switch to false when release
let isDevelop = true
let devProducts: [Product] = isDevelop
? [
.library(name: "DangerDeps", type: .dynamic, targets: ["Danger-Swift"])
] : []
let devDependencies: [Package.Dependency] = isDevelop
? [
// .package(url: "https://github.com/shibapm/Komondor", from: "1.1.4"),
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.50.7"),
.package(url: "https://github.com/Realm/SwiftLint", branch: "main"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.10.0"),
// .package(url: "https://github.com/shibapm/Rocket", from: "1.2.1")
] : []
let devTargets: [Target] = isDevelop
? [
.testTarget(name: "DangerTests",
dependencies: [
"Danger",
"DangerFixtures",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
]),
.testTarget(name: "RunnerLibTests",
dependencies: [
"RunnerLib",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
], exclude: ["__Snapshots__"]),
.testTarget(name: "DangerDependenciesResolverTests",
dependencies: [
"DangerDependenciesResolver",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
],
exclude: ["__Snapshots__"]),
]
: []
let package = Package(
name: "danger-swift",
products: [
.library(name: "Danger", targets: ["Danger"]),
.library(name: "DangerFixtures", targets: ["DangerFixtures"]),
.executable(name: "danger-swift", targets: ["Runner"]),
] + devProducts,
dependencies: [
.package(url: "https://github.com/shibapm/Logger", from: "0.1.0"),
.package(url: "https://github.com/mxcl/Version", from: "2.0.1"),
.package(name: "OctoKit", url: "https://github.com/nerdishbynature/octokit.swift", from: "0.12.0"),
] + devDependencies,
targets: [
.target(name: "Danger-Swift", dependencies: ["Danger"], plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]),
.target(name: "DangerShellExecutor"),
.target(name: "DangerDependenciesResolver", dependencies: ["DangerShellExecutor", "Version", "Logger"]),
.target(name: "Danger", dependencies: ["OctoKit", "Logger", "DangerShellExecutor"]),
.target(name: "RunnerLib", dependencies: ["Logger", "DangerShellExecutor", "Version"]),
.executableTarget(name: "Runner", dependencies: ["RunnerLib", "Logger", "DangerDependenciesResolver"]),
.target(name: "DangerFixtures", dependencies: ["Danger"]),
] + devTargets
)
// #if canImport(PackageConfig)
// import PackageConfig
// let config = PackageConfiguration([
// "komondor": [
// "pre-push": "swift test",
// "pre-commit": [
// "swift test",
// "swift test --generate-linuxmain",
// "swift run swiftformat .",
// "swift run swiftlint autocorrect --path Sources/",
// "git add ."
// ]
// ],
// "rocket": [
// "pre_release_checks": [
// "clean_git"
// ],
// "steps": [
// "Scripts/update_makefile.sh",
// "Scripts/update_danger_version.sh",
// "Scripts/update_changelog.sh",
// "Scripts/change_is_develop.sh false",
// "git_add",
// "commit",
// "tag",
// "push",
// "Scripts/change_is_develop.sh true",
// "git_add",
// ["commit": ["message": "Enable dev depdendencies"]],
// "push",
// "Scripts/create_homebrew_tap.sh"
// ]
// ]
// ]).write()
// #endif