Skip to content

Commit

Permalink
CDB-8052 CDB-8050 Upgraded to ruby 3.1.2 (#305)
Browse files Browse the repository at this point in the history
* CPD-8050: Update to ruby 3.1.2

* Fixed s3 client keyword argument error

* CPD-8050: volume_id fix for instance hash

* CPD-8052: moonhot status output fix

* CPD-8050: rubocop fixes

* CPD-8050: Fixed rubocop Naming/MethodParameterName.

---------

Co-authored-by: rutuja810 <[email protected]>
Co-authored-by: Kaushik Sirineni <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2023
1 parent 36969f8 commit 04bbbdf
Show file tree
Hide file tree
Showing 86 changed files with 532 additions and 425 deletions.
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 3.1.2
Exclude:
- '.gemspec'
- 'vendor/**/*'
Expand All @@ -20,3 +20,7 @@ Metrics/ClassLength:
Max: 130
Style/Documentation:
Enabled: false
Naming/HeredocDelimiterNaming:
Enabled: false
Style/HashSyntax:
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.2
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

6 changes: 5 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 @@ -6,6 +8,8 @@ gem 'rake', require: false

group :test do
gem 'codeclimate-test-reporter'
gem 'rubocop', '~> 0.38.0'
gem 'pry'
gem 'rubocop'
end

gem 'webrick', '~> 1.8'
4 changes: 3 additions & 1 deletion 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 All @@ -10,4 +12,4 @@ end

RSpec::Core::RakeTask.new(:spec)

task default: [:spec, :rubocop]
task default: %i[spec rubocop]
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
6 changes: 6 additions & 0 deletions lib/moonshot.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

require 'English'
require 'aws-sdk'

require 'logger'
require 'thor'
require 'interactive-logger'
Expand All @@ -16,10 +19,13 @@ def self.config

module ArtifactRepository
end

module BuildMechanism
end

module DeploymentMechanism
end

module Plugins
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/moonshot/account_context.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

module Moonshot
module AccountContext
def self.get
@account ||= determine_account_name
@get ||= determine_account_name
end

def self.set(account_name)
Expand Down
8 changes: 5 additions & 3 deletions lib/moonshot/always_use_default_source.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# 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
# useful if plugins provide the value for a parameter, and we don't
# want to prompt the user for an override. Of course, overrides from
# answer files or command-line arguments will always apply.
class AlwaysUseDefaultSource
def get(sp)
def get(param)
# Don't do anything, the default will apply on create, and the
# previous value will be used on update.
return if sp.default?
return if param.default?

raise "Parameter #{sp.name} does not have a default, cannot use AlwaysUseDefaultSource!"
raise "Parameter #{param.name} does not have a default, cannot use AlwaysUseDefaultSource!"
end
end
end
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
18 changes: 10 additions & 8 deletions lib/moonshot/ask_user_source.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# frozen_string_literal: true

require 'colorize'

module Moonshot
class AskUserSource
def get(sp)
def get(param)
return unless Moonshot.config.interactive

@sp = sp
@param = param

prompt
loop do
input = gets.chomp

if String(input).empty? && @sp.default?
if String(input).empty? && @param.default?
# We will use the default value, print it here so the output is clear.
puts 'Using default value.'
return
elsif String(input).empty?
puts "Cannot proceed without value for #{@sp.name}!"
puts "Cannot proceed without value for #{@param.name}!"
else
@sp.set(String(input))
@param.set(String(input))
return
end

Expand All @@ -29,9 +31,9 @@ def get(sp)
private

def prompt
print "(#{@sp.name})".light_black
print " #{@sp.description}" unless @sp.description.empty?
print " [#{@sp.default}]".light_black if @sp.default?
print "(#{@param.name})".light_black
print " #{@param.description}" unless @param.description.empty?
print " [#{@param.default}]".light_black if @param.default?
print ': '
end
end
Expand Down
11 changes: 7 additions & 4 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 @@ -40,9 +42,9 @@ def doctor_hook
@build_mechanism.doctor_hook
end

def resources=(r)
def resources=(res)
super
@build_mechanism.resources = r
@build_mechanism.resources = res
end

def pre_build_hook(version)
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 master')
rescue => e
rescue StandardError => e
critical "`hub` failed, install hub and authorize it.\n#{e.message}"
else
success '`hub` installed and authorized.'
Expand Down
15 changes: 8 additions & 7 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,10 +64,8 @@ def run_script(step, env: {})
end

result = wait.value
if result.exitstatus == 0
step.success "Build script #{@script} exited successfully!"
end
unless result.exitstatus == 0
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")
step.failure "Build script #{@script} failed with exit status #{result.exitstatus}!"
Expand Down
10 changes: 5 additions & 5 deletions 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 @@ -25,17 +27,15 @@ def initialize(slug, pro: false, timeout: 900)
@cli_args = "-r #{@slug} #{@endpoint}"
end

def pre_build_hook(_)
end
def pre_build_hook(_); end

def build_hook(version)
job_number = find_build_and_job(version)
wait_for_job(job_number)
check_build(version)
end

def post_build_hook(_)
end
def post_build_hook(_); end

private

Expand Down Expand Up @@ -120,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
8 changes: 5 additions & 3 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 All @@ -19,10 +21,10 @@ def doctor_hook
@dev.doctor_hook
end

def resources=(r)
def resources=(res)
super
@release.resources = r
@dev.resources = r
@release.resources = res
@dev.resources = res
end

def pre_build_hook(version)
Expand Down
Loading

0 comments on commit 04bbbdf

Please sign in to comment.