Sha256: 3e961661f314880b07c6fbad323e22b8d6af4cbda4b75bf9edb8330e18498fa5
Contents?: true
Size: 1.25 KB
Versions: 19
Compression:
Stored size: 1.25 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true require "English" # This script is used to run Rubocop in CircleCI so that on branches only # the changed files are checked and on main all files are checked. # # Additionally if rubocop configuration is changed, all files are checked, and # if the commit description on a non-main branch includes [rubocop skip] # then rubocop is skipped. def run(command) puts "Running: #{command}" exit 1 unless system(command) end def rubocop_everything run("bundle exec rubocop --parallel") end begin if ENV["CIRCLE_BRANCH"] == "main" rubocop_everything else git_commit_desc = `git log --format=%B -n 1 $CIRCLE_SHA1` puts "Git commit: #{git_commit_desc}" if git_commit_desc.match?(/\[rubocop skip\]/i) puts "Skipping RuboCop" exit 0 end changed_files = `git diff --diff-filter=d --name-only origin/main...$CIRCLE_BRANCH`.split("\n").join(" ") raise "Failed to identify changed files" unless $CHILD_STATUS.success? if changed_files.strip.empty? || changed_files.include?(".rubocop") rubocop_everything else run("bundle exec rubocop --force-exclusion #{changed_files}") end end rescue StandardError => e puts "Error: #{e.message}" rubocop_everything end
Version data entries
19 entries across 19 versions & 1 rubygems