Skip to content

Commit

Permalink
Add Danger
Browse files Browse the repository at this point in the history
close #5
  • Loading branch information
jessesquires committed Apr 12, 2020
1 parent 53353da commit 74e3b94
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
@@ -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
74 changes: 74 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

gem 'danger'
gem 'danger-todoist'
gem 'danger-prose'
gem 'danger-swiftlint'
74 changes: 74 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 74e3b94

Please sign in to comment.