Просмотр исходного кода

Integrate Danger in CircleCI

* Add jobs to run Danger as part of the CI
* Add the `Dangerfile` with some basics rules for the project
* Add the `Gemfile` to manage the Ruby dependencies
Victor Sigler 7 лет назад
Родитель
Сommit
2654c1e5cc
4 измененных файлов с 137 добавлено и 2 удалено
  1. 30 2
      .circleci/config.yml
  2. 36 0
      Dangerfile
  3. 8 0
      Gemfile
  4. 63 0
      Gemfile.lock

+ 30 - 2
.circleci/config.yml

@@ -1,6 +1,29 @@
 version: 2
 
 jobs:
+  danger:
+    macos:
+      xcode: 10.2.0
+    steps:
+      - checkout
+      - run:
+          name: Set Ruby Version
+          command: echo "ruby-2.4" > ~/.ruby-version
+      - restore_cache:
+            key: 1-gems-{{ checksum "Gemfile.lock" }}
+      - run:
+          name: Install Ruby Dependencies
+          command: bundle check || bundle install
+          environment:
+            BUNDLE_JOBS: 4
+            BUNDLE_RETRY: 3
+      - save_cache:
+            key: 1-gems-{{ checksum "Gemfile.lock" }}
+            paths:
+              - vendor/bundle
+      - run:
+          name: Danger
+          command: bundle exec danger
   macos:
     environment:
       TEST_REPORTS: /tmp/test-results
@@ -51,5 +74,10 @@ workflows:
   version: 2
   tests:
     jobs:
-      - linux
-      - macos
+      - danger
+      - linux:
+          requires:
+            - danger
+      - macos:
+          requires:
+            - danger

+ 36 - 0
Dangerfile

@@ -0,0 +1,36 @@
+# send a welcome message for the user
+message "Hey, @#{github.pr_author} 👋."
+
+# Just to let people know
+warn("PR is classed as Work in Progress.") if github.pr_title.include? "[WIP]"
+
+# Warn when there is a big PR
+warn("Big PR") if git.lines_of_code > 500
+
+# ensure there is a summary for a PR
+fail "Please provide a summary in the Pull Request description." if github.pr_body.length < 5
+
+# Changelog entries are required for changes to library files.
+fail("Please include a CHANGELOG entry. You 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")
+
+# Don't accept PR on master for now
+fail "Please re-submit this PR to stable, you're trying to merge the PR on master." if github.branch_for_base == "master"
+
+# If these are all empty something has gone wrong, better to raise it in a comment
+if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty?
+    fail "This PR has no changes at all, this is likely a developer issue."
+end
+
+# Run SwiftLint
+swiftlint.config_file = '.swiftlint.yml'
+swiftlint.lint_files
+
+# Warn when new tests are added but the XCTestManifests wasn't updated to run on Linux
+tests_added_or_modified = git.modified_files.grep(/XCode\/Tests/).empty? || git.added_files.grep(/XCode\/Tests/).empty?
+xc_manifest_updated = !git.modified_files.grep(/XCode\/Tests\/XCTestManifests.swift/).empty?
+if tests_added_or_modified && !xc_manifest_updated
+  warn("It seems like you've added new tests to the library. If that's the case, 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`.")
+
+  # This is a temporary warning to remove the entry for the failed test until we solve the issue in Linux
+  warn("If you ran the command `swift test --generate-linuxmain` in your terminal, please remove the line `testCase(IOSafetyTests.__allTests__IOSafetyTests),` from `public func __allTests() -> [XCTestCaseEntry]` in the bottom of the file. For more reference see [#366](https://github.com/httpswift/swifter/issues/366).")
+end

+ 8 - 0
Gemfile

@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
+
+gem 'danger'
+gem 'danger-swiftlint'

+ 63 - 0
Gemfile.lock

@@ -0,0 +1,63 @@
+GEM
+  remote: https://rubygems.org/
+  specs:
+    addressable (2.5.2)
+      public_suffix (>= 2.0.2, < 4.0)
+    claide (1.0.2)
+    claide-plugins (0.9.2)
+      cork
+      nap
+      open4 (~> 1.3)
+    colored2 (3.1.2)
+    cork (0.3.0)
+      colored2 (~> 3.1)
+    danger (6.0.6)
+      claide (~> 1.0)
+      claide-plugins (>= 0.9.2)
+      colored2 (~> 3.1)
+      cork (~> 0.1)
+      faraday (~> 0.9)
+      faraday-http-cache (~> 1.0)
+      git (~> 1.5)
+      kramdown (~> 2.0)
+      kramdown-parser-gfm (~> 1.0)
+      no_proxy_fix
+      octokit (~> 4.7)
+      terminal-table (~> 1)
+    danger-swiftlint (0.20.1)
+      danger
+      rake (> 10)
+      thor (~> 0.19)
+    faraday (0.15.4)
+      multipart-post (>= 1.2, < 3)
+    faraday-http-cache (1.3.1)
+      faraday (~> 0.8)
+    git (1.5.0)
+    kramdown (2.1.0)
+    kramdown-parser-gfm (1.0.1)
+      kramdown (~> 2.0)
+    multipart-post (2.0.0)
+    nap (1.1.0)
+    no_proxy_fix (0.1.2)
+    octokit (4.14.0)
+      sawyer (~> 0.8.0, >= 0.5.3)
+    open4 (1.3.4)
+    public_suffix (3.0.3)
+    rake (12.3.2)
+    sawyer (0.8.1)
+      addressable (>= 2.3.5, < 2.6)
+      faraday (~> 0.8, < 1.0)
+    terminal-table (1.8.0)
+      unicode-display_width (~> 1.1, >= 1.1.1)
+    thor (0.20.3)
+    unicode-display_width (1.5.0)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  danger
+  danger-swiftlint
+
+BUNDLED WITH
+   1.16.5