diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/detect-new-flaky-examples | 4 | ||||
-rwxr-xr-x | scripts/gitaly-test-build | 10 | ||||
-rwxr-xr-x | scripts/gitaly-test-spawn | 4 | ||||
-rw-r--r-- | scripts/gitaly_test.rb | 54 | ||||
-rwxr-xr-x | scripts/lint-changelog-yaml | 8 | ||||
-rwxr-xr-x | scripts/lint-rugged | 10 | ||||
-rwxr-xr-x | scripts/merge-reports | 8 | ||||
-rwxr-xr-x | scripts/merge-simplecov | 12 | ||||
-rwxr-xr-x | scripts/no-ee-check | 4 | ||||
-rwxr-xr-x | scripts/prune-old-flaky-specs | 8 | ||||
-rwxr-xr-x | scripts/review_apps/automated_cleanup.rb | 42 | ||||
-rwxr-xr-x | scripts/security-harness | 10 | ||||
-rwxr-xr-x | scripts/static-analysis | 20 | ||||
-rwxr-xr-x | scripts/sync-reports | 30 | ||||
-rwxr-xr-x | scripts/trigger-build | 71 | ||||
-rwxr-xr-x | scripts/trigger-build-docs | 32 |
16 files changed, 162 insertions, 165 deletions
diff --git a/scripts/detect-new-flaky-examples b/scripts/detect-new-flaky-examples index 3bee4f9a34b..b818cdcff5d 100755 --- a/scripts/detect-new-flaky-examples +++ b/scripts/detect-new-flaky-examples @@ -1,10 +1,10 @@ #!/usr/bin/env ruby -require 'json' +require "json" report_file = ARGV.shift unless report_file - puts 'usage: detect-new-flaky-examples <report-file>' + puts "usage: detect-new-flaky-examples <report-file>" exit 1 end diff --git a/scripts/gitaly-test-build b/scripts/gitaly-test-build index 374401caf89..070e01e466a 100755 --- a/scripts/gitaly-test-build +++ b/scripts/gitaly-test-build @@ -1,8 +1,8 @@ #!/usr/bin/env ruby -require 'fileutils' +require "fileutils" -require_relative 'gitaly_test' +require_relative "gitaly_test" # This script assumes tmp/tests/gitaly already contains the correct # Gitaly version. We just have to compile it and run its 'bundle @@ -12,18 +12,18 @@ class GitalyTestBuild include GitalyTest def run - abort 'gitaly build failed' unless system(env, 'make', chdir: tmp_tests_gitaly_dir) + abort "gitaly build failed" unless system(env, "make", chdir: tmp_tests_gitaly_dir) check_gitaly_config! # Starting gitaly further validates its configuration pid = start_gitaly - Process.kill('TERM', pid) + Process.kill("TERM", pid) # Make the 'gitaly' executable look newer than 'GITALY_SERVER_VERSION'. # Without this a gitaly executable created in the setup-test-env job # will look stale compared to GITALY_SERVER_VERSION. - FileUtils.touch(File.join(tmp_tests_gitaly_dir, 'gitaly'), mtime: Time.now + (1 << 24)) + FileUtils.touch(File.join(tmp_tests_gitaly_dir, "gitaly"), mtime: Time.now + (1 << 24)) end end diff --git a/scripts/gitaly-test-spawn b/scripts/gitaly-test-spawn index e9f91f75650..2c816c5b887 100755 --- a/scripts/gitaly-test-spawn +++ b/scripts/gitaly-test-spawn @@ -2,7 +2,7 @@ # This script is used both in CI and in local development 'rspec' runs. -require_relative 'gitaly_test' +require_relative "gitaly_test" class GitalyTestSpawn include GitalyTest @@ -16,7 +16,7 @@ class GitalyTestSpawn pid = start_gitaly # In local development this pid file is used by rspec. - IO.write(File.expand_path('../tmp/tests/gitaly.pid', __dir__), pid) + IO.write(File.expand_path("../tmp/tests/gitaly.pid", __dir__), pid) end end diff --git a/scripts/gitaly_test.rb b/scripts/gitaly_test.rb index dee4c2eba7e..0a7ec4fb779 100644 --- a/scripts/gitaly_test.rb +++ b/scripts/gitaly_test.rb @@ -4,48 +4,48 @@ # Please be careful when modifying this file. Your changes must work # both for local development rspec runs, and in CI. -require 'socket' +require "socket" module GitalyTest def tmp_tests_gitaly_dir - File.expand_path('../tmp/tests/gitaly', __dir__) + File.expand_path("../tmp/tests/gitaly", __dir__) end def gemfile - File.join(tmp_tests_gitaly_dir, 'ruby', 'Gemfile') + File.join(tmp_tests_gitaly_dir, "ruby", "Gemfile") end def env env_hash = { - 'HOME' => File.expand_path('tmp/tests'), - 'GEM_PATH' => Gem.path.join(':'), - 'BUNDLE_APP_CONFIG' => File.join(File.dirname(gemfile), '.bundle/config'), - 'BUNDLE_FLAGS' => "--jobs=4 --retry=3", - 'BUNDLE_INSTALL_FLAGS' => nil, - 'BUNDLE_GEMFILE' => gemfile, - 'RUBYOPT' => nil + "HOME" => File.expand_path("tmp/tests"), + "GEM_PATH" => Gem.path.join(":"), + "BUNDLE_APP_CONFIG" => File.join(File.dirname(gemfile), ".bundle/config"), + "BUNDLE_FLAGS" => "--jobs=4 --retry=3", + "BUNDLE_INSTALL_FLAGS" => nil, + "BUNDLE_GEMFILE" => gemfile, + "RUBYOPT" => nil, } - if ENV['CI'] - bundle_path = File.expand_path('../vendor/gitaly-ruby', __dir__) - env_hash['BUNDLE_FLAGS'] << " --path=#{bundle_path}" + if ENV["CI"] + bundle_path = File.expand_path("../vendor/gitaly-ruby", __dir__) + env_hash["BUNDLE_FLAGS"] << " --path=#{bundle_path}" end env_hash end def config_path - File.join(tmp_tests_gitaly_dir, 'config.toml') + File.join(tmp_tests_gitaly_dir, "config.toml") end def start_gitaly args = %W[#{tmp_tests_gitaly_dir}/gitaly #{config_path}] - pid = spawn(env, *args, [:out, :err] => 'log/gitaly-test.log') + pid = spawn(env, *args, [:out, :err] => "log/gitaly-test.log") begin try_connect! rescue - Process.kill('TERM', pid) + Process.kill("TERM", pid) raise end @@ -53,8 +53,8 @@ module GitalyTest end def check_gitaly_config! - puts 'Checking gitaly-ruby bundle...' - abort 'bundle check failed' unless system(env, 'bundle', 'check', chdir: File.dirname(gemfile)) + puts "Checking gitaly-ruby bundle..." + abort "bundle check failed" unless system(env, "bundle", "check", chdir: File.dirname(gemfile)) end def read_socket_path @@ -79,18 +79,16 @@ module GitalyTest socket = read_socket_path Integer(timeout / delay).times do - begin - UNIXSocket.new(socket) - puts ' OK' - - return - rescue Errno::ENOENT, Errno::ECONNREFUSED - print '.' - sleep delay - end + UNIXSocket.new(socket) + puts " OK" + + return + rescue Errno::ENOENT, Errno::ECONNREFUSED + print "." + sleep delay end - puts ' FAILED' + puts " FAILED" raise "could not connect to #{socket}" end diff --git a/scripts/lint-changelog-yaml b/scripts/lint-changelog-yaml index 06d502c4676..74c530f7803 100755 --- a/scripts/lint-changelog-yaml +++ b/scripts/lint-changelog-yaml @@ -1,17 +1,17 @@ #!/usr/bin/env ruby -require 'yaml' +require "yaml" -invalid_changelogs = Dir['changelogs/**/*'].reject do |changelog| +invalid_changelogs = Dir["changelogs/**/*"].reject { |changelog| next true if changelog =~ /((README|archive)\.md|unreleased(-ee)?)$/ - next false unless changelog.end_with?('.yml') + next false unless changelog.end_with?(".yml") begin YAML.load_file(changelog) rescue => exception puts exception end -end +} if invalid_changelogs.any? puts diff --git a/scripts/lint-rugged b/scripts/lint-rugged index 22e3e1f1505..6cdb055d0ff 100755 --- a/scripts/lint-rugged +++ b/scripts/lint-rugged @@ -2,19 +2,19 @@ ALLOWED = [ # Needed to handle repositories that are not in any storage - 'lib/gitlab/bare_repository_import/repository.rb', + "lib/gitlab/bare_repository_import/repository.rb", # Needed to avoid using the git binary to validate a branch name - 'lib/gitlab/git_ref_validator.rb' + "lib/gitlab/git_ref_validator.rb", ].freeze rugged_lines = IO.popen(%w[git grep -i -n rugged -- app config lib], &:read).lines rugged_lines = rugged_lines.select { |l| /^[^:]*\.rb:/ =~ l } rugged_lines = rugged_lines.reject { |l| l.start_with?(*ALLOWED) } -rugged_lines = rugged_lines.reject do |line| - code, _comment = line.split('# ', 2) +rugged_lines = rugged_lines.reject { |line| + code, _comment = line.split("# ", 2) code !~ /rugged/i -end +} exit if rugged_lines.empty? diff --git a/scripts/merge-reports b/scripts/merge-reports index 3a421f1f1fc..bf4fb269b9c 100755 --- a/scripts/merge-reports +++ b/scripts/merge-reports @@ -1,10 +1,10 @@ #!/usr/bin/env ruby -require 'json' +require "json" main_report_file = ARGV.shift unless main_report_file - puts 'usage: merge-reports <main-report> [extra reports...]' + puts "usage: merge-reports <main-report> [extra reports...]" exit 1 end @@ -16,9 +16,9 @@ ARGV.each do |report_file| report = JSON.parse(File.read(report_file)) # Remove existing values - updates = report.delete_if do |key, value| + updates = report.delete_if { |key, value| main_report[key] && main_report[key] == value - end + } new_report.merge!(updates) puts "Merged #{report_file} adding #{updates.size} results." diff --git a/scripts/merge-simplecov b/scripts/merge-simplecov index 65f93f8830b..31ac6abc35d 100755 --- a/scripts/merge-simplecov +++ b/scripts/merge-simplecov @@ -1,22 +1,20 @@ #!/usr/bin/env ruby -require_relative '../spec/simplecov_env' +require_relative "../spec/simplecov_env" SimpleCovEnv.configure_profile module SimpleCov module ResultMerger class << self def resultset_files - Dir.glob(File.join(SimpleCov.coverage_path, '*', '.resultset.json')) + Dir.glob(File.join(SimpleCov.coverage_path, "*", ".resultset.json")) end def resultset_hashes resultset_files.map do |path| - begin - JSON.parse(File.read(path)) - rescue - {} - end + JSON.parse(File.read(path)) + rescue + {} end end diff --git a/scripts/no-ee-check b/scripts/no-ee-check index 29d319dc822..7f3fef842d0 100755 --- a/scripts/no-ee-check +++ b/scripts/no-ee-check @@ -1,7 +1,7 @@ #!/usr/bin/env ruby -ee_path = File.join(File.expand_path(__dir__), '../ee') +ee_path = File.join(File.expand_path(__dir__), "../ee") if Dir.exist?(ee_path) - puts 'The repository contains /ee directory. There should be no /ee directory in CE repo.' + puts "The repository contains /ee directory. There should be no /ee directory in CE repo." exit 1 end diff --git a/scripts/prune-old-flaky-specs b/scripts/prune-old-flaky-specs index a00a334fd6e..97d49ffa5a2 100755 --- a/scripts/prune-old-flaky-specs +++ b/scripts/prune-old-flaky-specs @@ -3,17 +3,17 @@ # lib/rspec_flaky/flaky_examples_collection.rb is requiring # `active_support/hash_with_indifferent_access`, and we install the `activesupport` # gem manually on the CI -require 'rubygems' +require "rubygems" # In newer Ruby, alias_method is not private then we don't need __send__ singleton_class.__send__(:alias_method, :require_dependency, :require) # rubocop:disable GitlabSecurity/PublicSend -$:.unshift(File.expand_path('../lib', __dir__)) +$:.unshift(File.expand_path("../lib", __dir__)) -require 'rspec_flaky/report' +require "rspec_flaky/report" report_file = ARGV.shift unless report_file - puts 'usage: prune-old-flaky-specs <report-file> <new-report-file>' + puts "usage: prune-old-flaky-specs <report-file> <new-report-file>" exit 1 end diff --git a/scripts/review_apps/automated_cleanup.rb b/scripts/review_apps/automated_cleanup.rb index 4166070f7cd..bc0e76b9bc5 100755 --- a/scripts/review_apps/automated_cleanup.rb +++ b/scripts/review_apps/automated_cleanup.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'gitlab' -require_relative File.expand_path('../../lib/quality/helm_client.rb', __dir__) -require_relative File.expand_path('../../lib/quality/kubernetes_client.rb', __dir__) +require "gitlab" +require_relative File.expand_path("../../lib/quality/helm_client.rb", __dir__) +require_relative File.expand_path("../../lib/quality/kubernetes_client.rb", __dir__) class AutomatedCleanup attr_reader :project_path, :gitlab_token @@ -10,27 +10,27 @@ class AutomatedCleanup DEPLOYMENTS_PER_PAGE = 100 HELM_RELEASES_BATCH_SIZE = 5 IGNORED_HELM_ERRORS = [ - 'transport is closing', - 'error upgrading connection' + "transport is closing", + "error upgrading connection", ].freeze IGNORED_KUBERNETES_ERRORS = [ - 'NotFound' + "NotFound", ].freeze def self.ee? - ENV['CI_PROJECT_NAME'] == 'gitlab-ee' || File.exist?('CHANGELOG-EE.md') + ENV["CI_PROJECT_NAME"] == "gitlab-ee" || File.exist?("CHANGELOG-EE.md") end - def initialize(project_path: ENV['CI_PROJECT_PATH'], gitlab_token: ENV['GITLAB_BOT_REVIEW_APPS_CLEANUP_TOKEN']) + def initialize(project_path: ENV["CI_PROJECT_PATH"], gitlab_token: ENV["GITLAB_BOT_REVIEW_APPS_CLEANUP_TOKEN"]) @project_path = project_path @gitlab_token = gitlab_token - ENV['TILLER_NAMESPACE'] ||= review_apps_namespace + ENV["TILLER_NAMESPACE"] ||= review_apps_namespace end def gitlab @gitlab ||= begin Gitlab.configure do |config| - config.endpoint = 'https://gitlab.com/api/v4' + config.endpoint = "https://gitlab.com/api/v4" # gitlab-bot's token "GitLab review apps cleanup" config.private_token = gitlab_token end @@ -40,7 +40,7 @@ class AutomatedCleanup end def review_apps_namespace - self.class.ee? ? 'review-apps-ee' : 'review-apps-ce' + self.class.ee? ? "review-apps-ee" : "review-apps-ce" end def helm @@ -61,7 +61,7 @@ class AutomatedCleanup gitlab.deployments(project_path, per_page: DEPLOYMENTS_PER_PAGE).auto_paginate do |deployment| environment = deployment.environment - next unless environment.name.start_with?('review/') + next unless environment.name.start_with?("review/") next if checked_environments.include?(environment.slug) last_deploy = deployment.created_at @@ -74,7 +74,7 @@ class AutomatedCleanup elsif deployed_at < stop_threshold stop_environment(environment, deployment) else - print_release_state(subject: 'Review app', release_name: environment.slug, release_date: last_deploy, action: 'leaving') + print_release_state(subject: "Review app", release_name: environment.slug, release_date: last_deploy, action: "leaving") end checked_environments << environment.slug @@ -87,10 +87,10 @@ class AutomatedCleanup threshold_day = threshold_time(days: days) helm_releases.each do |release| - if release.status == 'FAILED' || release.last_update < threshold_day + if release.status == "FAILED" || release.last_update < threshold_day delete_helm_release(release) else - print_release_state(subject: 'Release', release_name: release.name, release_date: release.last_update, action: 'leaving') + print_release_state(subject: "Release", release_name: release.name, release_date: release.last_update, action: "leaving") end end end @@ -98,23 +98,23 @@ class AutomatedCleanup private def delete_environment(environment, deployment) - print_release_state(subject: 'Review app', release_name: environment.slug, release_date: deployment.created_at, action: 'deleting') + print_release_state(subject: "Review app", release_name: environment.slug, release_date: deployment.created_at, action: "deleting") gitlab.delete_environment(project_path, environment.id) end def stop_environment(environment, deployment) - print_release_state(subject: 'Review app', release_name: environment.slug, release_date: deployment.created_at, action: 'stopping') + print_release_state(subject: "Review app", release_name: environment.slug, release_date: deployment.created_at, action: "stopping") gitlab.stop_environment(project_path, environment.id) end def helm_releases - args = ['--all', '--date', "--max #{HELM_RELEASES_BATCH_SIZE}"] + args = ["--all", "--date", "--max #{HELM_RELEASES_BATCH_SIZE}"] helm.releases(args: args) end def delete_helm_release(release) - print_release_state(subject: 'Release', release_name: release.name, release_status: release.status, release_date: release.last_update, action: 'cleaning') + print_release_state(subject: "Release", release_name: release.name, release_status: release.status, release_date: release.last_update, action: "cleaning") helm.delete(release_name: release.name) kubernetes.cleanup(release_name: release.name) rescue Quality::HelmClient::CommandFailedError => ex @@ -148,13 +148,13 @@ end automated_cleanup = AutomatedCleanup.new -timed('Review apps cleanup') do +timed("Review apps cleanup") do automated_cleanup.perform_gitlab_environment_cleanup!(days_for_stop: 2, days_for_delete: 3) end puts -timed('Helm releases cleanup') do +timed("Helm releases cleanup") do automated_cleanup.perform_helm_releases_cleanup!(days: 3) end diff --git a/scripts/security-harness b/scripts/security-harness index 8369cf06223..51eaefe2003 100755 --- a/scripts/security-harness +++ b/scripts/security-harness @@ -1,9 +1,9 @@ #!/usr/bin/env ruby -require 'digest' -require 'fileutils' +require "digest" +require "fileutils" -harness_path = File.expand_path('../.git/security_harness', __dir__) +harness_path = File.expand_path("../.git/security_harness", __dir__) hook_path = File.expand_path("../.git/hooks/pre-push", __dir__) if File.exist?(hook_path) @@ -18,11 +18,11 @@ if File.exist?(hook_path) exit 1 end else - File.open(hook_path, 'w') do |file| + File.open(hook_path, "w") do |file| IO.copy_stream(DATA, file) end - File.chmod(0755, hook_path) + File.chmod(0o755, hook_path) end # Toggle the harness on or off diff --git a/scripts/static-analysis b/scripts/static-analysis index 642c50ec0a8..74bf635bffa 100755 --- a/scripts/static-analysis +++ b/scripts/static-analysis @@ -1,13 +1,13 @@ #!/usr/bin/env ruby # We don't have auto-loading here -require_relative '../lib/gitlab/popen' -require_relative '../lib/gitlab/popen/runner' +require_relative "../lib/gitlab/popen" +require_relative "../lib/gitlab/popen/runner" def emit_warnings(static_analysis) static_analysis.warned_results.each do |result| puts - puts "**** #{result.cmd.join(' ')} had the following warning(s):" + puts "**** #{result.cmd.join(" ")} had the following warning(s):" puts puts result.stderr puts @@ -17,7 +17,7 @@ end def emit_errors(static_analysis) static_analysis.failed_results.each do |result| puts - puts "**** #{result.cmd.join(' ')} failed with the following error(s):" + puts "**** #{result.cmd.join(" ")} failed with the following error(s):" puts puts result.stdout puts result.stderr @@ -33,14 +33,14 @@ tasks = [ %w[yarn run prettier-all], %w[bundle exec rubocop --parallel], %w[scripts/lint-conflicts.sh], - %w[scripts/lint-rugged] + %w[scripts/lint-rugged], ] static_analysis = Gitlab::Popen::Runner.new static_analysis.run(tasks) do |cmd, &run| puts - puts "$ #{cmd.join(' ')}" + puts "$ #{cmd.join(" ")}" result = run.call @@ -49,21 +49,21 @@ static_analysis.run(tasks) do |cmd, &run| end puts -puts '===================================================' +puts "===================================================" puts puts if static_analysis.all_success_and_clean? - puts 'All static analyses passed successfully.' + puts "All static analyses passed successfully." elsif static_analysis.all_success? - puts 'All static analyses passed successfully, but we have warnings:' + puts "All static analyses passed successfully, but we have warnings:" puts emit_warnings(static_analysis) exit 2 else - puts 'Some static analyses failed:' + puts "Some static analyses failed:" emit_warnings(static_analysis) emit_errors(static_analysis) diff --git a/scripts/sync-reports b/scripts/sync-reports index 5ed65e78005..ba7360d4d47 100755 --- a/scripts/sync-reports +++ b/scripts/sync-reports @@ -1,7 +1,7 @@ #!/usr/bin/env ruby -require 'rubygems' -require 'fog/aws' +require "rubygems" +require "fog/aws" class SyncReports ACTIONS = %w[get put].freeze @@ -18,9 +18,9 @@ class SyncReports def perform_sync! case options[:action] - when 'get' + when "get" get_reports! - when 'put' + when "put" put_reports! end end @@ -60,21 +60,21 @@ class SyncReports def storage @storage ||= Fog::Storage.new( - provider: 'AWS', - aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], - aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'] + provider: "AWS", + aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"], + aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"] ) end end -def usage!(error: 'action') +def usage!(error: "action") print "\n[ERROR]: " case error - when 'action' - puts "Please specify an action as first argument: #{SyncReports::ACTIONS.join(', ')}\n\n" - when 'bucket' + when "action" + puts "Please specify an action as first argument: #{SyncReports::ACTIONS.join(", ")}\n\n" + when "bucket" puts "Please specify a bucket as second argument!\n\n" - when 'files' + when "files" puts "Please specify one or more file paths as third argument!\n\n" end puts "Usage: #{__FILE__} [get|put] bucket report_path ...\n\n" @@ -85,11 +85,11 @@ end if $0 == __FILE__ action = ARGV.shift - usage!(error: 'action') unless SyncReports::ACTIONS.include?(action) + usage!(error: "action") unless SyncReports::ACTIONS.include?(action) bucket = ARGV.shift - usage!(error: 'bucket') unless bucket - usage!(error: 'files') unless ARGV.any? + usage!(error: "bucket") unless bucket + usage!(error: "files") unless ARGV.any? SyncReports.new(action: action, bucket: bucket, report_paths: ARGV) end diff --git a/scripts/trigger-build b/scripts/trigger-build index 9dbafffddfc..00b7c0caf39 100755 --- a/scripts/trigger-build +++ b/scripts/trigger-build @@ -1,18 +1,18 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'gitlab' +require "gitlab" # # Configure credentials to be used with gitlab gem # Gitlab.configure do |config| - config.endpoint = 'https://gitlab.com/api/v4' + config.endpoint = "https://gitlab.com/api/v4" end module Trigger def self.ee? - ENV['CI_PROJECT_NAME'] == 'gitlab-ee' || File.exist?('CHANGELOG-EE.md') + ENV["CI_PROJECT_NAME"] == "gitlab-ee" || File.exist?("CHANGELOG-EE.md") end class Base @@ -21,7 +21,8 @@ module Trigger downstream_project_path, trigger_token, ref, - variables) + variables + ) puts "Triggered downstream pipeline: #{pipeline.web_url}\n" puts "Waiting for downstream pipeline status" @@ -68,12 +69,12 @@ module Trigger def base_variables { - 'GITLAB_REF_SLUG' => ENV['CI_COMMIT_TAG'] ? ENV['CI_COMMIT_REF_NAME'] : ENV['CI_COMMIT_REF_SLUG'], - 'TRIGGERED_USER' => ENV['TRIGGERED_USER'] || ENV['GITLAB_USER_NAME'], - 'TRIGGER_SOURCE' => ENV['CI_JOB_URL'], - 'TOP_UPSTREAM_SOURCE_PROJECT' => ENV['CI_PROJECT_PATH'], - 'TOP_UPSTREAM_SOURCE_JOB' => ENV['CI_JOB_URL'], - 'TOP_UPSTREAM_SOURCE_SHA' => ENV['CI_COMMIT_SHA'] + "GITLAB_REF_SLUG" => ENV["CI_COMMIT_TAG"] ? ENV["CI_COMMIT_REF_NAME"] : ENV["CI_COMMIT_REF_SLUG"], + "TRIGGERED_USER" => ENV["TRIGGERED_USER"] || ENV["GITLAB_USER_NAME"], + "TRIGGER_SOURCE" => ENV["CI_JOB_URL"], + "TOP_UPSTREAM_SOURCE_PROJECT" => ENV["CI_PROJECT_PATH"], + "TOP_UPSTREAM_SOURCE_JOB" => ENV["CI_JOB_URL"], + "TOP_UPSTREAM_SOURCE_SHA" => ENV["CI_COMMIT_SHA"], } end @@ -89,27 +90,27 @@ module Trigger private def downstream_project_path - 'gitlab-org/omnibus-gitlab' + "gitlab-org/omnibus-gitlab" end def ref - ENV['OMNIBUS_BRANCH'] || 'master' + ENV["OMNIBUS_BRANCH"] || "master" end def trigger_token - ENV['BUILD_TRIGGER_TOKEN'] + ENV["BUILD_TRIGGER_TOKEN"] end def access_token - ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN'] + ENV["GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN"] end def extra_variables { - 'GITLAB_VERSION' => ENV['CI_COMMIT_SHA'], - 'ALTERNATIVE_SOURCES' => 'true', - 'ee' => Trigger.ee? ? 'true' : 'false', - 'QA_BRANCH' => ENV['QA_BRANCH'] || 'master' + "GITLAB_VERSION" => ENV["CI_COMMIT_SHA"], + "ALTERNATIVE_SOURCES" => "true", + "ee" => Trigger.ee? ? "true" : "false", + "QA_BRANCH" => ENV["QA_BRANCH"] || "master", } end end @@ -118,31 +119,31 @@ module Trigger private def downstream_project_path - ENV['CNG_PROJECT_PATH'] || 'gitlab-org/build/CNG-mirror' + ENV["CNG_PROJECT_PATH"] || "gitlab-org/build/CNG-mirror" end def ref - ENV['CNG_BRANCH'] || 'master' + ENV["CNG_BRANCH"] || "master" end def trigger_token - ENV['BUILD_TRIGGER_TOKEN'] + ENV["BUILD_TRIGGER_TOKEN"] end def access_token - ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN'] + ENV["GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN"] end def extra_variables - edition = Trigger.ee? ? 'EE' : 'CE' + edition = Trigger.ee? ? "EE" : "CE" { # Back-compatibility until https://gitlab.com/gitlab-org/build/CNG/merge_requests/189 is merged - "GITLAB_#{edition}_VERSION" => ENV['CI_COMMIT_REF_NAME'], - "GITLAB_VERSION" => ENV['CI_COMMIT_REF_NAME'], - "GITLAB_TAG" => ENV['CI_COMMIT_TAG'], - "GITLAB_ASSETS_TAG" => ENV['CI_COMMIT_REF_SLUG'], - "#{edition}_PIPELINE" => 'true' + "GITLAB_#{edition}_VERSION" => ENV["CI_COMMIT_REF_NAME"], + "GITLAB_VERSION" => ENV["CI_COMMIT_REF_NAME"], + "GITLAB_TAG" => ENV["CI_COMMIT_TAG"], + "GITLAB_ASSETS_TAG" => ENV["CI_COMMIT_REF_SLUG"], + "#{edition}_PIPELINE" => "true", } end @@ -150,7 +151,7 @@ module Trigger raw_version = super # if the version matches semver format, treat it as a tag and prepend `v` - if raw_version =~ Regexp.compile(/^\d+\.\d+\.\d+(-rc\d+)?(-ee)?$/) + if raw_version&.match?(Regexp.compile(/^\d+\.\d+\.\d+(-rc\d+)?(-ee)?$/)) "v#{raw_version}" else raw_version @@ -163,10 +164,10 @@ module Trigger Gitlab.private_token = access_token Gitlab.create_commit_comment( - ENV['CI_PROJECT_PATH'], - ENV['CI_COMMIT_SHA'], - "The [`#{ENV['CI_JOB_NAME']}`](#{ENV['CI_JOB_URL']}) job from pipeline #{ENV['CI_PIPELINE_URL']} triggered #{downstream_pipeline.web_url} downstream.") - + ENV["CI_PROJECT_PATH"], + ENV["CI_COMMIT_SHA"], + "The [`#{ENV["CI_JOB_NAME"]}`](#{ENV["CI_JOB_URL"]}) job from pipeline #{ENV["CI_PIPELINE_URL"]} triggered #{downstream_pipeline.web_url} downstream." + ) rescue Gitlab::Error::Error => error puts "Ignoring the following error: #{error}" end @@ -227,9 +228,9 @@ module Trigger end case ARGV[0] -when 'omnibus' +when "omnibus" Trigger::Omnibus.new.invoke!(post_comment: true).wait! -when 'cng' +when "cng" Trigger::CNG.new.invoke!.wait! else puts "Please provide a valid option: diff --git a/scripts/trigger-build-docs b/scripts/trigger-build-docs index dfc8ee6050a..aa496f552b5 100755 --- a/scripts/trigger-build-docs +++ b/scripts/trigger-build-docs @@ -1,19 +1,19 @@ #!/usr/bin/env ruby -require 'gitlab' +require "gitlab" # # Configure credentials to be used with gitlab gem # Gitlab.configure do |config| - config.endpoint = 'https://gitlab.com/api/v4' + config.endpoint = "https://gitlab.com/api/v4" config.private_token = ENV["DOCS_API_TOKEN"] # GitLab Docs bot access token with Developer access to gitlab-docs end # # The remote docs project # -GITLAB_DOCS_REPO = 'gitlab-com/gitlab-docs'.freeze +GITLAB_DOCS_REPO = "gitlab-com/gitlab-docs".freeze # # Truncate the remote docs branch name otherwise we hit the filesystem @@ -34,7 +34,7 @@ end # https://gitlab.com/gitlab-com/gitlab-docs/issues/154. # def create_remote_branch - Gitlab.create_branch(GITLAB_DOCS_REPO, docs_branch, 'master') + Gitlab.create_branch(GITLAB_DOCS_REPO, docs_branch, "master") puts "=> Remote branch '#{docs_branch}' created" pipelines = nil @@ -43,7 +43,7 @@ def create_remote_branch loop do sleep 1 puts "=> Waiting for pipeline to start..." - pipelines = Gitlab.pipelines(GITLAB_DOCS_REPO, { ref: docs_branch }) + pipelines = Gitlab.pipelines(GITLAB_DOCS_REPO, {ref: docs_branch}) break if pipelines.any? end @@ -69,14 +69,14 @@ end # def slug case ENV["CI_PROJECT_NAME"] - when 'gitlab-ce' - 'ce' - when 'gitlab-ee' - 'ee' - when 'gitlab-runner' - 'runner' - when 'omnibus-gitlab' - 'omnibus' + when "gitlab-ce" + "ce" + when "gitlab-ee" + "ee" + when "gitlab-runner" + "runner" + when "omnibus-gitlab" + "omnibus" end end @@ -95,7 +95,7 @@ def trigger_pipeline app_url = "http://#{docs_branch}.#{ENV["DOCS_REVIEW_APPS_DOMAIN"]}/#{slug}" # Create the cross project pipeline using CI_JOB_TOKEN - pipeline = Gitlab.run_trigger(GITLAB_DOCS_REPO, ENV["CI_JOB_TOKEN"], docs_branch, { param_name => ENV["CI_COMMIT_REF_NAME"] }) + pipeline = Gitlab.run_trigger(GITLAB_DOCS_REPO, ENV["CI_JOB_TOKEN"], docs_branch, {param_name => ENV["CI_COMMIT_REF_NAME"]}) puts "=> Follow the status of the triggered pipeline:" puts "" @@ -118,10 +118,10 @@ end # are no stale remote branches and the Review server doesn't fill. # case ARGV[0] -when 'deploy' +when "deploy" create_remote_branch trigger_pipeline -when 'cleanup' +when "cleanup" remove_remote_branch else puts "Please provide a valid option: |