Commit 13cdd3f8 authored by Albert Salim's avatar Albert Salim

Merge branch 'workaround-require_relative' into 'master'

Use `.rb` as the script name so it can be required

See merge request gitlab-org/gitlab!51263
parents c2b21d3c bd88dfaf
...@@ -38,7 +38,7 @@ review-build-cng: ...@@ -38,7 +38,7 @@ review-build-cng:
- BUILD_TRIGGER_TOKEN=$REVIEW_APPS_BUILD_TRIGGER_TOKEN ./scripts/trigger-build cng - BUILD_TRIGGER_TOKEN=$REVIEW_APPS_BUILD_TRIGGER_TOKEN ./scripts/trigger-build cng
# When the job is manual, review-deploy is also manual and we don't want people # When the job is manual, review-deploy is also manual and we don't want people
# to have to manually start the jobs in sequence, so we do it for them. # to have to manually start the jobs in sequence, so we do it for them.
- '[ -z $CI_JOB_MANUAL ] || scripts/api/play_job --job-name "review-deploy"' - '[ -z $CI_JOB_MANUAL ] || scripts/api/play_job.rb --job-name "review-deploy"'
.review-workflow-base: .review-workflow-base:
extends: extends:
...@@ -78,8 +78,8 @@ review-deploy: ...@@ -78,8 +78,8 @@ review-deploy:
- disable_sign_ups || (delete_release && exit 1) - disable_sign_ups || (delete_release && exit 1)
# When the job is manual, review-qa-smoke is also manual and we don't want people # When the job is manual, review-qa-smoke is also manual and we don't want people
# to have to manually start the jobs in sequence, so we do it for them. # to have to manually start the jobs in sequence, so we do it for them.
- '[ -z $CI_JOB_MANUAL ] || scripts/api/play_job --job-name "review-qa-smoke"' - '[ -z $CI_JOB_MANUAL ] || scripts/api/play_job.rb --job-name "review-qa-smoke"'
- '[ -z $CI_JOB_MANUAL ] || scripts/api/play_job --job-name "review-performance"' - '[ -z $CI_JOB_MANUAL ] || scripts/api/play_job.rb --job-name "review-performance"'
after_script: after_script:
# Run seed-dast-test-data.sh only when DAST_RUN is set to true. This is to pupulate review app with data for DAST scan. # Run seed-dast-test-data.sh only when DAST_RUN is set to true. This is to pupulate review app with data for DAST scan.
# Set DAST_RUN to true when jobs are manually scheduled. # Set DAST_RUN to true when jobs are manually scheduled.
......
# frozen_string_literal: true # frozen_string_literal: true
FILE_EXTENSION = ".rb" FILE_EXTENSION = ".rb"
MAGIC_COMMENT = "# frozen_string_literal: true" FROZEN_STRING_MAGIC_COMMENT = "# frozen_string_literal: true"
SHEBANG_COMMENT = "#!"
def get_files_with_no_magic_comment(files) def get_files_with_no_magic_comment(files)
files.select do |file| files.select do |path|
file.end_with?(FILE_EXTENSION) && path.end_with?(FILE_EXTENSION) &&
!File.open(file, &:gets)&.start_with?(MAGIC_COMMENT) file_has_frozen_string_magic_comment?(path)
end end
end end
def file_has_frozen_string_magic_comment?(path)
File.open(path) do |file|
first_line = file.gets
line_has_frozen_string_magic_comment?(first_line) ||
(line_has_shebang?(first_line) &&
line_has_frozen_string_magic_comment?(file.gets))
end
end
def line_has_frozen_string_magic_comment?(line)
line&.start_with?(FROZEN_STRING_MAGIC_COMMENT)
end
def line_has_shebang?(line)
line&.start_with?(SHEBANG_COMMENT)
end
files_to_fix = get_files_with_no_magic_comment(git.added_files) files_to_fix = get_files_with_no_magic_comment(git.added_files)
if files_to_fix.any? if files_to_fix.any?
...@@ -20,7 +39,7 @@ if files_to_fix.any? ...@@ -20,7 +39,7 @@ if files_to_fix.any?
markdown(<<~MARKDOWN) markdown(<<~MARKDOWN)
## Enable Frozen String Literal ## Enable Frozen String Literal
The following files should have `#{MAGIC_COMMENT}` on the first line: The following files should have `#{FROZEN_STRING_MAGIC_COMMENT}` on the first line:
* #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")} * #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")}
MARKDOWN MARKDOWN
......
...@@ -14,7 +14,6 @@ class PlayJob ...@@ -14,7 +14,6 @@ class PlayJob
}.freeze }.freeze
def initialize(options) def initialize(options)
@project = options.delete(:project)
@options = options @options = options
Gitlab.configure do |config| Gitlab.configure do |config|
...@@ -24,14 +23,18 @@ class PlayJob ...@@ -24,14 +23,18 @@ class PlayJob
end end
def execute def execute
job = JobFinder.new(project, options.slice(:api_token, :pipeline_id, :job_name).merge(scope: 'manual')).execute job = JobFinder.new(options.slice(:project, :api_token, :pipeline_id, :job_name).merge(scope: 'manual')).execute
Gitlab.job_play(project, job.id) Gitlab.job_play(project, job.id)
end end
private private
attr_reader :project, :options attr_reader :options
def project
options[:project]
end
end end
if $0 == __FILE__ if $0 == __FILE__
......
...@@ -7,14 +7,14 @@ function retrieve_tests_metadata() { ...@@ -7,14 +7,14 @@ function retrieve_tests_metadata() {
local test_metadata_job_id local test_metadata_job_id
# Ruby # Ruby
test_metadata_job_id=$(scripts/api/get_job_id --project "${project_path}" -q "status=success" -q "ref=master" -q "username=gitlab-bot" -Q "scope=success" --job-name "update-tests-metadata") test_metadata_job_id=$(scripts/api/get_job_id.rb --project "${project_path}" -q "status=success" -q "ref=master" -q "username=gitlab-bot" -Q "scope=success" --job-name "update-tests-metadata")
if [[ ! -f "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ]]; then if [[ ! -f "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ]]; then
scripts/api/download_job_artifact --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" scripts/api/download_job_artifact.rb --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}"
fi fi
if [[ ! -f "${FLAKY_RSPEC_SUITE_REPORT_PATH}" ]]; then if [[ ! -f "${FLAKY_RSPEC_SUITE_REPORT_PATH}" ]]; then
scripts/api/download_job_artifact --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${FLAKY_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${FLAKY_RSPEC_SUITE_REPORT_PATH}" scripts/api/download_job_artifact.rb --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${FLAKY_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${FLAKY_RSPEC_SUITE_REPORT_PATH}"
fi fi
} }
...@@ -42,10 +42,10 @@ function retrieve_tests_mapping() { ...@@ -42,10 +42,10 @@ function retrieve_tests_mapping() {
local project_path="gitlab-org/gitlab" local project_path="gitlab-org/gitlab"
local test_metadata_with_mapping_job_id local test_metadata_with_mapping_job_id
test_metadata_with_mapping_job_id=$(scripts/api/get_job_id --project "${project_path}" -q "status=success" -q "ref=master" -q "username=gitlab-bot" -Q "scope=success" --job-name "update-tests-metadata" --artifact-path "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") test_metadata_with_mapping_job_id=$(scripts/api/get_job_id.rb --project "${project_path}" -q "status=success" -q "ref=master" -q "username=gitlab-bot" -Q "scope=success" --job-name "update-tests-metadata" --artifact-path "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz")
if [[ ! -f "${RSPEC_PACKED_TESTS_MAPPING_PATH}" ]]; then if [[ ! -f "${RSPEC_PACKED_TESTS_MAPPING_PATH}" ]]; then
(scripts/api/download_job_artifact --project "${project_path}" --job-id "${test_metadata_with_mapping_job_id}" --artifact-path "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" && gzip -d "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") || echo "{}" > "${RSPEC_PACKED_TESTS_MAPPING_PATH}" (scripts/api/download_job_artifact.rb --project "${project_path}" --job-id "${test_metadata_with_mapping_job_id}" --artifact-path "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" && gzip -d "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") || echo "{}" > "${RSPEC_PACKED_TESTS_MAPPING_PATH}"
fi fi
scripts/unpack-test-mapping "${RSPEC_PACKED_TESTS_MAPPING_PATH}" "${RSPEC_TESTS_MAPPING_PATH}" scripts/unpack-test-mapping "${RSPEC_PACKED_TESTS_MAPPING_PATH}" "${RSPEC_TESTS_MAPPING_PATH}"
......
...@@ -89,12 +89,12 @@ function echosuccess() { ...@@ -89,12 +89,12 @@ function echosuccess() {
function fail_pipeline_early() { function fail_pipeline_early() {
local dont_interrupt_me_job_id local dont_interrupt_me_job_id
dont_interrupt_me_job_id=$(scripts/api/get_job_id --job-query "scope=success" --job-name "dont-interrupt-me") dont_interrupt_me_job_id=$(scripts/api/get_job_id.rb --job-query "scope=success" --job-name "dont-interrupt-me")
if [[ -n "${dont_interrupt_me_job_id}" ]]; then if [[ -n "${dont_interrupt_me_job_id}" ]]; then
echoinfo "This pipeline cannot be interrupted due to \`dont-interrupt-me\` job ${dont_interrupt_me_job_id}" echoinfo "This pipeline cannot be interrupted due to \`dont-interrupt-me\` job ${dont_interrupt_me_job_id}"
else else
echoinfo "Failing pipeline early for fast feedback due to test failures in rspec fail-fast." echoinfo "Failing pipeline early for fast feedback due to test failures in rspec fail-fast."
scripts/api/cancel_pipeline scripts/api/cancel_pipeline.rb
fi fi
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment