Skip to content

Commit

Permalink
Merge pull request basecamp#701 from basecamp/rubocop
Browse files Browse the repository at this point in the history
Add Rubocop
  • Loading branch information
djmb authored Mar 20, 2024
2 parents c985fa3 + 3ecfb37 commit 474b76c
Show file tree
Hide file tree
Showing 51 changed files with 229 additions and 164 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ on:
- main
pull_request:
jobs:
rubocop:
name: RuboCop
runs-on: ubuntu-latest
env:
BUNDLE_ONLY: rubocop
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Ruby and install gems
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.0
bundler-cache: true
- name: Run Rubocop
run: bundle exec rubocop --parallel
tests:
strategy:
matrix:
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_gem: { rubocop-37signals: rubocop.yml }
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
source 'https://rubygems.org'
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gemspec

group :rubocop do
gem "rubocop-37signals", github: "basecamp/house-style", require: false
end
47 changes: 47 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
GIT
remote: https://github.com/basecamp/house-style.git
revision: a9ca7e4ab80b72c1a10053c50efefe8cd275e3b8
specs:
rubocop-37signals (1.0.0)
rubocop
rubocop-minitest
rubocop-performance
rubocop-rails

PATH
remote: .
specs:
Expand Down Expand Up @@ -42,6 +52,7 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bcrypt_pbkdf (1.1.0)
bigdecimal (3.1.5)
Expand All @@ -63,6 +74,8 @@ GEM
irb (1.11.0)
rdoc
reline (>= 0.3.8)
json (2.7.1)
language_server-protocol (3.17.0.3)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -79,6 +92,10 @@ GEM
racc (~> 1.4)
nokogiri (1.16.0-x86_64-linux)
racc (~> 1.4)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
psych (5.1.2)
stringio
racc (1.7.3)
Expand All @@ -105,11 +122,39 @@ GEM
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.1.0)
rdoc (6.6.2)
psych (>= 4.0.0)
regexp_parser (2.9.0)
reline (0.4.2)
io-console (~> 0.5)
rexml (3.2.6)
rubocop (1.61.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.1)
parser (>= 3.3.0.4)
rubocop-minitest (0.34.5)
rubocop (>= 1.39, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-performance (1.20.2)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rails (2.24.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sshkit (1.21.7)
mutex_m
Expand All @@ -119,6 +164,7 @@ GEM
thor (1.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
webrick (1.8.1)
zeitwerk (2.6.12)

Expand All @@ -132,6 +178,7 @@ DEPENDENCIES
kamal!
mocha
railties
rubocop-37signals!

BUNDLED WITH
2.4.3
2 changes: 1 addition & 1 deletion lib/kamal/cli/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def remove(name)
if name == "all"
KAMAL.accessory_names.each { |accessory_name| remove(accessory_name) }
else
if options[:confirmed] || ask("This will remove all containers, images and data directories for #{name}. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
if options[:confirmed] || ask("This will remove all containers, images and data directories for #{name}. Are you sure?", limited_to: %w[ y N ], default: "N") == "y"
with_accessory(name) do
stop(name)
remove_container(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def logs
run_locally do
info "Following logs on #{KAMAL.primary_host}..."

KAMAL.specific_roles ||= ["web"]
KAMAL.specific_roles ||= [ "web" ]
role = KAMAL.roles_on(KAMAL.primary_host).first

info KAMAL.app(role: role).follow_logs(host: KAMAL.primary_host, lines: lines, grep: grep)
Expand Down
4 changes: 2 additions & 2 deletions lib/kamal/cli/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def initialize_commander(options)
def print_runtime
started_at = Time.now
yield
return Time.now - started_at
Time.now - started_at
ensure
runtime = Time.now - started_at
puts " Finished all in #{sprintf("%.1f seconds", runtime)}"
Expand Down Expand Up @@ -181,5 +181,5 @@ def ensure_run_directory
execute(*KAMAL.server.ensure_run_directory)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/kamal/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def envify
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
def remove
mutating do
if options[:confirmed] || ask("This will remove all containers and images. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
if options[:confirmed] || ask("This will remove all containers and images. Are you sure?", limited_to: %w[ y N ], default: "N") == "y"
invoke "kamal:cli:traefik:remove", [], options.without(:confirmed)
invoke "kamal:cli:app:remove", [], options.without(:confirmed)
invoke "kamal:cli:accessory:remove", [ "all" ], options
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/cli/traefik.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def boot
option :rolling, type: :boolean, default: false, desc: "Reboot traefik on hosts in sequence, rather than in parallel"
def reboot
mutating do
host_groups = options[:rolling] ? KAMAL.traefik_hosts : [KAMAL.traefik_hosts]
host_groups = options[:rolling] ? KAMAL.traefik_hosts : [ KAMAL.traefik_hosts ]
host_groups.each do |hosts|
host_list = Array(hosts).join(",")
run_hook "pre-traefik-reboot", hosts: host_list
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/commands/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def make_env_directory
end

def remove_env_file
[:rm, "-f", accessory_config.host_env_file_path]
[ :rm, "-f", accessory_config.host_env_file_path ]
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/commands/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def run(hostname: nil)
"--detach",
"--restart unless-stopped",
"--name", container_name,
*(["--hostname", hostname] if hostname),
*([ "--hostname", hostname ] if hostname),
"-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
"-e", "KAMAL_VERSION=\"#{config.version}\"",
*role.env_args,
Expand Down
6 changes: 3 additions & 3 deletions lib/kamal/commands/app/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def extract_assets

combine \
make_directory(role.asset_extracted_path),
[*docker(:stop, "-t 1", asset_container, "2> /dev/null"), "|| true"],
[ *docker(:stop, "-t 1", asset_container, "2> /dev/null"), "|| true" ],
docker(:run, "--name", asset_container, "--detach", "--rm", config.latest_image, "sleep 1000000"),
docker(:cp, "-L", "#{asset_container}:#{role.asset_path}/.", role.asset_extracted_path),
docker(:stop, "-t 1", asset_container),
Expand All @@ -17,7 +17,7 @@ def sync_asset_volumes(old_version: nil)
old_extracted_path, old_volume_path = role.asset_extracted_path(old_version), role.asset_volume(old_version).host_path
end

commands = [make_directory(new_volume_path), copy_contents(new_extracted_path, new_volume_path)]
commands = [ make_directory(new_volume_path), copy_contents(new_extracted_path, new_volume_path) ]

if old_version.present?
commands << copy_contents(new_extracted_path, old_volume_path, continue_on_error: true)
Expand Down Expand Up @@ -46,6 +46,6 @@ def find_and_remove_older_siblings(path)
end

def copy_contents(source, destination, continue_on_error: false)
[ :cp, "-rnT", "#{source}", destination, *("|| true" if continue_on_error)]
[ :cp, "-rnT", "#{source}", destination, *("|| true" if continue_on_error) ]
end
end
4 changes: 2 additions & 2 deletions lib/kamal/commands/app/cord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Kamal::Commands::App::Cord
def cord(version:)
pipe \
docker(:inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", container_name(version)),
[:awk, "'$2 == \"#{role.cord_volume.container_path}\" {print $1}'"]
[ :awk, "'$2 == \"#{role.cord_volume.container_path}\" {print $1}'" ]
end

def tie_cord(cord)
Expand All @@ -17,6 +17,6 @@ def cut_cord(cord)
def create_empty_file(file)
chain \
make_directory_for(file),
[:touch, file]
[ :touch, file ]
end
end
6 changes: 3 additions & 3 deletions lib/kamal/commands/builder/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def validate_image
pipe \
docker(:inspect, "-f", "'{{ .Config.Labels.service }}'", config.absolute_image),
any(
[:grep, "-x", config.service],
[ :grep, "-x", config.service ],
"(echo \"Image #{config.absolute_image} is missing the 'service' label\" && exit 1)"
)
end
Expand All @@ -38,8 +38,8 @@ def build_tags

def build_cache
if cache_to && cache_from
["--cache-to", cache_to,
"--cache-from", cache_from]
[ "--cache-to", cache_to,
"--cache-from", cache_from ]
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/kamal/commands/healthcheck.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Kamal::Commands::Healthcheck < Kamal::Commands::Base

def run
primary = config.role(config.primary_role)

Expand Down
16 changes: 8 additions & 8 deletions lib/kamal/commands/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
class Kamal::Commands::Lock < Kamal::Commands::Base
def acquire(message, version)
combine \
[:mkdir, lock_dir],
[ :mkdir, lock_dir ],
write_lock_details(message, version)
end

def release
combine \
[:rm, lock_details_file],
[:rm, "-r", lock_dir]
[ :rm, lock_details_file ],
[ :rm, "-r", lock_dir ]
end

def status
Expand All @@ -24,19 +24,19 @@ def status
private
def write_lock_details(message, version)
write \
[:echo, "\"#{Base64.encode64(lock_details(message, version))}\""],
[ :echo, "\"#{Base64.encode64(lock_details(message, version))}\"" ],
lock_details_file
end

def read_lock_details
pipe \
[:cat, lock_details_file],
[:base64, "-d"]
[ :cat, lock_details_file ],
[ :base64, "-d" ]
end

def stat_lock_dir
write \
[:stat, lock_dir],
[ :stat, lock_dir ],
"/dev/null"
end

Expand All @@ -45,7 +45,7 @@ def lock_dir
end

def lock_details_file
[lock_dir, :details].join("/")
[ lock_dir, :details ].join("/")
end

def lock_details(message, version)
Expand Down
4 changes: 2 additions & 2 deletions lib/kamal/commands/prune.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def healthcheck_containers

private
def stopped_containers_filters
[ "created", "exited", "dead" ].flat_map { |status| ["--filter", "status=#{status}"] }
[ "created", "exited", "dead" ].flat_map { |status| [ "--filter", "status=#{status}" ] }
end

def active_image_list
Expand All @@ -43,4 +43,4 @@ def service_filter
def healthcheck_service_filter
[ "--filter", "label=service=#{config.healthcheck_service}" ]
end
end
end
2 changes: 1 addition & 1 deletion lib/kamal/commands/server.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Kamal::Commands::Server < Kamal::Commands::Base
def ensure_run_directory
[:mkdir, "-p", config.run_directory]
[ :mkdir, "-p", config.run_directory ]
end
end
4 changes: 2 additions & 2 deletions lib/kamal/commands/traefik.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Kamal::Commands::Traefik < Kamal::Commands::Base
DEFAULT_IMAGE = "traefik:v2.10"
CONTAINER_PORT = 80
DEFAULT_ARGS = {
'log.level' => 'DEBUG'
"log.level" => "DEBUG"
}
DEFAULT_LABELS = {
# These ensure we serve a 502 rather than a 404 if no containers are available
Expand Down Expand Up @@ -84,7 +84,7 @@ def make_env_directory
end

def remove_env_file
[:rm, "-f", host_env_file_path]
[ :rm, "-f", host_env_file_path ]
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/kamal/configuration/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def image
end

def hosts
if (specifics.keys & ["host", "hosts", "roles"]).size != 1
if (specifics.keys & [ "host", "hosts", "roles" ]).size != 1
raise ArgumentError, "Specify one of `host`, `hosts` or `roles` for accessory `#{name}`"
end

Expand Down Expand Up @@ -159,7 +159,7 @@ def hosts_from_host
if specifics.key?("host")
host = specifics["host"]
if host
[host]
[ host ]
else
raise ArgumentError, "Missing host for accessory `#{name}`"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/configuration/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def limit
limit = @options["limit"]

if limit.to_s.end_with?("%")
[@host_count * limit.to_i / 100, 1].max
[ @host_count * limit.to_i / 100, 1 ].max
else
limit
end
Expand Down
Loading

0 comments on commit 474b76c

Please sign in to comment.