Skip to content

Commit

Permalink
Merge pull request #52 from clutter/spm
Browse files Browse the repository at this point in the history
Add SPM Support
  • Loading branch information
MichaelM1177 authored Jul 29, 2022
2 parents c25aa04 + 4191252 commit 49f21e7
Show file tree
Hide file tree
Showing 62 changed files with 1,119 additions and 134 deletions.
64 changes: 50 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,66 @@
version: 2
jobs:
build-and-test:
build-and-test-pods:
macos:
xcode: 12.5.1
working_directory: /Users/distiller/project
environment:
FL_OUTPUT_DIR: /Users/distiller/project/Example/fastlane/test_output
FASTLANE_LANE: test
xcode: 13.4.1
shell: /bin/bash --login -o pipefail
steps:
- checkout
- run: mkdir $FL_OUTPUT_DIR
- run: bundle install
- run:
name: Fastlane
command: cd Example; bundle exec fastlane $FASTLANE_LANE; cd --
- run:
command: cp $FL_OUTPUT_DIR/report.junit $FL_OUTPUT_DIR/results.xml
when: always
command: bundle exec fastlane ios test_pod
- store_test_results:
path: test_output/report.xml
- store_artifacts:
path: /Users/distiller/project/Example/fastlane
path: /tmp/test-results
destination: scan-test-results
- store_artifacts:
path: ~/Library/Logs/scan
destination: scan-logs
build-and-test-spm:
macos:
xcode: 13.4.1
shell: /bin/bash --login -o pipefail
steps:
- checkout
- run: bundle install
- run:
name: Fastlane
command: bundle exec fastlane ios test_spm
- store_test_results:
path: /Users/distiller/project/Example/fastlane/test_output
path: test_output/report.xml
- store_artifacts:
path: /tmp/test-results
destination: scan-test-results
- store_artifacts:
path: ~/Library/Logs/scan
destination: scan-logs
danger:
macos:
xcode: 13.4.1
working_directory: /Users/distiller/project
shell: /bin/bash --login -o pipefail
steps:
- run:
name: Setup Environment Variables
command: |
echo 'export PATH=~/.mint/bin:$PATH' >> $BASH_ENV
- checkout
- run: brew update
- run: brew install mint
- run: mint bootstrap --link --overwrite y
- run: swiftlint version
- run: brew tap danger/tap
- run: brew install danger/tap/danger-swift
- run:
name: Danger
command: danger-swift ci

workflows:
version: 2
build-test-adhoc:
jobs:
- build-and-test
- build-and-test-pods
- build-and-test-spm
- danger
15 changes: 12 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# OS X
.DS_Store
.DS*

# Xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
*.mode*
!default.mode1v3
*.mode2v3
!default.mode2v3
Expand All @@ -18,9 +18,14 @@ profile
DerivedData
*.hmap
*.ipa
**/*.xcodeproj/*.mode*
**/*.xcodeproj/*.pbxuser
**/*.xcodeproj/*.xcworkspace
**/*.xcodeproj/xcuserdata
**/*.xcworkspace/xcuserdata

# Pods
/Example/Pods/*
**/Pods/*

# Bundler
.bundle
Expand All @@ -29,3 +34,7 @@ DerivedData
fastlane/report.xml
fastlane/test_output/report.html
fastlane/test_output/report.junit

# SPM
.swiftpm/*

40 changes: 40 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
disabled_rules: # rule identifiers to exclude from running
- todo
- line_length
- large_tuple
opt_in_rules:
- force_unwrapping

custom_rules:
weak_root_coordinator:
name: "Weak Root Coordinator"
message: "Root coordinators should be weak to avoid reference cycles."
regex: "(?<!weak )var rootCoordinator: RootCoordinator\\?(?! \\{ get (set )?\\})"
file_length:
warning: 600
identifier_name:
min_length: # only min_length
error: 2 # only error
excluded: # excluded via string array
- id
- f
- s
- i
- j
- x
- y
- vc
- to
function_body_length:
- 60
- 60
nesting:
type_level:
warning: 2
private_over_fileprivate:
validate_extensions: true

excluded:
- Pods/**
- Example/PodApp/Pods/**
- Sources/SplitScreenScanner/Classes/ScannerStyleKit.swift
98 changes: 98 additions & 0 deletions Dangerfile.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import Foundation
import Danger

// MARK: Helper methods

func validateTitleAllowsMerging(for pullRequest: GitHub.PullRequest) throws {
let range = NSRange(pullRequest.title.startIndex..., in: pullRequest.title)

let wipRegex = try NSRegularExpression(pattern: "\\bWIP\\b", options: .caseInsensitive)
if wipRegex.firstMatch(in: pullRequest.title, range: range) != nil {
print("Pull request title contains “WIP”.")
}

let doNotMergeRegex = try NSRegularExpression(pattern: "\\bdo not merge\\b", options: .caseInsensitive)
if doNotMergeRegex.firstMatch(in: pullRequest.title, range: range) != nil {
print("Pull request title contains “do not merge”.")
}
}

func validateMessage(for ghCommit: GitHub.Commit, doesNotHavePrefixes prefixes: [String]) {
let commitMessage = ghCommit.commit.message.lowercased()
for prefix in prefixes where commitMessage.hasPrefix(prefix.lowercased()) {
fail("Commit message \(ghCommit.sha) begins with `\(prefix)`. Squash before merging.")
}
}

func messageIsGenerated(for ghCommit: GitHub.Commit) -> Bool {
guard let firstWord = ghCommit.commit.message.components(separatedBy: " ").first else {
return false
}
return firstWord == "Merge" || firstWord == "Revert" || firstWord == "fixup!" || firstWord == "squash!"
}

/// Fails if the commit’s message does not satisfy Chris Beams’s
/// [“The seven rules of a great Git commit message”](https://chris.beams.io/posts/git-commit/).
func validateMessageIsGreat(for ghCommit: GitHub.Commit) {
guard !messageIsGenerated(for: ghCommit) else { return }

let messageComponents = ghCommit.commit.message.components(separatedBy: "\n")
let title = messageComponents[0]

// Rule 1
if messageComponents.count > 1 {
let separator = messageComponents[1]
if !separator.isEmpty {
fail("Commit message \(ghCommit.sha) is missing a blank line between title and body.")
}
}

// Rule 2
if title.count > 50 {
fail("Commit title \(ghCommit.sha) is \(title.count) characters long (title should be limited to 50 characters).")
}

// Rule 3
if title.first != title.capitalized.first {
fail("Commit title \(ghCommit.sha) is not capitalized.")
}

// Rule 4
if title.hasSuffix(".") {
fail("Commit title \(ghCommit.sha) ends with a period.")
}

// Rule 5
// Use the imperative mood in the subject line
// Not validated here

// Rule 6
let body = messageComponents.dropFirst()
let lineNumbers = body.indices.map({ $0 + 1 })
for (lineNumber, line) in zip(lineNumbers, body) where line.count > 72 {
fail("Commit message \(ghCommit.sha) line \(lineNumber) is \(line.count) characters long (body should be wrapped at 72 characters).")
}

// Rule 7
// Use the body to explain what and why vs. how
// Not validated here
}

// MARK: - Validations

let danger = Danger()
let pullRequest = danger.github.pullRequest

try validateTitleAllowsMerging(for: pullRequest)

let unmergeablePrefixes = ["fixup!", "squash!", "WIP"]
danger.github.commits.forEach {
validateMessage(for: $0, doesNotHavePrefixes: unmergeablePrefixes)
validateMessageIsGreat(for: $0)
}

if let additions = pullRequest.additions, let deletions = pullRequest.deletions, additions < deletions {
message("🎉 This PR removes more code than it adds! (\(additions - deletions) net lines)")
}

SwiftLint.lint(inline: true, directory: "Session")
7 changes: 7 additions & 0 deletions Example/PodApp/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
platform :ios, '14.0'
use_frameworks!

pod 'SplitScreenScanner', :path => '../..'

target 'SplitScreenScanner_Example'
target 'SplitScreenScanner_Tests'
23 changes: 23 additions & 0 deletions Example/PodApp/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PODS:
- Sections (0.8.0)
- SplitScreenScanner (10.0.0):
- Sections

DEPENDENCIES:
- SplitScreenScanner (from `../..`)

SPEC REPOS:
trunk:
- Sections

EXTERNAL SOURCES:
SplitScreenScanner:
:path: "../.."

SPEC CHECKSUMS:
Sections: efc268a207d0e7afba82d2a0efd6cdf61872b5d4
SplitScreenScanner: 14f7388b33bb57afc2dfd1eab6af0bd18a45b9a2

PODFILE CHECKSUM: a50e47e37e36a517f8de6ae75d836fb0fdfdecfd

COCOAPODS: 1.8.4
Loading

0 comments on commit 49f21e7

Please sign in to comment.