Skip to content

Commit 49f21e7

Browse files
authored
Merge pull request #52 from clutter/spm
Add SPM Support
2 parents c25aa04 + 4191252 commit 49f21e7

62 files changed

Lines changed: 1119 additions & 134 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,66 @@
11
version: 2
22
jobs:
3-
build-and-test:
3+
build-and-test-pods:
44
macos:
5-
xcode: 12.5.1
6-
working_directory: /Users/distiller/project
7-
environment:
8-
FL_OUTPUT_DIR: /Users/distiller/project/Example/fastlane/test_output
9-
FASTLANE_LANE: test
5+
xcode: 13.4.1
106
shell: /bin/bash --login -o pipefail
117
steps:
128
- checkout
13-
- run: mkdir $FL_OUTPUT_DIR
149
- run: bundle install
1510
- run:
1611
name: Fastlane
17-
command: cd Example; bundle exec fastlane $FASTLANE_LANE; cd --
18-
- run:
19-
command: cp $FL_OUTPUT_DIR/report.junit $FL_OUTPUT_DIR/results.xml
20-
when: always
12+
command: bundle exec fastlane ios test_pod
13+
- store_test_results:
14+
path: test_output/report.xml
2115
- store_artifacts:
22-
path: /Users/distiller/project/Example/fastlane
16+
path: /tmp/test-results
17+
destination: scan-test-results
18+
- store_artifacts:
19+
path: ~/Library/Logs/scan
20+
destination: scan-logs
21+
build-and-test-spm:
22+
macos:
23+
xcode: 13.4.1
24+
shell: /bin/bash --login -o pipefail
25+
steps:
26+
- checkout
27+
- run: bundle install
28+
- run:
29+
name: Fastlane
30+
command: bundle exec fastlane ios test_spm
2331
- store_test_results:
24-
path: /Users/distiller/project/Example/fastlane/test_output
32+
path: test_output/report.xml
33+
- store_artifacts:
34+
path: /tmp/test-results
35+
destination: scan-test-results
36+
- store_artifacts:
37+
path: ~/Library/Logs/scan
38+
destination: scan-logs
39+
danger:
40+
macos:
41+
xcode: 13.4.1
42+
working_directory: /Users/distiller/project
43+
shell: /bin/bash --login -o pipefail
44+
steps:
45+
- run:
46+
name: Setup Environment Variables
47+
command: |
48+
echo 'export PATH=~/.mint/bin:$PATH' >> $BASH_ENV
49+
- checkout
50+
- run: brew update
51+
- run: brew install mint
52+
- run: mint bootstrap --link --overwrite y
53+
- run: swiftlint version
54+
- run: brew tap danger/tap
55+
- run: brew install danger/tap/danger-swift
56+
- run:
57+
name: Danger
58+
command: danger-swift ci
2559

2660
workflows:
2761
version: 2
2862
build-test-adhoc:
2963
jobs:
30-
- build-and-test
64+
- build-and-test-pods
65+
- build-and-test-spm
66+
- danger

.gitignore

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# OS X
2-
.DS_Store
2+
.DS*
33

