Skip to content

Commit

Permalink
Update for Ruby 3.1.3 (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenthedev authored Feb 22, 2023
1 parent 6b321c9 commit 5406f6c
Show file tree
Hide file tree
Showing 80 changed files with 369 additions and 276 deletions.
22 changes: 19 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 3.1.3
Exclude:
- '.gemspec'
- 'vendor/**/*'
Expand All @@ -22,7 +22,23 @@ Metrics/ClassLength:
Max: 130
Style/Documentation:
Enabled: false
Style/MethodMissing:
Lint/MissingSuper:
Enabled: false
Layout/IndentHeredoc:
Style/MissingRespondToMissing:
Enabled: false
Layout/HeredocIndentation:
Enabled: false
Naming/HeredocDelimiterNaming:
Enabled: false
Naming/MemoizedInstanceVariableName:
Enabled: false
Naming/MethodParameterName:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Style/OptionalBooleanParameter:
Enabled: false
Lint/EmptyFile:
Enabled: false
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.8
3.1.3
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
Expand All @@ -7,5 +9,5 @@ gem 'rake', require: false
group :test do
gem 'codeclimate-test-reporter'
gem 'pry'
gem 'rubocop', '~> 0.49.0'
gem 'rubocop'
end
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
Expand Down
5 changes: 4 additions & 1 deletion bin/moonshot
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'moonshot'

# This is the main entry point for the `moonshot` command-line tool.
begin
Moonshot::CommandLine.new.run!
rescue => e
rescue StandardError => e
warn "#{e} (at #{e.backtrace.first})"
raise e if ENV['MOONSHOT_BACKTRACE']

exit 1
end
5 changes: 5 additions & 0 deletions lib/moonshot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'English'

require 'aws-sdk-cloudformation'
Expand All @@ -23,10 +25,13 @@ def self.config

module ArtifactRepository
end

module BuildMechanism
end

module DeploymentMechanism
end

module Plugins
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/moonshot/account_context.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Moonshot
module AccountContext
def self.get
Expand Down
2 changes: 2 additions & 0 deletions lib/moonshot/always_use_default_source.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Moonshot
# The AlwaysUseDefaultSource will always use the previous value in
# the stack, or use the default value during stack creation. This is
Expand Down
2 changes: 1 addition & 1 deletion lib/moonshot/artifact_repository/s3_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def filename_for_version(version_name)
def upload_to_s3(file, key)
s3_client.put_object(
acl: 'bucket-owner-full-control',
key: key,
key:,
body: File.open(file),
bucket: @bucket_name,
storage_class: 'STANDARD_IA'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'moonshot/artifact_repository/s3_bucket'
require 'moonshot/shell'
require 'digest'
Expand All @@ -9,7 +11,7 @@
module Moonshot::ArtifactRepository
# S3 Bucket repository backed by GitHub releases.
# If a SemVer package isn't found in S3, it is copied from GitHub releases.
class S3BucketViaGithubReleases < S3Bucket # rubocop:disable ClassLength
class S3BucketViaGithubReleases < S3Bucket # rubocop:disable Metrics/ClassLength
include Moonshot::BuildMechanism
include Moonshot::Shell

Expand All @@ -36,9 +38,7 @@ def store_hook(build_mechanism, version)
# artifact repositories a hook before deploy.
def filename_for_version(version)
s3_name = super
if !@output_file && release?(version) && !in_s3?(s3_name)
github_to_s3(version, s3_name)
end
github_to_s3(version, s3_name) if !@output_file && release?(version) && !in_s3?(s3_name)
s3_name
end

Expand All @@ -51,7 +51,7 @@ def release?(version)
end

def in_s3?(key)
s3_client.head_object(key: key, bucket: bucket_name)
s3_client.head_object(key:, bucket: bucket_name)
rescue ::Aws::S3::Errors::NotFound
false
end
Expand All @@ -62,7 +62,7 @@ def attach_release_asset(version, file)

# If there is a checksum file, attach it as well. We only support MD5
# since that's what S3 uses.
checksum_file = File.basename(file, '.tar.gz') + '.md5'
checksum_file = "#{File.basename(file, '.tar.gz')}.md5"
cmd += " --attach=#{checksum_file}" if File.exist?(checksum_file)

sh_step(cmd)
Expand Down Expand Up @@ -218,7 +218,7 @@ def backup_failed_s3_file(s3_name, attempt)

def doctor_check_hub_release_download
sh_out('hub release download --help')
rescue
rescue StandardError
critical '`hub release download` command missing, upgrade hub.' \
' See https://github.com/github/hub/pull/1103'
else
Expand Down
2 changes: 2 additions & 0 deletions lib/moonshot/ask_user_source.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'colorize'

module Moonshot
Expand Down
7 changes: 5 additions & 2 deletions lib/moonshot/build_mechanism/github_release.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'forwardable'
require 'moonshot/shell'
require 'open3'
Expand Down Expand Up @@ -135,6 +137,7 @@ def git_push_tag(remote, tag)

def hub_create_release(semver, commitish, changelog_entry)
return if hub_release_exists(semver)

message = "#{semver}\n\n#{changelog_entry}"
cmd = "hub release create #{semver} --commitish=#{commitish}"
cmd << ' --prerelease' if semver.pre || semver.build
Expand Down Expand Up @@ -220,15 +223,15 @@ def releases_url

def doctor_check_upstream
sh_out('git remote | grep ^upstream$')
rescue => e
rescue StandardError => e
critical "git remote `upstream` not found.\n#{e.message}"
else
success 'git remote `upstream` exists.'
end

def doctor_check_hub_auth
sh_out('hub ci-status 0.0.0')
rescue => e
rescue StandardError => e
critical "`hub` failed, install hub and authorize it.\n#{e.message}"
else
success '`hub` installed and authorized.'
Expand Down
13 changes: 7 additions & 6 deletions lib/moonshot/build_mechanism/script.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'open3'
include Open3

# Compile a release artifact using a shell script.
#
Expand All @@ -18,6 +19,8 @@ class Moonshot::BuildMechanism::Script
include Moonshot::ResourcesHelper
include Moonshot::DoctorHelper

include Open3

attr_reader :output_file

def initialize(script, output_file: 'output.tar.gz')
Expand All @@ -35,12 +38,12 @@ def build_hook(version)
'OUTPUT_FILE' => @output_file
}
ilog.start_threaded "Running Script: #{@script}" do |s|
run_script(s, env: env)
run_script(s, env:)
end
end

def post_build_hook(_version)
unless File.exist?(@output_file) # rubocop:disable GuardClause
unless File.exist?(@output_file) # rubocop:disable Style/GuardClause
raise 'Build command did not produce output file!'
end
end
Expand All @@ -61,9 +64,7 @@ def run_script(step, env: {})
end

result = wait.value
if result.exitstatus.zero?
step.success "Build script #{@script} exited successfully!"
end
step.success "Build script #{@script} exited successfully!" if result.exitstatus.zero?
unless result.exitstatus.zero?
ilog.error "Build script failed with exit status #{result.exitstatus}!"
ilog.error output.join("\n")
Expand Down
4 changes: 3 additions & 1 deletion lib/moonshot/build_mechanism/travis_deploy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'moonshot/shell'
require 'travis'
require 'travis/pro'
Expand Down Expand Up @@ -118,7 +120,7 @@ def check_build(version)

def doctor_check_travis_auth
sh_out("bundle exec travis raw #{@endpoint} repos/#{@slug}")
rescue => e
rescue StandardError => e
critical "`travis` not available or not authorized.\n#{e.message}"
else
success '`travis` installed and authorized.'
Expand Down
2 changes: 2 additions & 0 deletions lib/moonshot/build_mechanism/version_proxy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'forwardable'
require 'semantic'

Expand Down
15 changes: 8 additions & 7 deletions lib/moonshot/change_set.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

module Moonshot
class ChangeSet
attr_reader :name
attr_reader :stack_name
attr_reader :name, :stack_name

def initialize(name, stack_name)
@name = name
Expand All @@ -11,16 +12,15 @@ def initialize(name, stack_name)
end

def confirm?
unless Moonshot.config.interactive
raise 'Cannot confirm ChangeSet when interactive mode is disabled!'
end
raise 'Cannot confirm ChangeSet when interactive mode is disabled!' unless Moonshot.config.interactive

loop do
print 'Apply changes? '
resp = gets.chomp.downcase

return true if resp == 'yes'
return false if resp == 'no'

puts "Please enter 'yes' or 'no'!"
end
end
Expand All @@ -39,9 +39,10 @@ def display_changes
@change_set.changes.map(&:resource_change).each do |c|
puts "* #{c.action} #{c.logical_resource_id} (#{c.resource_type})"

if c.replacement == 'True'
case c.replacement
when 'True'
puts ' - Will be replaced'
elsif c.replacement == 'Conditional'
when 'Conditional'
puts ' - May be replaced (Conditional)'
end

Expand Down
4 changes: 3 additions & 1 deletion lib/moonshot/command.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'optparse'

module Moonshot
Expand Down Expand Up @@ -44,7 +46,7 @@ def controller
# Degrade to a more compatible logger if the terminal seems outdated,
# or at the users request.
if !$stdout.isatty || !@use_interactive_logger
log = Logger.new(STDOUT)
log = Logger.new($stdout)
controller.config.interactive_logger = InteractiveLoggerProxy.new(log)
end

Expand Down
Loading

0 comments on commit 5406f6c

Please sign in to comment.