Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dangermattic Setup #518

Merged
merged 20 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
37 changes: 1 addition & 36 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ common_params:
propagate-environment: true
environment:
- "RUBYGEMS_API_KEY"
- &docker_plugin_with_danger_token
docker#v5.8.0:
image: *ruby_version
propagate-environment: true
environment:
- "DANGER_GITHUB_API_TOKEN"


steps:
#################
Expand Down Expand Up @@ -55,32 +48,6 @@ steps:
ruby:
- 3.2.2

#################
# Lint
#################
- label: "🧹 Lint (Rubocop)"
key: rubocop
command: |
bundle install
echo "--- :rubocop: Run Rubocop"
bundle exec rubocop
plugins: [*docker_plugin]
agents:
queue: "default"

#################
# Danger
#################
- label: "⛔️ Danger"
key: danger
command: |
bundle install
echo "--- :rubocop: Run Danger"
bundle exec danger
plugins: [*docker_plugin_with_danger_token]
agents:
queue: "default"

#################
# Push to RubyGems
#################
Expand All @@ -89,12 +56,10 @@ steps:
if: build.tag != null
depends_on:
- test
- rubocop
- danger
# Note: We intentionally call a separate `.sh` script here (as opposed to having all the
# commands written inline) to avoid leaking a key used in the process in clear in the
# BUILDKITE_COMMAND environment variable.
command: .buildkite/gem-push.sh
command: .buildkite/commands/gem-push.sh
plugins: [*docker_plugin]
agents:
queue: "default"
13 changes: 13 additions & 0 deletions .github/workflows/run-danger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: ☢️ Danger

on:
pull_request:
types: [opened, reopened, ready_for_review, synchronize, edited, review_requested, review_request_removed, labeled, unlabeled, milestoned, demilestoned]

jobs:
dangermattic:
# runs on draft PRs only for opened / synchronize events
if: ${{ (github.event.pull_request.draft == false) || (github.event.pull_request.draft == true && contains(fromJSON('["opened", "synchronize"]'), github.event.action)) }}
uses: Automattic/dangermattic/.github/workflows/[email protected]
secrets:
github-token: ${{ secrets.DANGERMATTIC_GITHUB_TOKEN }}
22 changes: 7 additions & 15 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-09-21 15:44:18 UTC using RuboCop version 1.56.3.
# on 2024-02-07 17:44:01 UTC using RuboCop version 1.60.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -14,24 +14,16 @@ Gemspec/DevelopmentDependencies:
Exclude:
- 'fastlane-plugin-wpmreleasetoolkit.gemspec'

# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'fastlane-plugin-wpmreleasetoolkit.gemspec'

# Offense count: 3
Lint/NonLocalExitFromIterator:
Exclude:
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/extract_release_notes_for_version_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb'

# Offense count: 7
# Offense count: 4
Naming/AccessorMethodName:
Exclude:
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb'

# Offense count: 2
Expand All @@ -42,7 +34,7 @@ Naming/MethodParameterName:
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb'

# Offense count: 108
# Offense count: 110
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
# NamePrefix: is_, has_, have_
# ForbiddenPrefixes: is_, has_, have_
Expand All @@ -68,7 +60,7 @@ RSpec/ContextWording:
- 'spec/git_helper_spec.rb'
- 'spec/ios_lint_localizations_spec.rb'

# Offense count: 45
# Offense count: 62
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
Expand All @@ -81,7 +73,7 @@ RSpec/InstanceVariable:
- 'spec/git_helper_spec.rb'
- 'spec/ios_lint_localizations_spec.rb'

# Offense count: 109
# Offense count: 122
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
Expand All @@ -96,7 +88,7 @@ RSpec/NamedSubject:
- 'spec/configuration_spec.rb'
- 'spec/file_reference_spec.rb'

# Offense count: 10
# Offense count: 14
RSpec/NestedGroups:
Max: 5

Expand Down Expand Up @@ -124,7 +116,7 @@ Security/Open:
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_validate_lib_strings_action.rb'
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_create_xml_release_notes.rb'

# Offense count: 123
# Offense count: 124
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false
Expand Down
49 changes: 35 additions & 14 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

def version
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Expand All @@ -10,16 +12,26 @@ def gemfile_lock_version
gemfile_lock.scan(/fastlane-plugin-wpmreleasetoolkit \((\d+.\d+.\d+)\)/).last.first
end

# Before checking the version, get rid of any change that `bundle install`
# might have done.
`git checkout Gemfile.lock &> /dev/null`
github.dismiss_out_of_range_messages

# `files: []` forces rubocop to scan all files, not just the ones modified in the PR
rubocop.lint(files: [], force_exclusion: true, inline_comment: true, fail_on_inline_comment: true, include_cop_names: true)

manifest_pr_checker.check_gemfile_lock_updated

# skip remaining checks if we're in a release-process PR
if github.pr_labels.include?('Releases')
message('This PR has the `Releases` label: some checks will be skipped.')
return
end

if version.to_s != gemfile_lock_version.to_s
message = %{
The version in the `Gemfile.lock` (`#{gemfile_lock_version}`) doesn't match the one in `version.rb` (`#{version}`).
message = <<~MESSAGE
The version in the `Gemfile.lock` (`#{gemfile_lock_version}`) doesn't match the one in `version.rb` (`#{version}`).

Please run `bundle install` to make sure they match.
MESSAGE

Please run `bundle install` to make sure they match.
}
failure(message)
end

Expand All @@ -30,11 +42,20 @@ unless git.modified_files.include?('CHANGELOG.md')
warn 'Please add an entry in the CHANGELOG.md file to describe the changes made by this PR'
end

# Lint with Rubocop and report violations inline in GitHub
github.dismiss_out_of_range_messages # This way, fixed violations should go
renaming_map = (git.renamed_files || []).to_h { |e| [e[:before], e[:after]] } # when files are renamed, git.modified_files contains old name, not new one, so we need to do the convertion
rubocop.lint(
files: git.added_files + (git.modified_files.map { |f| renaming_map[f] || f }) - git.deleted_files,
inline_comment: true,
fail_on_inline_comment: true # Make the inline comments failures
pr_size_checker.check_diff_size(max_size: 500)

# skip remaining checks if the PR is still a Draft
if github.pr_draft?
message('This PR is still a Draft: some checks will be skipped.')
return
end

labels_checker.check(
do_not_merge_labels: ['Do Not Merge'],
required_labels: [//],
required_labels_error: 'PR requires at least one label.'
)

milestone_checker.check_milestone_due_date(days_before_due: 5)

warn("No reviewers have been set for this PR yet. Please request a review from **@\u2060wordpress-mobile/apps-infrastructure**.") unless github_utils.requested_reviewers?
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ gemspec

gem 'buildkite-test_collector', '~> 2.3'
gem 'codecov', require: false
gem 'danger', '~> 9.3'
gem 'danger-rubocop', '~> 0.6'
gem 'danger-dangermattic', '~> 1.0'
gem 'webmock', require: false
gem 'yard'
Loading