Merge branch 'ml-skip-package-and-qa-when-only-quarantining-tests' into 'master'

Skip package-and-qa if an MR only quarantines tests

See merge request gitlab-org/gitlab!73041
This commit is contained in:
Rémy Coutable 2021-11-04 11:29:59 +00:00
commit b68665c3c8
5 changed files with 64 additions and 8 deletions

View file

@ -55,8 +55,14 @@ update-qa-cache:
before_script:
- source scripts/utils.sh
- install_gitlab_gem
- tooling/bin/find_change_diffs ${CHANGES_DIFFS_DIR}
script:
- ./scripts/trigger-build omnibus
- |
if tooling/bin/qa/check_if_only_quarantined_specs ${CHANGES_DIFFS_DIR}; then
exit 0
else
./scripts/trigger-build omnibus
fi
# These jobs often time out, so temporarily use private runners and a long timeout: https://gitlab.com/gitlab-org/gitlab/-/issues/238563
tags:
- prm
@ -66,14 +72,19 @@ update-qa-cache:
artifacts: false
- job: build-assets-image
artifacts: false
- detect-tests
artifacts:
expire_in: 7d
paths:
- ${CHANGES_FILE}
- ${CHANGES_DIFFS_DIR}/*
variables:
CHANGES_FILE: tmp/changed_files.txt
CHANGES_DIFFS_DIR: tmp/diffs
.package-and-qa-ff-base:
needs:
- detect-tests
variables:
CHANGED_FILES: tmp/changed_files.txt
script:
- export GITLAB_QA_OPTIONS="--set-feature-flags $(scripts/changed-feature-flags --files $(cat $CHANGED_FILES | tr ' ' ',') --state $QA_FF_STATE)"
- export GITLAB_QA_OPTIONS="--set-feature-flags $(scripts/changed-feature-flags --files $(cat $CHANGES_FILE | tr ' ' ',') --state $QA_FF_STATE)"
- echo $GITLAB_QA_OPTIONS
- ./scripts/trigger-build omnibus

View file

@ -1258,7 +1258,7 @@
.rails:rules:detect-tests:
rules:
- changes: *code-backstage-patterns
- changes: *code-backstage-qa-patterns
- <<: *if-merge-request-labels-run-all-rspec
.rails:rules:detect-previous-failed-tests:

View file

@ -123,7 +123,7 @@ Naming/FileName:
- 'ee/lib/generators/**/*'
- 'scripts/**/*'
- 'spec/**/*'
- 'tooling/bin/*'
- 'tooling/bin/**/*'
- 'ee/spec/**/*'
- 'jh/spec/**/*'
- 'qa/bin/*'

27
tooling/bin/find_change_diffs Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'gitlab'
require 'pathname'
# This script saves the diffs of changes in an MR to the directory specified as the first argument
gitlab_token = ENV.fetch('PROJECT_TOKEN_FOR_CI_SCRIPTS_API_USAGE')
gitlab_endpoint = ENV.fetch('CI_API_V4_URL')
mr_project_path = ENV.fetch('CI_MERGE_REQUEST_PROJECT_PATH')
mr_iid = ENV.fetch('CI_MERGE_REQUEST_IID')
abort("ERROR: Please specify a directory to write MR diffs into.") if ARGV.empty?
output_diffs_dir = Pathname.new(ARGV.shift).expand_path
Gitlab.configure do |config|
config.endpoint = gitlab_endpoint
config.private_token = gitlab_token
end
Gitlab.merge_request_changes(mr_project_path, mr_iid).changes.each do |change|
next if change['diff'].empty?
output_diffs_dir.join(File.dirname(change['new_path'])).mkpath
output_diffs_dir.join("#{change['new_path']}.diff").write(change['diff'])
end

View file

@ -0,0 +1,18 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'pathname'
# This script assumes the first argument is a directory of files containing diffs of changes from an MR. It exits with a
# success code if all diffs add a line that quarantines a test. If any diffs are not specs, or they are specs that don't
# quarantine a test, it exits with code 1 to indicate failure (i.e., there was _not_ only quarantined specs).
abort("ERROR: Please specify the directory containing MR diffs.") if ARGV.empty?
diffs_dir = Pathname.new(ARGV.shift).expand_path
diffs_dir.glob('**/*').each do |path|
next if path.directory?
exit 1 unless path.to_s.end_with?('_spec.rb.diff')
exit 1 unless path.read.match?(/^\+.*, quarantine:/)
end