From 74e3b94f0499f9b4055e1b993ad7ee90ae714f9b Mon Sep 17 00:00:00 2001 From: Jesse Squires Date: Sun, 12 Apr 2020 09:27:04 -0700 Subject: [PATCH] Add Danger close #5 --- .github/workflows/danger.yml | 39 +++++++++++++++++++ Dangerfile | 74 ++++++++++++++++++++++++++++++++++++ Gemfile | 6 +++ Gemfile.lock | 74 ++++++++++++++++++++++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 .github/workflows/danger.yml create mode 100644 Dangerfile create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml new file mode 100644 index 0000000..8f1139a --- /dev/null +++ b/.github/workflows/danger.yml @@ -0,0 +1,39 @@ +name: Danger + +on: pull_request + +env: + DEVELOPER_DIR: /Applications/Xcode_11.4.app/Contents/Developer + +jobs: + job-danger: + name: Review, Lint, Verify + runs-on: macOS-latest + steps: + - name: git checkout + uses: actions/checkout@v1 + + - name: ruby versions + run: | + ruby --version + gem --version + bundler --version + + - name: cache gems + uses: actions/cache@v1 + with: + path: vendor/bundle + key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gem- + + - name: bundle install + run: | + bundle config path vendor/bundle + bundle install --without=documentation --jobs 4 --retry 3 + echo "::add-path::/Users/runner/Library/Python/2.7/bin" + + - name: danger + env: + DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }} + run: bundle exec danger diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 0000000..04edbcd --- /dev/null +++ b/Dangerfile @@ -0,0 +1,74 @@ +# ----------------------------------------------------------------------------- +# Changed library files, but didn't add/update tests +# ----------------------------------------------------------------------------- +all_changed_files = (git.added_files + git.modified_files + git.deleted_files) + +has_source_changes = !all_changed_files.grep(/Sources/).empty? +has_test_changes = !all_changed_files.grep(/Tests/).empty? +if has_source_changes && !has_test_changes + warn("Library files were updated without test coverage. Please update or add tests, if possible!") +end + +# ----------------------------------------------------------------------------- +# Pull request is too large to review +# ----------------------------------------------------------------------------- +if git.lines_of_code > 600 + warn("This is a large pull request! Can you break it up into multiple smaller ones instead?") +end + +# ----------------------------------------------------------------------------- +# All pull requests need a description +# ----------------------------------------------------------------------------- +if github.pr_body.length < 15 + fail("Please provide a detailed summary in the pull request description.") +end + +# ----------------------------------------------------------------------------- +# Fail on TODOs in code +# ----------------------------------------------------------------------------- +todoist.message = "Oops! We should not commit TODOs. Please fix them before merging." +todoist.fail_for_todos + +# ----------------------------------------------------------------------------- +# All pull requests should be submitted to master branch +# ----------------------------------------------------------------------------- +if github.branch_for_base != "master" + warn("Pull requests should be submitted to the master branch only.") +end + +# ----------------------------------------------------------------------------- +# CHANGELOG entries are required for changes to library files +# ----------------------------------------------------------------------------- +no_changelog_entry = !git.modified_files.include?("CHANGELOG.md") +if has_source_changes && no_changelog_entry + warn("There is no CHANGELOG entry. Do you need to add one?") +end + +# ----------------------------------------------------------------------------- +# Milestones are required for all PRs to track what's included in each release +# ----------------------------------------------------------------------------- +has_milestone = github.pr_json["milestone"] != nil +warn('All pull requests should have a milestone.', sticky: false) unless has_milestone + +# ----------------------------------------------------------------------------- +# Lint all changed markdown files +# ----------------------------------------------------------------------------- +markdown_files = (git.added_files + git.modified_files).grep(%r{.*\.md/}) +unless markdown_files.empty? + # Run proselint to check prose and check spelling + prose.language = "en-us" + prose.ignore_acronyms = true + prose.ignore_numbers = true + prose.ignored_words = ["jessesquires", "swiftpm", "iOS", + "macOS", "watchOS", "tvOS", "Xcode" + ] + prose.lint_files markdown_files + prose.check_spelling markdown_files +end + +# ----------------------------------------------------------------------------- +# Run SwiftLint +# ----------------------------------------------------------------------------- +swiftlint.verbose = true +swiftlint.config_file = './.swiftlint.yml' +swiftlint.lint_files(inline_mode: true, fail_on_error: true) diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..992110a --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source 'https://rubygems.org' + +gem 'danger' +gem 'danger-todoist' +gem 'danger-prose' +gem 'danger-swiftlint' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..ea469ce --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,74 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + claide (1.0.3) + claide-plugins (0.9.2) + cork + nap + open4 (~> 1.3) + colored2 (3.1.2) + cork (0.3.0) + colored2 (~> 3.1) + danger (6.3.2) + claide (~> 1.0) + claide-plugins (>= 0.9.2) + colored2 (~> 3.1) + cork (~> 0.1) + faraday (~> 0.9) + faraday-http-cache (~> 2.0) + git (~> 1.6) + kramdown (~> 2.0) + kramdown-parser-gfm (~> 1.0) + no_proxy_fix + octokit (~> 4.7) + terminal-table (~> 1) + danger-plugin-api (1.0.0) + danger (> 2.0) + danger-prose (2.0.7) + danger + danger-swiftlint (0.24.2) + danger + rake (> 10) + thor (~> 0.19) + danger-todoist (2.0.1) + danger-plugin-api (~> 1.0) + faraday (0.17.3) + multipart-post (>= 1.2, < 3) + faraday-http-cache (2.1.0) + faraday (~> 0.8) + git (1.6.0) + rchardet (~> 1.8) + kramdown (2.1.0) + kramdown-parser-gfm (1.1.0) + kramdown (~> 2.0) + multipart-post (2.1.1) + nap (1.1.0) + no_proxy_fix (0.1.2) + octokit (4.18.0) + faraday (>= 0.9) + sawyer (~> 0.8.0, >= 0.5.3) + open4 (1.3.4) + public_suffix (4.0.4) + rake (13.0.1) + rchardet (1.8.0) + sawyer (0.8.2) + addressable (>= 2.3.5) + faraday (> 0.8, < 2.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thor (0.20.3) + unicode-display_width (1.7.0) + +PLATFORMS + ruby + +DEPENDENCIES + danger + danger-prose + danger-swiftlint + danger-todoist + +BUNDLED WITH + 2.1.4