From 8c9773b8836b181713fe3691e0a2eb3028408de6 Mon Sep 17 00:00:00 2001 From: Rutuja Dhimate <73694479+rutuja810@users.noreply.github.com> Date: Thu, 14 Mar 2024 21:43:34 +0530 Subject: [PATCH] CPD-10296: Updated activesupport gem. (#309) Change: minor Purpose: maintenance Co-authored-by: rutuja810 --- lib/moonshot/build_mechanism/travis_deploy.rb | 129 ---------------- moonshot.gemspec | 3 +- .../build_mechanism/travis_deploy_spec.rb | 141 ------------------ 3 files changed, 1 insertion(+), 272 deletions(-) delete mode 100644 lib/moonshot/build_mechanism/travis_deploy.rb delete mode 100644 spec/moonshot/build_mechanism/travis_deploy_spec.rb diff --git a/lib/moonshot/build_mechanism/travis_deploy.rb b/lib/moonshot/build_mechanism/travis_deploy.rb deleted file mode 100644 index abd69384..00000000 --- a/lib/moonshot/build_mechanism/travis_deploy.rb +++ /dev/null @@ -1,129 +0,0 @@ -# frozen_string_literal: true - -require 'moonshot/shell' -require 'travis' -require 'travis/pro' -require 'travis/client/auto_login' - -module Moonshot::BuildMechanism - # This simply waits for Travis-CI to finish building a job matching the - # version and 'BUILD=1'. - class TravisDeploy - include Moonshot::ResourcesHelper - include Moonshot::DoctorHelper - include Moonshot::Shell - - MAX_BUILD_FIND_ATTEMPTS = 10 - - attr_reader :output_file - - def initialize(slug, pro: false, timeout: 900) - @slug = slug - @pro = pro - @timeout = timeout - - @endpoint = pro ? '--pro' : '--org' - @travis_base = @pro ? Travis::Pro : Travis - @cli_args = "-r #{@slug} #{@endpoint}" - 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 - - private - - # Authenticates with the proper travis service. - def authenticate - Travis::Client::AutoLogin.new(@travis_base).authenticate - end - - # Retrieves the travis repository. - # - # @return [Travis::Client::Repository] - def repo - @repo ||= @travis_base::Repository.find(@slug) - end - - def find_build_and_job(version) - job_number = nil - ilog.start_threaded('Find Travis CI build') do |step| - job_number = wait_for_build(version) - - step.success("Travis CI ##{job_number.gsub(/\..*/, '')} running.") - end - job_number - end - - # Looks for the travis build and attempts to retry if the build does not - # exist yet. - # - # @param verison [String] Build version to look for. - # - # @return [String] Job number for the travis build. - def wait_for_build(version) - # Attempt to find the build. Re-attempt if the build can not - # be found on travis yet. - retry_opts = { - tries: MAX_BUILD_FIND_ATTEMPTS, - base_interval: 10 - } - job_number = nil - sh_retry("bundle exec travis show #{@cli_args} #{version}", - opts: retry_opts) do |build_out| - raise CommandError, "Build for #{version} not found.\n#{build_out}" \ - unless (job_number = build_out.match(/^#(\d+\.\d+) .+BUILD=1.+/)[1]) - end - job_number - end - - # Waits for a job to complete, within the defined timeout. - # - # @param job_number [String] The job number to wait for. - def wait_for_job(job_number) - authenticate - - # Wait for the job to complete or hit the timeout. - start = Time.new - job = repo.job(job_number) - ilog.start_threaded("Waiting for job #{job_number} to complete.") do |s| - while !job.finished? && Time.new - start < @timeout - s.continue("Job status: #{job.state}") - sleep 10 - job.reload - end - - if job.finished? - s.success - else - s.failure("Job #{job_number} did not complete within time limit of " \ - "#{@timeout} seconds") - end - end - end - - def check_build(version) - cmd = "bundle exec travis show #{@cli_args} #{version}" - sh_step(cmd) do |step, out| - raise "Build didn't pass.\n#{out}" \ - if out =~ /^#(\d+\.\d+) (?!passed).+BUILD=1.+/ - - step.success("Travis CI build for #{version} passed.") - end - end - - def doctor_check_travis_auth - sh_out("bundle exec travis raw #{@endpoint} repos/#{@slug}") - rescue StandardError => e - critical "`travis` not available or not authorized.\n#{e.message}" - else - success '`travis` installed and authorized.' - end - end -end diff --git a/moonshot.gemspec b/moonshot.gemspec index 0a4daff6..50f132c7 100644 --- a/moonshot.gemspec +++ b/moonshot.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.add_dependency('aws-sdk', '~> 2.0', '>= 2.2.0') s.required_ruby_version = '>= 3.1.2' - s.add_dependency('activesupport') + s.add_dependency('activesupport', '= 6.1.7.1') s.add_dependency('colorize') s.add_dependency('highline') s.add_dependency('interactive-logger') @@ -29,7 +29,6 @@ Gem::Specification.new do |s| s.add_dependency('ruby-duration') s.add_dependency('semantic') s.add_dependency('thor') - s.add_dependency('travis') s.add_dependency('vandamme') s.add_development_dependency('fakefs') diff --git a/spec/moonshot/build_mechanism/travis_deploy_spec.rb b/spec/moonshot/build_mechanism/travis_deploy_spec.rb deleted file mode 100644 index faab5eba..00000000 --- a/spec/moonshot/build_mechanism/travis_deploy_spec.rb +++ /dev/null @@ -1,141 +0,0 @@ -# coding: utf-8 -module Moonshot # rubocop:disable Metrics/ModuleLength - describe BuildMechanism::TravisDeploy do - let(:resources) do - Resources.new( - ilog: double(InteractiveLogger).as_null_object, - stack: double(Stack).as_null_object, - controller: instance_double(Moonshot::Controller).as_null_object - ) - end - let(:slug) { 'myorg/myrepo' } - - subject do - s = described_class.new(slug) - s.resources = resources - s - end - - describe '#doctor_hook' do - it 'should call our hooks' do - allow(subject).to receive(:puts) - expect(subject).to receive(:puts).with('we did it') - expect(subject).to receive(:print).with(' ✓ '.green) - expect(subject).to receive(:doctor_check_travis_auth) do - subject.send(:success, 'we did it') - end - subject.doctor_hook - end - - describe '#doctor_check_travis_auth' do - it 'should pass if travis exits 0' do - expect(subject).to receive(:sh_out) - .with('bundle exec travis raw --org repos/myorg/myrepo') - expect(subject).to receive(:success) - .with('`travis` installed and authorized.') - subject.send(:doctor_check_travis_auth) - end - - it 'should pass fail travis exits 1' do - expect(subject).to receive(:sh_out) - .with('bundle exec travis raw --org repos/myorg/myrepo') - .and_raise(RuntimeError, 'stuffs broke man') - expect(subject).to receive(:critical) - .with("`travis` not available or not authorized.\nstuffs broke man") - subject.send(:doctor_check_travis_auth) - end - end - end - - describe '#wait_for_build' do - let(:tag) { '0.0.0-rspec' } - let(:job_number) { '1401.3' } - let(:output) do - "Build #1401: Merge pull request #245 from respectest/updChange\n" \ - "State: passed\nType: push\n" \ - "Branch: 0.0.0-rspec\n" \ - "Compare URL: https://github.com/acquia/moonshot/compare/0.0.0-rspec\n" \ - "Duration: 5 min 50 sec\nStarted: 2016-06-30 16:05:34\n" \ - "Finished: 2016-06-30 16:06:48\n\n" \ - "#1401.1 passed: 1 min 13 sec rvm: 2.1.7, os: linux\n" \ - "#1401.2 passed: 1 min 14 sec rvm: 2.2.3, os: linux\n" \ - '#1401.3 passed: 3 min 23 sec rvm: 2.2.3, env: BUILD=1, ' \ - 'gemfile: .travis.build.Gemfile, os: linux ' - end - - before(:each) do - Retriable.configure do |c| - c.sleep_disabled = true - end - end - - it 'should return the right job number' do - expect(subject).to receive(:sh_out).and_return(output).once - - expect(subject.send(:wait_for_build, tag)).to eq(job_number) - end - - it 'should only make the max number of attempts before failing' do - expect(subject).to receive(:sh_out).and_raise.exactly(10).times - - expect { subject.send(:wait_for_build, tag) }.to \ - raise_error(RuntimeError) - end - - it 'should make attempts until the build is found' do - expect(subject).to receive(:sh_out).and_raise.twice - expect(subject).to receive(:sh_out).and_return(output) - - expect(subject.send(:wait_for_build, tag)).to eq(job_number) - end - end - - describe '#wait_for_job' do - let(:job_number) { '1401.3' } - let(:repo) do - instance_double(Travis::Client::Repository) - end - let(:step) do - instance_double(InteractiveLogger::Step) - end - let(:job) do - instance_double( - Travis::Client::Job, - state: 'received', - finished?: false, - reload: nil - ) - end - - before(:each) do - allow(subject).to receive(:authenticate) - allow(subject).to receive(:repo).and_return(repo) - allow(repo).to receive(:job).with(job_number).and_return(job) - end - - it 'should continue until the job is complete' do - expect(job).to receive(:state).and_return('started').exactly(3).times - expect(job).to receive(:finished?).and_return(false).exactly(3).times - expect(job).to receive(:finished?).and_return(true).twice - expect(subject).to receive(:sleep).with(10).exactly(3).times - - expect(resources.ilog).to receive(:start_threaded).and_yield(step) - expect(step).to receive(:continue).with('Job status: started') - .exactly(3).times - expect(step).to receive(:success) - - subject.send(:wait_for_job, job_number) - end - - it 'should fail if the job does not complete within the time limit' do - expect(resources.ilog).to receive(:start_threaded).and_yield(step) - expect(step).to receive(:continue).at_least(9) - expect(step).to receive(:failure) - expect(subject).to receive(:sleep).at_least(:once) { sleep 0.1 } - - subject.instance_variable_set(:@timeout, 1) - subject.send(:wait_for_job, job_number) - end - end - end -end