diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0ef5d8305488090ed82992a1990379018119eb26..b7d7a6062acdd8af19bbb830481b5fd6ff7fd074 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -193,9 +193,11 @@ variables: RSPEC_MATCHING_TESTS_FOSS_PATH: rspec/matching_tests-foss.txt RSPEC_MATCHING_TESTS_PATH: rspec/matching_tests.txt RSPEC_PACKED_TESTS_MAPPING_PATH: crystalball/packed-mapping.json + RSPEC_PACKED_TESTS_MAPPING_ALT_PATH: crystalball/packed-mapping-alt.json RSPEC_PREDICTIVE_PIPELINE_TEMPLATE_YML: .gitlab/ci/rails/rspec-predictive.gitlab-ci.yml.erb RSPEC_PROFILING_FOLDER_PATH: rspec/profiling RSPEC_TESTS_MAPPING_PATH: crystalball/mapping.json + RSPEC_TESTS_MAPPING_ALT_PATH: crystalball/mapping-alt.json RSPEC_VIEWS_INCLUDING_PARTIALS_PATH: rspec/views_including_partials.txt RSPEC_AUTO_EXPLAIN_LOG_PATH: auto_explain/auto_explain.ndjson.gz TMP_TEST_FOLDER: "${CI_PROJECT_DIR}/tmp/tests" diff --git a/.gitlab/ci/pages.gitlab-ci.yml b/.gitlab/ci/pages.gitlab-ci.yml index ea4319809f9c56d394c675855d5df4169afa8654..f77ba19cde71762c8cb3844e6ebc19efc9163102 100644 --- a/.gitlab/ci/pages.gitlab-ci.yml +++ b/.gitlab/ci/pages.gitlab-ci.yml @@ -21,15 +21,16 @@ pages: script: - mv public/ .public/ - mkdir public/ - - mkdir -p public/$(dirname "$KNAPSACK_RSPEC_SUITE_REPORT_PATH") public/$(dirname "$FLAKY_RSPEC_SUITE_REPORT_PATH") public/$(dirname "$RSPEC_PACKED_TESTS_MAPPING_PATH") public/$(dirname "$FRONTEND_FIXTURES_MAPPING_PATH") + - mkdir -p public/$(dirname "$KNAPSACK_RSPEC_SUITE_REPORT_PATH") public/$(dirname "$FLAKY_RSPEC_SUITE_REPORT_PATH") public/$(dirname "$RSPEC_PACKED_TESTS_MAPPING_PATH") public/$(dirname "$RSPEC_PACKED_TESTS_MAPPING_ALT_PATH") public/$(dirname "$FRONTEND_FIXTURES_MAPPING_PATH") - mv coverage/ public/coverage-ruby/ || true - mv coverage-frontend/ public/coverage-frontend/ || true - mv storybook/public public/storybook || true - cp .public/assets/application-*.css public/application.css || true - mv $KNAPSACK_RSPEC_SUITE_REPORT_PATH public/$KNAPSACK_RSPEC_SUITE_REPORT_PATH || true - mv $FLAKY_RSPEC_SUITE_REPORT_PATH public/$FLAKY_RSPEC_SUITE_REPORT_PATH || true - - mv $RSPEC_PACKED_TESTS_MAPPING_PATH.gz public/$RSPEC_PACKED_TESTS_MAPPING_PATH.gz || true - - mv $FRONTEND_FIXTURES_MAPPING_PATH public/$FRONTEND_FIXTURES_MAPPING_PATH || true + - mv $RSPEC_PACKED_TESTS_MAPPING_PATH.gz public/ || true + - mv $RSPEC_PACKED_TESTS_MAPPING_ALT_PATH.gz public/ || true + - mv $FRONTEND_FIXTURES_MAPPING_PATH public/ || true - *compress-public artifacts: paths: diff --git a/.gitlab/ci/rules.gitlab-ci.yml b/.gitlab/ci/rules.gitlab-ci.yml index 5d3b4a6e022067bba121825620b111e2b4c47955..87d29989a43e53d243d27d01917fa55dd7136b56 100644 --- a/.gitlab/ci/rules.gitlab-ci.yml +++ b/.gitlab/ci/rules.gitlab-ci.yml @@ -2993,6 +2993,12 @@ changes: - ".gitlab/ci/test-metadata.gitlab-ci.yml" - "scripts/rspec_helpers.sh" + - <<: *if-merge-request + changes: + - ".gitlab/ci/test-metadata.gitlab-ci.yml" + - "scripts/rspec_helpers.sh" + when: manual + allow_failure: true - <<: *if-merge-request-not-approved when: never - <<: *if-merge-request diff --git a/.gitlab/ci/test-metadata.gitlab-ci.yml b/.gitlab/ci/test-metadata.gitlab-ci.yml index 5ecacce339c9b519b3dd63fd4b286dc2403320eb..8af330a5f29cb97c17c30ede3dc688290bf6d041 100644 --- a/.gitlab/ci/test-metadata.gitlab-ci.yml +++ b/.gitlab/ci/test-metadata.gitlab-ci.yml @@ -29,23 +29,23 @@ update-tests-metadata: - .tests-metadata-state - .test-metadata:rules:update-tests-metadata stage: post-test - dependencies: - - retrieve-tests-metadata - - generate-frontend-fixtures-mapping - - setup-test-env - - rspec migration pg14 - - rspec-all frontend_fixture - - rspec unit pg14 - - rspec unit clickhouse - - rspec integration pg14 - - rspec system pg14 - - rspec background_migration pg14 - - rspec-ee migration pg14 - - rspec-ee unit pg14 - - rspec-ee unit clickhouse - - rspec-ee integration pg14 - - rspec-ee system pg14 - - rspec-ee background_migration pg14 + needs: + - job: retrieve-tests-metadata + optional: true + - job: generate-frontend-fixtures-mapping + optional: true + - job: setup-test-env + optional: true + - job: rspec:artifact-collector unit + optional: true + - job: rspec:artifact-collector part-a + optional: true + - job: rspec:artifact-collector part-b + optional: true + - job: rspec:artifact-collector ee unit + optional: true + - job: rspec:artifact-collector ee remainder + optional: true script: - run_timed_command "retry gem install fog-aws mime-types activesupport rspec_profiling postgres-copy --no-document" - source ./scripts/rspec_helpers.sh diff --git a/scripts/rspec_helpers.sh b/scripts/rspec_helpers.sh index b025c2a7f53d7f3f6d4b00e2a0ba60c0cfde4208..771b8054952bb9923067dd489242284ee531bd71 100644 --- a/scripts/rspec_helpers.sh +++ b/scripts/rspec_helpers.sh @@ -72,19 +72,25 @@ function retrieve_frontend_fixtures_mapping() { } function update_tests_mapping() { - if ! crystalball_rspec_data_exists; then - echo "No crystalball rspec data found." - return 0 - fi + pack_and_gzip_mapping "${RSPEC_TESTS_MAPPING_PATH}" "${RSPEC_PACKED_TESTS_MAPPING_PATH}" crystalball/described/rspec*.yml - scripts/generate-test-mapping "${RSPEC_TESTS_MAPPING_PATH:-unknown_file}" crystalball/rspec*.yml - scripts/pack-test-mapping "${RSPEC_TESTS_MAPPING_PATH:-unknown_file}" "${RSPEC_PACKED_TESTS_MAPPING_PATH:-unknown_file}" - gzip "${RSPEC_PACKED_TESTS_MAPPING_PATH:-unknown_file}" - rm -f crystalball/rspec*.yml "${RSPEC_PACKED_TESTS_MAPPING_PATH:-unknown_file}" + pack_and_gzip_mapping "${RSPEC_TESTS_MAPPING_ALT_PATH}" "${RSPEC_PACKED_TESTS_MAPPING_ALT_PATH}" crystalball/coverage/rspec*.yml } -function crystalball_rspec_data_exists() { - compgen -G "crystalball/rspec*.yml" >/dev/null +function pack_and_gzip_mapping() { + local mapping_path="${1}" + local packed_path="${2}" + local crystal_yaml_files=("${@:3}") + + if test -z "${crystal_yaml_files[1]}"; then + echo "No crystalball rspec data for ${mapping_path}" + return 0 + fi + + scripts/generate-test-mapping "${mapping_path}" "${crystal_yaml_files[@]}" + scripts/pack-test-mapping "${mapping_path}" "${packed_path}" + gzip "${packed_path}" + rm -f "${packed_path}" "${mapping_path}" "${crystal_yaml_files[@]}" } function retrieve_failed_tests() { diff --git a/spec/crystalball_env.rb b/spec/crystalball_env.rb index 61721fcc20c52db980c4c5873ee7375d4a853bc9..da1c208cb6066069bd4d5935a3fcad0d961b8478 100644 --- a/spec/crystalball_env.rb +++ b/spec/crystalball_env.rb @@ -9,13 +9,16 @@ def start! return unless ENV['CRYSTALBALL'] == 'true' require 'crystalball' - require_relative '../tooling/lib/tooling/crystalball/described_class_execution_detector' - map_storage_path_base = ENV['CI_JOB_NAME'] || 'crystalball_data' - map_storage_path = "crystalball/#{map_storage_path_base.gsub(%r{[/ ]}, '_')}.yml" + enable_described_strategy # We use this for writing and reading + enable_coverage_strategy # We use this only for writing for now + end + + def enable_described_strategy + require_relative '../tooling/lib/tooling/crystalball/described_class_execution_detector' Crystalball::MapGenerator.start! do |config| - config.map_storage_path = map_storage_path + config.map_storage_path = "crystalball/described/#{map_storage_name}.yml" # https://toptal.github.io/crystalball/map_generators/#describedclassstrategy described_class_execution_detector = Tooling::Crystalball::DescribedClassExecutionDetector.new( @@ -25,18 +28,30 @@ def start! config.register Crystalball::MapGenerator::DescribedClassStrategy.new( execution_detector: described_class_execution_detector ) + end + end - # Modified version of https://toptal.github.io/crystalball/map_generators/#coveragestrategy - # - # require_relative '../tooling/lib/tooling/crystalball/coverage_lines_execution_detector' - # require_relative '../tooling/lib/tooling/crystalball/coverage_lines_strategy' - # execution_detector = Tooling::Crystalball::CoverageLinesExecutionDetector.new( - # exclude_prefixes: EXCLUDED_PREFIXES - # ) - # config.register Tooling::Crystalball::CoverageLinesStrategy.new(execution_detector) + def enable_coverage_strategy + # Modified version of https://toptal.github.io/crystalball/map_generators/#coveragestrategy + require_relative '../tooling/lib/tooling/crystalball/coverage_lines_execution_detector' + require_relative '../tooling/lib/tooling/crystalball/coverage_lines_strategy' + + Crystalball::MapGenerator.start! do |config| + config.map_storage_path = "crystalball/coverage/#{map_storage_name}.yml" + + execution_detector = Tooling::Crystalball::CoverageLinesExecutionDetector + .new(exclude_prefixes: EXCLUDED_PREFIXES) + + config.register Tooling::Crystalball::CoverageLinesStrategy + .new(execution_detector) # https://toptal.github.io/crystalball/map_generators/#actionviewstrategy + # require 'crystalball/rails/map_generator/action_view_strategy' # config.register Crystalball::Rails::MapGenerator::ActionViewStrategy.new end end + + def map_storage_name + (ENV['CI_JOB_NAME'] || 'crystalball_data').gsub(%r{[/ ]}, '_') + end end