diff options
author | drew cimino <dcimino@gitlab.com> | 2019-07-09 17:29:45 -0400 |
---|---|---|
committer | drew cimino <dcimino@gitlab.com> | 2019-07-10 23:27:01 -0400 |
commit | 610bd121842f5348aef97ef002734c6f15065f8b (patch) | |
tree | 6a6da3c92f322c2324230f772a9f593f74ad8b72 | |
parent | 48fa47e07d54979b70704beb16ea55548f2190c4 (diff) | |
download | gitlab-ce-downtime-check-fix-master.tar.gz |
passing source and target ref to downtime_check rake taskdowntime-check-fix-master
-rw-r--r-- | .gitlab/ci/rails.gitlab-ci.yml | 9 | ||||
-rw-r--r-- | lib/tasks/downtime_check.rake | 4 | ||||
-rw-r--r-- | lib/tasks/gitlab/db.rake | 9 |
3 files changed, 16 insertions, 6 deletions
diff --git a/.gitlab/ci/rails.gitlab-ci.yml b/.gitlab/ci/rails.gitlab-ci.yml index 2d06a8acc58..657f03c0650 100644 --- a/.gitlab/ci/rails.gitlab-ci.yml +++ b/.gitlab/ci/rails.gitlab-ci.yml @@ -209,6 +209,15 @@ downtime_check: dependencies: - setup-test-env +mr_downtime_check: + extends: .dedicated-no-docs-no-db-pull-cache-job + script: + - bundle exec rake downtime_check[$CI_COMMIT_REF_NAME,$CI_MERGE_REQUEST_TARGET_BRANCH_SHA] + only: + - merge_requests + dependencies: + - setup-test-env + ee_compat_check: <<: *rake-exec dependencies: [] diff --git a/lib/tasks/downtime_check.rake b/lib/tasks/downtime_check.rake index 557f4fef10b..b17b08fa7ad 100644 --- a/lib/tasks/downtime_check.rake +++ b/lib/tasks/downtime_check.rake @@ -1,5 +1,5 @@ desc 'Checks if migrations in a branch require downtime' -task downtime_check: :environment do +task :downtime_check, [:source_sha, :target_sha] => :environment do |_, args| repo = if defined?(Gitlab::License) 'gitlab-ee' else @@ -8,5 +8,5 @@ task downtime_check: :environment do `git fetch https://gitlab.com/gitlab-org/#{repo}.git --depth 1` - Rake::Task['gitlab:db:downtime_check'].invoke('FETCH_HEAD') + Rake::Task['gitlab:db:downtime_check'].invoke((args[:source_sha] || 'FETCH_HEAD'), args[:target_sha]) end diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index 4e7a8adbef6..2ca893a360e 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -63,14 +63,15 @@ namespace :gitlab do end desc 'Checks if migrations require downtime or not' - task :downtime_check, [:ref] => :environment do |_, args| - abort 'You must specify a Git reference to compare with' unless args[:ref] + task :downtime_check, [:source_ref, :target_ref] => :environment do |_, args| + abort 'You must specify a Git reference to compare with' if args[:source_ref].blank? require 'shellwords' - ref = Shellwords.escape(args[:ref]) + source_ref = Shellwords.escape(args[:source_ref]) + target_ref = Shellwords.escape(args[:target_ref]) - migrations = `git diff #{ref}.. --diff-filter=A --name-only -- db/migrate`.lines + migrations = `git diff #{source_ref}..#{target_ref} --diff-filter=A --name-only -- db/migrate`.lines .map { |file| Rails.root.join(file.strip).to_s } .select { |file| File.file?(file) } .select { |file| /\A[0-9]+.*\.rb\z/ =~ File.basename(file) } |