Skip to content

Commit 2094527

Browse files
committed
Integrate Swiftlint and Danger in CircleCI
* Add jobs to run Swiftlint and Danger as part of the CI * Add the `Dangerfile` with some basics rules for the project
1 parent de03182 commit 2094527

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

.circleci/config.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
version: 2
22

33
jobs:
4+
swiftlint:
5+
docker:
6+
- image: dantoml/swiftlint:latest
7+
steps:
8+
- checkout
9+
- run: swiftlint lint --reporter junit | tee result.xml
10+
- store_artifacts:
11+
path: result.xml
12+
- store_test_results:
13+
path: result.xml
14+
danger:
15+
docker:
16+
- image: dantoml/danger:latest
17+
steps:
18+
- checkout
19+
- run: danger
420
macos:
521
environment:
622
TEST_REPORTS: /tmp/test-results
@@ -51,5 +67,7 @@ workflows:
5167
version: 2
5268
tests:
5369
jobs:
70+
- swiftlint
71+
- danger
5472
- linux
5573
- macos

Dangerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# send a welcome message for the user
2+
message "Welcome, @#{github.pr_author}."
3+
4+
# Just to let people know
5+
warn("PR is classed as Work in Progress.") if github.pr_title.include? "[WIP]"
6+
7+
# ensure that the PR have an assignee
8+
warn "This PR does not have any assignees yet." unless github.pr_json["assignee"]
9+
10+
# Warn when there is a big PR
11+
warn("Big PR") if git.lines_of_code > 500
12+
13+
# ensure there is a summary for a PR
14+
fail "Please provide a summary in the Pull Request description." if github.pr_body.length < 5
15+
16+
# Changelog entries are required for changes to library files.
17+
fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/httpswift/swifter/blob/stable/CHANGELOG.md).") unless git.modified_files.include?("CHANGELOG.md") || git.added_files.include?("CHANGELOG.md")
18+
19+
# Don't accept PR on master for now
20+
fail "Please re-submit this PR to stable, you're trying to merge the PR on master." if github.branch_for_base == "master"
21+
22+
# If these are all empty something has gone wrong, better to raise it in a comment
23+
if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty?
24+
fail "This PR has no changes at all, this is likely a developer issue."
25+
end
26+
27+
# Run SwiftLint
28+
swiftlint.config_file = '.swiftlint.yml'
29+
swiftlint.lint_files
30+
31+
# Warn when new tests files were added but the XCTestManifests files wasn't updated
32+
tests_added = !git.added_files.grep(XCode/Tests/).empty?
33+
xc_manifest_updated = !git.modified_files.grep(XCode/Tests/XCTestManifests.swift).empty?
34+
if !tests_added && xc_manifest_updated
35+
fail("It seems like new tests files were added to the library. Please update the [XCTestManifests.swift](https://github.com/httpswift/swifter/blob/stable/XCode/Tests/XCTestManifests.swift) file running in your terminal the command `swift test --generate-linuxmain`.")
36+
message "Please after you run the command in your terminal remove the `testCase(IOSafetyTests.__allTests__IOSafetyTests),` from the function `public func __allTests() -> [XCTestCaseEntry]` in the bottom of the file."
37+
end

0 commit comments

Comments
 (0)