44
# Xcode
55
build/
66
*.pbxuser
77
!default.pbxuser
8-
*.mode1v3
8+
*.mode*
99
!default.mode1v3
1010
*.mode2v3
1111
!default.mode2v3
@@ -18,9 +18,14 @@ profile
1818
DerivedData
1919
*.hmap
2020
*.ipa
21+
**/*.xcodeproj/*.mode*
22+
**/*.xcodeproj/*.pbxuser
23+
**/*.xcodeproj/*.xcworkspace
24+
**/*.xcodeproj/xcuserdata
25+
**/*.xcworkspace/xcuserdata
2126

2227
# Pods
23-
/Example/Pods/*
28+
**/Pods/*
2429

2530
# Bundler
2631
.bundle
@@ -29,3 +34,7 @@ DerivedData
2934
fastlane/report.xml
3035
fastlane/test_output/report.html
3136
fastlane/test_output/report.junit
37+
38+
# SPM
39+
.swiftpm/*
40+

.swiftlint.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
disabled_rules: # rule identifiers to exclude from running
2+
- todo
3+
- line_length
4+
- large_tuple
5+
opt_in_rules:
6+
- force_unwrapping
7+
8+
custom_rules:
9+
weak_root_coordinator:
10+
name: "Weak Root Coordinator"
11+
message: "Root coordinators should be weak to avoid reference cycles."
12+
regex: "(?<!weak )var rootCoordinator: RootCoordinator\\?(?! \\{ get (set )?\\})"
13+
file_length:
14+
warning: 600
15+
identifier_name:
16+
min_length: # only min_length
17+
error: 2 # only error
18+
excluded: # excluded via string array
19+
- id
20+
- f
21+
- s
22+
- i
23+
- j
24+
- x
25+
- y
26+
- vc
27+
- to
28+
function_body_length:
29+
- 60
30+
- 60
31+
nesting:
32+
type_level:
33+
warning: 2
34+
private_over_fileprivate:
35+
validate_extensions: true
36+
37+
excluded:
38+
- Pods/**
39+
- Example/PodApp/Pods/**
40+
- Sources/SplitScreenScanner/Classes/ScannerStyleKit.swift

Dangerfile.swift

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import Foundation
2+
import Danger
3+
4+
// MARK: Helper methods
5+
6+
func validateTitleAllowsMerging(for pullRequest: GitHub.PullRequest) throws {
7+
let range = NSRange(pullRequest.title.startIndex..., in: pullRequest.title)
8+
9+
let wipRegex = try NSRegularExpression(pattern: "\\bWIP\\b", options: .caseInsensitive)
10+
if wipRegex.firstMatch(in: pullRequest.title, range: range) != nil {
11+
print("Pull request title contains “WIP”.")
12+
}
13+
14+
let doNotMergeRegex = try NSRegularExpression(pattern: "\\bdo not merge\\b", options: .caseInsensitive)
15+
if doNotMergeRegex.firstMatch(in: pullRequest.title, range: range) != nil {
16+
print("Pull request title contains “do not merge”.")
17+
}
18+
}
19+
20+
func validateMessage(for ghCommit: GitHub.Commit, doesNotHavePrefixes prefixes: [String]) {
21+
let commitMessage = ghCommit.commit.message.lowercased()
22+
for prefix in prefixes where commitMessage.hasPrefix(prefix.lowercased()) {
23+
fail("Commit message \(ghCommit.sha) begins with `\(prefix)`. Squash before merging.")
24+
}
25+
}
26+
27+
func messageIsGenerated(for ghCommit: GitHub.Commit) -> Bool {
28+
guard let firstWord = ghCommit.commit.message.components(separatedBy: " ").first else {
29+
return false
30+
}
31+
return firstWord == "Merge" || firstWord == "Revert" || firstWord == "fixup!" || firstWord == "squash!"
32+
}
33+
34+
/// Fails if the commit’s message does not satisfy Chris Beams’s
35+
/// [“The seven rules of a great Git commit message”](https://chris.beams.io/posts/git-commit/).
36+
func validateMessageIsGreat(for ghCommit: GitHub.Commit) {
37+
guard !messageIsGenerated(for: ghCommit) else { return }
38+
39+
let messageComponents = ghCommit.commit.message.components(separatedBy: "\n")
40+
let title = messageComponents[0]
41+
42+
// Rule 1
43+
if messageComponents.count > 1 {
44+
let separator = messageComponents[1]
45+
if !separator.isEmpty {
46+
fail("Commit message \(ghCommit.sha) is missing a blank line between title and body.")
47+
}
48+
}
49+
50+
// Rule 2
51+
if title.count > 50 {
52+
fail("Commit title \(ghCommit.sha) is \(title.count) characters long (title should be limited to 50 characters).")
53+
}
54+
55+
// Rule 3
56+
if title.first != title.capitalized.first {
57+
fail("Commit title \(ghCommit.sha) is not capitalized.")
58+
}
59+
60+
// Rule 4
61+
if title.hasSuffix(".") {
62+
fail("Commit title \(ghCommit.sha) ends with a period.")
63+
}
64+
65+
// Rule 5
66+
// Use the imperative mood in the subject line
67+
// Not validated here
68+
69+
// Rule 6
70+
let body = messageComponents.dropFirst()
71+
let lineNumbers = body.indices.map({ $0 + 1 })
72+
for (lineNumber, line) in zip(lineNumbers, body) where line.count > 72 {
73+
fail("Commit message \(ghCommit.sha) line \(lineNumber) is \(line.count) characters long (body should be wrapped at 72 characters).")
74+
}
75+
76+
// Rule 7
77+
// Use the body to explain what and why vs. how
78+
// Not validated here
79+
}
80+
81+
// MARK: - Validations
82+
83+
let danger = Danger()
84+
let pullRequest = danger.github.pullRequest
85+
86+
try validateTitleAllowsMerging(for: pullRequest)
87+
88+
let unmergeablePrefixes = ["fixup!", "squash!", "WIP"]
89+
danger.github.commits.forEach {
90+
validateMessage(for: $0, doesNotHavePrefixes: unmergeablePrefixes)
91+
validateMessageIsGreat(for: $0)
92+
}
93+
94+
if let additions = pullRequest.additions, let deletions = pullRequest.deletions, additions < deletions {
95+
message("🎉 This PR removes more code than it adds! (\(additions - deletions) net lines)")
96+
}
97+
98+
SwiftLint.lint(inline: true, directory: "Session")

Example/PodApp/Podfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
platform :ios, '14.0'
2+
use_frameworks!
3+
4+
pod 'SplitScreenScanner', :path => '../..'
5+
6+
target 'SplitScreenScanner_Example'
7+
target 'SplitScreenScanner_Tests'

Example/PodApp/Podfile.lock

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
PODS:
2+
- Sections (0.8.0)
3+
- SplitScreenScanner (10.0.0):
4+
- Sections
5+
6+
DEPENDENCIES:
7+
- SplitScreenScanner (from `../..`)
8+
9+
SPEC REPOS:
10+
trunk:
11+
- Sections
12+
13+
EXTERNAL SOURCES:
14+
SplitScreenScanner:
15+
:path: "../.."
16+
17+
SPEC CHECKSUMS:
18+
Sections: efc268a207d0e7afba82d2a0efd6cdf61872b5d4
19+
SplitScreenScanner: 14f7388b33bb57afc2dfd1eab6af0bd18a45b9a2
20+
21+
PODFILE CHECKSUM: a50e47e37e36a517f8de6ae75d836fb0fdfdecfd
22+
23+
COCOAPODS: 1.8.4

0 commit comments

Comments
 (0)