diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
commit | 3b1af5cc7ed2666ff18b718ce5d30fa5a2756674 (patch) | |
tree | 3bc4a40e0ee51ec27eabf917c537033c0c5b14d4 /scripts | |
parent | 9bba14be3f2c211bf79e15769cd9b77bc73a13bc (diff) |
Add latest changes from gitlab-org/gitlab@16-1-stable-eev16.1.0-rc42
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/api/create_merge_request_note.rb | 22 | ||||
-rwxr-xr-x | scripts/build_gdk_image | 52 | ||||
-rwxr-xr-x | scripts/failed_tests.rb | 4 | ||||
-rwxr-xr-x | scripts/frontend/start_storybook.sh | 8 | ||||
-rwxr-xr-x | scripts/generate-e2e-pipeline | 3 | ||||
-rwxr-xr-x | scripts/generate-message-to-run-e2e-pipeline.rb | 106 | ||||
-rwxr-xr-x | scripts/lint-doc.sh | 180 | ||||
-rwxr-xr-x | scripts/lint-docs-metadata.sh | 10 | ||||
-rw-r--r-- | scripts/prepare_build.sh | 7 | ||||
-rwxr-xr-x | scripts/regenerate-schema | 10 | ||||
-rwxr-xr-x | scripts/remote_development/run-e2e-tests.sh | 36 | ||||
-rwxr-xr-x | scripts/remote_development/run-smoke-test-suite.sh | 71 | ||||
-rwxr-xr-x | scripts/review_apps/review-apps.sh | 4 | ||||
-rw-r--r-- | scripts/rspec_helpers.sh | 18 | ||||
-rwxr-xr-x | scripts/trigger-build.rb | 2 | ||||
-rw-r--r-- | scripts/utils.sh | 9 | ||||
-rwxr-xr-x | scripts/verify-tff-mapping | 32 |
17 files changed, 461 insertions, 113 deletions
diff --git a/scripts/api/create_merge_request_note.rb b/scripts/api/create_merge_request_note.rb new file mode 100644 index 00000000000..c73987c6961 --- /dev/null +++ b/scripts/api/create_merge_request_note.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require_relative 'base' + +class CreateMergeRequestNote < Base + def initialize(options) + super + @merge_request = options.fetch(:merge_request) + end + + def execute(content) + client.create_merge_request_comment( + project, + merge_request.iid, + content + ) + end + + private + + attr_reader :merge_request +end diff --git a/scripts/build_gdk_image b/scripts/build_gdk_image new file mode 100755 index 00000000000..292d315b5ec --- /dev/null +++ b/scripts/build_gdk_image @@ -0,0 +1,52 @@ +#!/bin/bash + +set -e + +source "$(dirname "$0")/utils.sh" + +REGISTRY="${CI_REGISTRY}/${CI_PROJECT_PATH}" +SHA_TAG="${CI_COMMIT_SHA}" +BRANCH_TAG="${CI_COMMIT_REF_SLUG}" +BASE_TAG=$([ "${BUILD_GDK_BASE}" == "true" ] && echo "${SHA_TAG}" || echo "master") + +if [[ -z "${GDK_SHA}" ]]; then + GDK_SHA=$(git ls-remote https://gitlab.com/gitlab-org/gitlab-development-kit.git main | cut -f 1) +fi + +if [[ -n "${CI}" ]]; then + OUTPUT_OPTION="--push" +else + OUTPUT_OPTION="--load" +fi + +function build_image() { + local image=$1 + local target=$2 + + echoinfo "Using GDK at SHA ${GDK_SHA}" + + docker buildx build \ + --cache-to="type=inline" \ + --cache-from="${image}:${BRANCH_TAG}" \ + --cache-from="${image}:master" \ + --file="qa/gdk/Dockerfile.gdk" \ + --target="${target}" \ + --platform=${ARCH:-amd64} \ + --tag="${image}:${SHA_TAG}" \ + --tag="${image}:${BRANCH_TAG}" \ + --build-arg="BASE_TAG=${BASE_TAG}" \ + --build-arg="GDK_SHA=${GDK_SHA:-main}" \ + ${OUTPUT_OPTION} \ + . +} + +# Rebuild base image when BUILD_GDK_BASE is set to true +if [[ "${BUILD_GDK_BASE}" == "true" ]]; then + echoinfo "Building GDK base image", "yes" + build_image "${REGISTRY}/gitlab-qa-gdk-base" "gdk-base" +fi + +echoinfo "Building GDK image", "yes" +build_image "${REGISTRY}/gitlab-qa-gdk" "gdk" + +echosuccess "Built image '${REGISTRY}/gitlab-qa-gdk:${SHA_TAG}'" diff --git a/scripts/failed_tests.rb b/scripts/failed_tests.rb index 0ba454894b7..f828155f6f0 100755 --- a/scripts/failed_tests.rb +++ b/scripts/failed_tests.rb @@ -12,8 +12,8 @@ class FailedTests previous_tests_report_path: 'test_results/previous/test_reports.json', output_directory: 'tmp/previous_failed_tests/', format: :oneline, - rspec_pg_regex: /rspec .+ pg13( .+)?/, - rspec_ee_pg_regex: /rspec-ee .+ pg13( .+)?/ + rspec_pg_regex: /rspec .+ pg14( .+)?/, + rspec_ee_pg_regex: /rspec-ee .+ pg14( .+)?/ }.freeze def initialize(options) diff --git a/scripts/frontend/start_storybook.sh b/scripts/frontend/start_storybook.sh index 7ae0a21b15b..622e35f5483 100755 --- a/scripts/frontend/start_storybook.sh +++ b/scripts/frontend/start_storybook.sh @@ -3,14 +3,6 @@ bold=$(tput bold) normal=$(tput sgr0) -echo -e "Storybook provides a mock server that allows creating stories for components that make HTTP requests." -echo -e "${bold}Storybook will fail to start if it can’t find the fixtures used by the mock server.${normal}\n" -read -rp "Would you like to generate/update the frontend fixtures used by the mock server (y/N)? " answer - -if [[ "$answer" =~ ^(Y|y)$ ]] ; then - bundle exec rake frontend:mock_server_fixtures -fi - if ! [[ -d storybook/node_modules ]] ; then yarn storybook:install fi diff --git a/scripts/generate-e2e-pipeline b/scripts/generate-e2e-pipeline index 3f30fb86ccc..2b882094dc2 100755 --- a/scripts/generate-e2e-pipeline +++ b/scripts/generate-e2e-pipeline @@ -40,7 +40,6 @@ variables: GIT_SUBMODULE_STRATEGY: "none" GITLAB_QA_CACHE_KEY: "$qa_cache_key" GITLAB_SEMVER_VERSION: "$(cat VERSION)" - SKIP_OMNIBUS_TRIGGER: "false" QA_EXPORT_TEST_METRICS: "${QA_EXPORT_TEST_METRICS:-true}" QA_FEATURE_FLAGS: "${QA_FEATURE_FLAGS}" QA_FRAMEWORK_CHANGES: "${QA_FRAMEWORK_CHANGES:-false}" @@ -49,6 +48,7 @@ variables: QA_SAVE_TEST_METRICS: "${QA_SAVE_TEST_METRICS:-false}" QA_SUITES: "$QA_SUITES" QA_TESTS: "$QA_TESTS" + KNAPSACK_TEST_FILE_PATTERN: "$KNAPSACK_TEST_FILE_PATTERN" YML ) @@ -63,3 +63,4 @@ for key in "${!qa_pipelines[@]}"; do done echoinfo "Successfully generated qa pipeline files" +echo "$variables" diff --git a/scripts/generate-message-to-run-e2e-pipeline.rb b/scripts/generate-message-to-run-e2e-pipeline.rb new file mode 100755 index 00000000000..af18578add6 --- /dev/null +++ b/scripts/generate-message-to-run-e2e-pipeline.rb @@ -0,0 +1,106 @@ +#!/usr/bin/env ruby + +# frozen_string_literal: true + +require 'gitlab' +require 'optparse' + +require_relative 'api/create_merge_request_note' +require_relative 'api/commit_merge_requests' + +class GenerateMessageToRunE2ePipeline + NOTE_PATTERN = /<!-- Run e2e warning begin -->[\s\S]+<!-- Run e2e warning end -->/ + + def initialize(options) + @options = options + @project = @options.fetch(:project) + + # If api_token is nil, it's set to '' to allow unauthenticated requests (for forks). + api_token = @options.fetch(:api_token, '') + + warn "No API token given." if api_token.empty? + + @client = ::Gitlab.client( + endpoint: options.fetch(:endpoint), + private_token: api_token + ) + end + + def execute + return unless qa_tests_folders? + + add_note_to_mr unless existing_note + end + + private + + attr_reader :project, :client, :options + + def qa_tests_folders? + return unless File.exist?(env('ENV_FILE')) + + qa_tests_line = File.open(env('ENV_FILE')).detect { |line| line.include?("QA_TESTS=") } + qa_tests_match = qa_tests_line&.match(/'([\s\S]+)'/) + + qa_tests_match && !qa_tests_match[1].include?('_spec.rb') # rubocop:disable Rails/NegateInclude + end + + def add_note_to_mr + CreateMergeRequestNote.new( + options.merge(merge_request: merge_request) + ).execute(content) + end + + def match?(body) + body.match?(NOTE_PATTERN) + end + + def existing_note + @note ||= client.merge_request_comments(project, merge_request.iid).auto_paginate.detect do |note| + match?(note.body) + end + end + + def merge_request + @merge_request ||= CommitMergeRequests.new( + options.merge(sha: ENV['CI_MERGE_REQUEST_SOURCE_BRANCH_SHA']) + ).execute.first + end + + def content + <<~MARKDOWN + <!-- Run e2e warning begin --> + :warning: @#{author_username} Some end-to-end (E2E) tests have been selected based on the stage label on this MR. + If not run already, please run the `e2e:package-and-test-ee` job in the `qa` stage + and review the results **before merging this MR**. (E2E tests are not run automatically on some MRs due to [runner resource constraints](https://gitlab.com/gitlab-org/gitlab-qa/-/issues/261).) + + If you would like to run all e2e tests, please apply the ~"pipeline:run-all-e2e" label and restart the pipeline. + + Once done, please apply the ✅ emoji on this comment. + + For any questions or help in reviewing the E2E test results, please reach out on the internal #quality Slack channel. + <!-- Run e2e warning end --> + MARKDOWN + end + + def author_username + merge_request&.author&.username + end + + def env(name) + return unless ENV[name] && !ENV[name].strip.empty? + + ENV[name] + end +end + +if $PROGRAM_NAME == __FILE__ + OptionParser.new do |opts| + opts.on("-h", "--help", "Prints this help") do + puts opts + exit + end + end.parse! + + GenerateMessageToRunE2ePipeline.new(API::DEFAULT_OPTIONS).execute +end diff --git a/scripts/lint-doc.sh b/scripts/lint-doc.sh index 18e7d7d1c1c..e6b63925fc6 100755 --- a/scripts/lint-doc.sh +++ b/scripts/lint-doc.sh @@ -1,67 +1,75 @@ #!/usr/bin/env bash set -o pipefail +COLOR_RED="\e[31m" +COLOR_GREEN="\e[32m" +COLOR_RESET="\e[39m" + cd "$(dirname "$0")/.." || exit 1 -echo "=> Linting documents at path $(pwd) as $(whoami)..." -echo +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Linting documents at path $(pwd) as $(whoami)...${COLOR_RESET}\n" ERRORCODE=0 # Use long options (e.g. --header instead of -H) for curl examples in documentation. -echo '=> Checking for cURL short options...' -echo -grep --extended-regexp --recursive --color=auto 'curl (.+ )?-[^- ].*' doc/ >/dev/null 2>&1 -if [ $? -eq 0 ] +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Checking for cURL short options...${COLOR_RESET}\n" +if grep --extended-regexp --recursive --color=auto 'curl (.+ )?-[^- ].*' doc/ >/dev/null 2>&1; then - echo '✖ ERROR: Short options for curl should not be used in documentation! - Use long options (e.g., --header instead of -H):' >&2 - grep --extended-regexp --recursive --color=auto 'curl (.+ )?-[^- ].*' doc/ + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: Short options for curl should not be used in documentation!${COLOR_RESET}" + printf " Use long options (for example, --header instead of -H):\n" >&2 + grep --extended-regexp --recursive --color=auto 'curl (.+ )?-[^- ].*' doc ((ERRORCODE++)) fi # Documentation pages need front matter for tracking purposes. -echo '=> Checking documentation for front matter...' -echo +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Checking documentation for front matter...${COLOR_RESET}\n" if ! scripts/lint-docs-metadata.sh then - echo '✖ ERROR: These documentation pages need front matter. See https://docs.gitlab.com/ee/development/documentation/index.html#stage-and-group-metadata for how to add it.' >&2 - echo + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: These documentation pages need front matter!${COLOR_RESET}" + printf " See https://docs.gitlab.com/ee/development/documentation/index.html#stage-and-group-metadata for how to add it.\n" >&2 ((ERRORCODE++)) fi # Test for non-standard spaces (NBSP, NNBSP, ZWSP) in documentation. -echo '=> Checking for non-standard spaces...' -echo -grep --extended-regexp --binary-file=without-match --recursive '[ ]' doc/ >/dev/null 2>&1 -if [ $? -eq 0 ] +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Checking for non-standard spaces...${COLOR_RESET}\n" +if grep --extended-regexp --binary-file=without-match --recursive '[ ]' doc/ >/dev/null 2>&1; then - echo '✖ ERROR: Non-standard spaces (NBSP, NNBSP, ZWSP) should not be used in documentation. - https://docs.gitlab.com/ee/development/documentation/styleguide/index.html#spaces-between-words - Replace with standard spaces:' >&2 + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: Non-standard spaces (NBSP, NNBSP, ZWSP) should not be used in documentation!${COLOR_RESET}" + printf " https://docs.gitlab.com/ee/development/documentation/styleguide/index.html#spaces-between-words\n" + printf "Replace with standard spaces:\n" >&2 # Find the spaces, then add color codes with sed to highlight each NBSP or NNBSP in the output. + # shellcheck disable=SC1018 grep --extended-regexp --binary-file=without-match --recursive --color=auto '[ ]' doc \ - | sed -e ''/ /s//`printf "\033[0;101m \033[0m"`/'' -e ''/ /s//`printf "\033[0;101m \033[0m"`/'' + | sed -e ''/ /s//"$(printf "\033[0;101m \033[0m")"/'' -e ''/ /s//"$(printf "\033[0;101m \033[0m")"/'' ((ERRORCODE++)) fi # Ensure that the CHANGELOG.md does not contain duplicate versions DUPLICATE_CHANGELOG_VERSIONS=$(grep --extended-regexp '^## .+' CHANGELOG.md | sed -E 's| \(.+\)||' | sort -r | uniq -d) -echo '=> Checking for CHANGELOG.md duplicate entries...' -echo +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Checking for CHANGELOG.md duplicate entries...${COLOR_RESET}\n" if [ "${DUPLICATE_CHANGELOG_VERSIONS}" != "" ] then - echo '✖ ERROR: Duplicate versions in CHANGELOG.md:' >&2 + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: Duplicate versions in CHANGELOG.md:${COLOR_RESET}\n" >&2 echo "${DUPLICATE_CHANGELOG_VERSIONS}" >&2 ((ERRORCODE++)) fi # Make sure no files in doc/ are executable EXEC_PERM_COUNT=$(find doc/ -type f -perm 755 | wc -l) -echo "=> Checking $(pwd)/doc for executable permissions..." -echo +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Checking $(pwd)/doc for executable permissions...${COLOR_RESET}\n" if [ "${EXEC_PERM_COUNT}" -ne 0 ] then - echo '✖ ERROR: Executable permissions should not be used in documentation! Use `chmod 644` to the files in question:' >&2 - find doc/ -type f -perm 755 + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: Executable permissions should not be used in documentation!${COLOR_RESET} Use 'chmod 644' on these files:\n" >&2 + find doc -type f -perm 755 ((ERRORCODE++)) fi @@ -69,15 +77,14 @@ fi # Number of 'README.md's as of 2021-08-17 NUMBER_READMES=0 FIND_READMES=$(find doc/ -name "README.md" | wc -l) -echo '=> Checking for new README.md files...' -echo -if [ ${FIND_READMES} -ne $NUMBER_READMES ] +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Checking for new README.md files...${COLOR_RESET}\n" +if [ "${FIND_READMES}" -ne $NUMBER_READMES ] then - echo - echo ' ✖ ERROR: The number of README.md file(s) has changed. Use index.md instead of README.md.' >&2 - echo ' ✖ If removing a README.md file, update NUMBER_READMES in lint-doc.sh.' >&2 - echo ' https://docs.gitlab.com/ee/development/documentation/styleguide/index.html#work-with-directories-and-files' - echo + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: The number of README.md files has changed!${COLOR_RESET} Use index.md instead of README.md.\n" >&2 + printf "If removing a README.md file, update NUMBER_READMES in lint-doc.sh.\n" >&2 + printf "https://docs.gitlab.com/ee/development/documentation/site_architecture/folder_structure.html#work-with-directories-and-files\n" ((ERRORCODE++)) fi @@ -85,15 +92,40 @@ fi # Number of directories with dashes as of 2021-09-17 NUMBER_DASHES=2 FIND_DASHES=$(find doc -type d -name "*-*" | wc -l) -echo '=> Checking for directory names containing dashes...' -echo -if [ ${FIND_DASHES} -ne $NUMBER_DASHES ] +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Checking for directory names containing dashes...${COLOR_RESET}\n" +if [ "${FIND_DASHES}" -ne $NUMBER_DASHES ] +then + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: The number of directory names containing dashes has changed!${COLOR_RESET} Use underscores instead of dashes for the directory names.\n" >&2 + printf "If removing a directory containing dashes, update NUMBER_DASHES in lint-doc.sh.\n" >&2 + printf "https://docs.gitlab.com/ee/development/documentation/site_architecture/folder_structure.html#work-with-directories-and-files\n" + ((ERRORCODE++)) +fi + +# Do not use uppercase letters in directory and file names, use all lowercase instead. +# (find always returns 0, so we use the grep hack https://serverfault.com/a/225827) +FIND_UPPERCASE_DIRS=$(find doc -type d -name "*[[:upper:]]*") +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Checking for directory names containing an uppercase letter...${COLOR_RESET}\n" +if echo "${FIND_UPPERCASE_DIRS}" | grep . &>/dev/null +then + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: Found one or more directories with an uppercase letter in their name!${COLOR_RESET} Use lowercase instead of uppercase for the directory names.\n" >&2 + printf "https://docs.gitlab.com/ee/development/documentation/site_architecture/folder_structure.html#work-with-directories-and-files\n" >&2 + echo "${FIND_UPPERCASE_DIRS}" + ((ERRORCODE++)) +fi + +FIND_UPPERCASE_FILES=$(find doc -type f -name "*[[:upper:]]*.md") +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Checking for file names containing an uppercase letter...${COLOR_RESET}\n" +if echo "${FIND_UPPERCASE_FILES}" | grep . &>/dev/null then - echo - echo ' ✖ ERROR: The number of directory names containing dashes has changed. Use underscores instead of dashes for the directory names.' >&2 - echo ' ✖ If removing a directory containing dashes, update NUMBER_DASHES in lint-doc.sh.' >&2 - echo ' https://docs.gitlab.com/ee/development/documentation/styleguide/index.html#work-with-directories-and-files' - echo + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: Found one or more file names with an uppercase letter in their name!${COLOR_RESET} Use lowercase instead of uppercase for the file names.\n" >&2 + printf "https://docs.gitlab.com/ee/development/documentation/site_architecture/folder_structure.html#work-with-directories-and-files\n" >&2 + echo "${FIND_UPPERCASE_FILES}" ((ERRORCODE++)) fi @@ -103,18 +135,21 @@ fi if [ -z "${CI_MERGE_REQUEST_TARGET_BRANCH_SHA}" ] then MD_DOC_PATH=${MD_DOC_PATH:-doc} - echo "Merge request pipeline (detached) detected. Testing all files." + # shellcheck disable=2059 + printf "${COLOR_GREEN}INFO: Merge request pipeline (detached) detected. Running Markdownlint and Vale on all files...${COLOR_RESET}\n" else - MERGE_BASE=$(git merge-base ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA} ${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA}) + MERGE_BASE=$(git merge-base "${CI_MERGE_REQUEST_TARGET_BRANCH_SHA}" "${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA}") if git diff --diff-filter=d --name-only "${MERGE_BASE}..${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA}" | grep -E "\.vale|\.markdownlint|lint-doc\.sh|docs\.gitlab-ci\.yml" then MD_DOC_PATH=${MD_DOC_PATH:-doc} - echo "Vale, Markdownlint, lint-doc.sh, or pipeline configuration changed. Testing all files." + # shellcheck disable=2059 + printf "${COLOR_GREEN}INFO: Vale, Markdownlint, lint-doc.sh, or pipeline configuration changed. Testing all files.${COLOR_RESET}\n" else MD_DOC_PATH=$(git diff --diff-filter=d --name-only "${MERGE_BASE}..${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA}" -- 'doc/*.md') if [ -n "${MD_DOC_PATH}" ] then - echo -e "Merged results pipeline detected. Testing only the following files:\n${MD_DOC_PATH}" + # shellcheck disable=2059 + printf "${COLOR_GREEN}INFO: Merged results pipeline detected. Testing only the following files:${COLOR_RESET}\n${MD_DOC_PATH}" fi fi fi @@ -124,58 +159,63 @@ function run_locally_or_in_container() { local args=$2 local registry_url="registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.16-vale-2.22.0-markdownlint-0.32.2-markdownlint2-0.6.0" - if hash ${cmd} 2>/dev/null + if hash "${cmd}" 2>/dev/null then + # shellcheck disable=2059 + printf "${COLOR_GREEN}INFO: Found locally-installed ${cmd}! Running...${COLOR_RESET}\n" $cmd $args # When using software like Rancher Desktop, both nerdctl and docker binaries are available # but only one is configured. To check which one to use, we need to probe each runtime - elif (hash nerdctl 2>/dev/null) && (nerdctl info 2>&1 1>/dev/null) + elif (hash nerdctl 2>/dev/null) && (nerdctl info > /dev/null 2>&1) then + # shellcheck disable=2059 + printf "${COLOR_GREEN}INFO: Found nerdctl! Using linting image to run ${cmd}...${COLOR_RESET}\n" nerdctl run -t -v "${PWD}:/gitlab" -w /gitlab --rm ${registry_url} ${cmd} ${args} - elif (hash docker 2>/dev/null) && (docker info 2>&1 1>/dev/null) + elif (hash docker 2>/dev/null) && (docker info > /dev/null 2>&1) then + # shellcheck disable=2059 + printf "${COLOR_GREEN}INFO: Found docker! Using linting image to run ${cmd}...${COLOR_RESET}\n" docker run -t -v "${PWD}:/gitlab" -w /gitlab --rm ${registry_url} ${cmd} ${args} else - echo - echo " ✖ ERROR: '${cmd}' not found. Install '${cmd}' or a container runtime (Docker/Nerdctl) to proceed." >&2 - echo + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: '${cmd}' not found!${COLOR_RESET} Install '${cmd}' locally, or install a container runtime (docker or nerdctl) and try again.\n" >&2 ((ERRORCODE++)) fi if [ $? -ne 0 ] then - echo - echo " ✖ ERROR: '${cmd}' failed with errors." >&2 - echo + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: '${cmd}' failed with errors!${COLOR_RESET}\n" >&2 ((ERRORCODE++)) fi } -echo '=> Linting markdown style...' -echo +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Linting markdown style...${COLOR_RESET}\n" if [ -z "${MD_DOC_PATH}" ] then - echo "Merged results pipeline detected, but no markdown files found. Skipping." + # shellcheck disable=2059 + printf "${COLOR_GREEN}INFO: Merged results pipeline detected, but no markdown files found. Skipping.${COLOR_RESET}\n" else - yarn markdownlint --config .markdownlint.yml ${MD_DOC_PATH} --rules doc/.markdownlint/rules - - if [ $? -ne 0 ] + if ! yarn markdownlint --rules doc/.markdownlint/rules ${MD_DOC_PATH}; then - echo - echo '✖ ERROR: Markdownlint failed with errors.' >&2 - echo + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: Markdownlint failed with errors!${COLOR_RESET}\n" >&2 ((ERRORCODE++)) fi fi -echo '=> Linting prose...' +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Looking for Vale to lint prose, either installed locally or available in documentation linting image...${COLOR_RESET}\n" run_locally_or_in_container 'vale' "--minAlertLevel error --output=doc/.vale/vale.tmpl ${MD_DOC_PATH}" -if [ $ERRORCODE -ne 0 ] +if [ "$ERRORCODE" -ne 0 ] then - echo "✖ ${ERRORCODE} lint test(s) failed. Review the log carefully to see full listing." + # shellcheck disable=2059 + printf "\n${COLOR_RED}ERROR: lint test(s) failed! Review the log carefully to see full listing.${COLOR_RESET}\n" exit 1 else - echo "✔ Linting passed" + # shellcheck disable=2059 + printf "\n${COLOR_GREEN}INFO: Linting passed.${COLOR_RESET}\n" exit 0 fi diff --git a/scripts/lint-docs-metadata.sh b/scripts/lint-docs-metadata.sh index 4212adfd3f1..cbf571729f3 100755 --- a/scripts/lint-docs-metadata.sh +++ b/scripts/lint-docs-metadata.sh @@ -38,10 +38,10 @@ function check_file { file="$1" TOTAL_FILES=$((TOTAL_FILES + 1)) if [ "$(head -n1 "$file")" != "---" ]; then - printf "${COLOR_RED}Documentation metadata missing in %s.${COLOR_RESET}\n" "$file" >&2 + printf "${COLOR_RED}ERROR: Documentation metadata missing in %s.${COLOR_RESET}\n" "$file" >&2 FAILING_FILES=$((FAILING_FILES + 1)) elif [ "$VERBOSE" == "true" ]; then - printf "Documentation metadata found in %s.\n" "$file" + printf "${COLOR_GREEN}INFO: Documentation metadata found in %s.${COLOR_RESET}\n" "$file" fi } @@ -53,7 +53,7 @@ function check_all_files { if [[ "$CHECK_ALL" = "true" ]]; then # shellcheck disable=SC2059 - printf "No files supplied. Checking all markdown files in doc/.\n" + printf "${COLOR_GREEN}INFO: No files supplied! Checking all markdown files in doc/...${COLOR_RESET}\n" check_all_files else # Takes a list of Markdown files as a parameter @@ -66,10 +66,10 @@ fi if [ "$FAILING_FILES" -gt 0 ]; then # shellcheck disable=SC2059 - printf "\n${COLOR_RED}Documentation metadata is missing in ${FAILING_FILES} of ${TOTAL_FILES} documentation files.${COLOR_RESET} For more information, see https://docs.gitlab.com/ee/development/documentation/#metadata.\n" >&2 + printf "\n${COLOR_RED}ERROR: Documentation metadata is missing in ${FAILING_FILES} of ${TOTAL_FILES} documentation files.${COLOR_RESET} For more information, see https://docs.gitlab.com/ee/development/documentation/#metadata.\n" >&2 exit 1 else # shellcheck disable=SC2059 - printf "${COLOR_GREEN}Documentation metadata found in ${TOTAL_FILES} documentation files.${COLOR_RESET}\n" + printf "${COLOR_GREEN}INFO: Documentation metadata found in ${TOTAL_FILES} documentation files.${COLOR_RESET}\n" exit 0 fi diff --git a/scripts/prepare_build.sh b/scripts/prepare_build.sh index 53674e9cb90..536da48f07f 100644 --- a/scripts/prepare_build.sh +++ b/scripts/prepare_build.sh @@ -53,6 +53,13 @@ sed -i 's|url:.*$|url: redis://redis:6379|g' config/cable.yml cp config/resque.yml.example config/resque.yml sed -i 's|url:.*$|url: redis://redis:6379|g' config/resque.yml +# By default, run CI against Redis Cluster to ensure Redis Cluster compatibility. +# if SETUP_DB is false, the jobs are not backend-related +if [[ "$USE_REDIS_CLUSTER" != "false" ]] && [[ "$SETUP_DB" != "false" ]]; then + cp config/redis.yml.example config/redis.yml + sed -i 's|- .*$|- redis://rediscluster:7001|g' config/redis.yml +fi + if [ "$SETUP_DB" != "false" ]; then setup_db elif getent hosts postgres; then diff --git a/scripts/regenerate-schema b/scripts/regenerate-schema index 06230942dcd..67c58339c6c 100755 --- a/scripts/regenerate-schema +++ b/scripts/regenerate-schema @@ -52,7 +52,7 @@ class SchemaRegenerator def checkout_ref return unless ci? - run %Q[git checkout #{source_ref}] + run %[git checkout #{source_ref}] run %q[git clean -f -- db] end @@ -71,8 +71,8 @@ class SchemaRegenerator return false unless project_url return false unless target_project_url - run %Q[git remote add target_project #{target_project_url}.git] - run %Q[git fetch target_project #{target_branch}:#{target_branch}] + run %[git remote add target_project #{target_project_url}.git] + run %[git fetch target_project #{target_branch}:#{target_branch}] local_checkout_clean_schema end @@ -83,8 +83,8 @@ class SchemaRegenerator # Ask git to checkout the schema from the target branch and reset # the file to unstage the changes. def local_checkout_clean_schema - run %Q[git checkout #{merge_base} -- #{FILENAME}] - run %Q[git reset -- #{FILENAME}] + run %[git checkout #{merge_base} -- #{FILENAME}] + run %[git reset -- #{FILENAME}] end ## diff --git a/scripts/remote_development/run-e2e-tests.sh b/scripts/remote_development/run-e2e-tests.sh new file mode 100755 index 00000000000..905bef4754d --- /dev/null +++ b/scripts/remote_development/run-e2e-tests.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh + +# frozen_string_literal: true + +# This is a convenience script to run the Remote Development category E2E spec(s) against a local +# GDK environment. It sets default values for the necessary environment variables, but allows +# them to be overridden. +# +# For details on how to run this, see the documentation comments at the top of +# qa/qa/specs/features/ee/browser_ui/3_create/remote_development/create_new_workspace_and_terminate_spec.rb + +DEFAULT_PASSWORD='5iveL!fe' + +export WEBDRIVER_HEADLESS="${WEBDRIVER_HEADLESS:-0}" +export QA_SUPER_SIDEBAR_ENABLED="${QA_SUPER_SIDEBAR_ENABLED:-1}" # This is currently necessary for the test to pass +export GITLAB_USERNAME="${GITLAB_USERNAME:-root}" +export GITLAB_PASSWORD="${GITLAB_PASSWORD:-${DEFAULT_PASSWORD}}" +export DEVFILE_PROJECT="${DEVFILE_PROJECT:-Gitlab Org / Gitlab Shell}" +export AGENT_NAME="${AGENT_NAME:-remotedev}" +export TEST_INSTANCE_URL="${TEST_INSTANCE_URL:-http://gdk.test:3000}" + +echo "WEBDRIVER_HEADLESS: ${WEBDRIVER_HEADLESS}" +echo "QA_SUPER_SIDEBAR_ENABLED: ${QA_SUPER_SIDEBAR_ENABLED}" +echo "GITLAB_USERNAME: ${GITLAB_USERNAME}" +echo "DEVFILE_PROJECT: ${AGENT_NAME}" +echo "AGENT_NAME: ${AGENT_NAME}" +echo "TEST_INSTANCE_URL: ${TEST_INSTANCE_URL}" + +working_directory="$(git rev-parse --show-toplevel)/qa" + +# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/397005 +# Remove the '--tag quarantine' from below once this test is removed from quarantine +(cd "$working_directory" && \ + bundle && \ + bundle exec bin/qa Test::Instance::All "$TEST_INSTANCE_URL" -- \ + --tag quarantine qa/specs/features/ee/browser_ui/3_create/remote_development) diff --git a/scripts/remote_development/run-smoke-test-suite.sh b/scripts/remote_development/run-smoke-test-suite.sh new file mode 100755 index 00000000000..5c1c5532a05 --- /dev/null +++ b/scripts/remote_development/run-smoke-test-suite.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +# This script runs a suite of non-E2E specs related to the Remote Development category, as +# a pre-commit/pre-push "Smoke Test" to catch any broken tests without having to wait +# on CI to catch them. Note that there are some shared/common specs related to +# Remote Development which are not included in this suite. +# https://en.wikipedia.org/wiki/Smoke_testing_(software) + +# shellcheck disable=SC2059 + +set -o errexit # AKA -e - exit immediately on errors (http://mywiki.wooledge.org/BashFAQ/105) + +# https://stackoverflow.com/a/28938235 +BCyan='\033[1;36m' # Bold Cyan +BRed='\033[1;31m' # Bold Red +BGreen='\033[1;32m' # Bold Green +BBlue='\033[1;34m' # Bold Blue +Color_Off='\033[0m' # Text Reset + +function onexit_err() { + local exit_status=${1:-$?} + printf "\n❌❌❌ ${BRed}Remote Development specs failed!${Color_Off} ❌❌❌\n" + exit "${exit_status}" +} +trap onexit_err ERR +set -o errexit + +printf "${BCyan}" +printf "\nStarting Remote Development specs.\n\n" +printf "${Color_Off}" + +printf "${BBlue}Running Remote Development backend specs${Color_Off}\n\n" + +# NOTE: For some reason this test started causing the following spec file in the list to blow up with +# "Failed to write to log, write log/workhorse-test.log: file already closed". Just removing +# it for now. +# ee/spec/graphql/api/workspace_spec.rb + +bin/spring rspec -r spec_helper \ +ee/spec/features/remote_development/workspaces_spec.rb \ +ee/spec/finders/remote_development/workspaces_finder_spec.rb \ +ee/spec/graphql/types/query_type_spec.rb \ +ee/spec/graphql/types/remote_development/workspace_type_spec.rb \ +ee/spec/graphql/types/subscription_type_spec.rb \ +ee/spec/lib/remote_development/workspaces/create/create_processor_spec.rb \ +ee/spec/lib/remote_development/workspaces/create/devfile_processor_spec.rb \ +ee/spec/lib/remote_development/workspaces/create/devfile_validator_spec.rb \ +ee/spec/lib/remote_development/workspaces/reconcile/actual_state_calculator_spec.rb \ +ee/spec/lib/remote_development/workspaces/reconcile/agent_info_parser_spec.rb \ +ee/spec/lib/remote_development/workspaces/reconcile/agent_info_spec.rb \ +ee/spec/lib/remote_development/workspaces/reconcile/desired_config_generator_spec.rb \ +ee/spec/lib/remote_development/workspaces/reconcile/params_parser_spec.rb \ +ee/spec/lib/remote_development/workspaces/reconcile/reconcile_processor_scenarios_spec.rb \ +ee/spec/lib/remote_development/workspaces/reconcile/reconcile_processor_spec.rb \ +ee/spec/lib/remote_development/workspaces/states_spec.rb \ +ee/spec/lib/remote_development/workspaces/update/update_processor_spec.rb \ +ee/spec/models/remote_development/remote_development_agent_config_spec.rb \ +ee/spec/models/remote_development/workspace_spec.rb \ +ee/spec/requests/api/graphql/mutations/remote_development/workspaces/create_spec.rb \ +ee/spec/requests/api/graphql/mutations/remote_development/workspaces/update_spec.rb \ +ee/spec/requests/api/graphql/remote_development/current_user_workspaces_spec.rb \ +ee/spec/requests/api/graphql/remote_development/workspaces_by_ids_spec.rb \ +ee/spec/requests/api/graphql/remote_development/workspace_by_id_spec.rb \ +ee/spec/requests/api/internal/kubernetes_spec.rb \ +ee/spec/services/remote_development/agent_config/update_service_spec.rb \ +ee/spec/services/remote_development/workspaces/create_service_spec.rb \ +ee/spec/services/remote_development/workspaces/reconcile_service_spec.rb \ +ee/spec/services/remote_development/workspaces/update_service_spec.rb \ +spec/graphql/types/subscription_type_spec.rb \ + +printf "\n✅✅✅ ${BGreen}All Remote Development specs passed successfully!${Color_Off} ✅✅✅\n" diff --git a/scripts/review_apps/review-apps.sh b/scripts/review_apps/review-apps.sh index 6ebb0f61a04..660257b042a 100755 --- a/scripts/review_apps/review-apps.sh +++ b/scripts/review_apps/review-apps.sh @@ -133,8 +133,8 @@ function disable_sign_ups() { # We use this weird syntax because we need to pass a one-liner ruby command to a Kubernetes container via kubectl. read -r -d '' multiline_ruby_code <<RUBY user = User.find_by_username('root'); -puts 'Error: Could not find root user. Check that the database was properly seeded'; exit(1) unless user; -token = user.personal_access_tokens.create(scopes: [:api], name: 'Token to disable sign-ups'); +(puts 'Error: Could not find root user. Check that the database was properly seeded'; exit(1)) unless user; +token = user.personal_access_tokens.create(scopes: [:api], name: 'Token to disable sign-ups', expires_at: 30.days.from_now); token.set_token('${REVIEW_APPS_ROOT_TOKEN}'); begin; token.save!; diff --git a/scripts/rspec_helpers.sh b/scripts/rspec_helpers.sh index 4e73bf48021..8be98cb6346 100644 --- a/scripts/rspec_helpers.sh +++ b/scripts/rspec_helpers.sh @@ -97,15 +97,16 @@ function retrieve_failed_tests() { function rspec_args() { local rspec_opts="${1}" - local junit_report_file="${2:-${JUNIT_RESULT_FILE}}" + local json_report_file="${2:-rspec/rspec-${CI_JOB_ID}.json}" + local junit_report_file="${3:-rspec/rspec-${CI_JOB_ID}.xml}" - echo "-Ispec -rspec_helper --color --failure-exit-code 1 --error-exit-code 2 --format documentation --format RspecJunitFormatter --out ${junit_report_file} ${rspec_opts}" + echo "-Ispec -rspec_helper --color --failure-exit-code 1 --error-exit-code 2 --format documentation --format Support::Formatters::JsonFormatter --out ${json_report_file} --format RspecJunitFormatter --out ${junit_report_file} ${rspec_opts}" } function rspec_simple_job() { export NO_KNAPSACK="1" - local rspec_cmd="bin/rspec $(rspec_args "${1}" "${2}")" + local rspec_cmd="bin/rspec $(rspec_args "${1}" "${2}" "${3}")" echoinfo "Running RSpec command: ${rspec_cmd}" eval "${rspec_cmd}" @@ -114,7 +115,7 @@ function rspec_simple_job() { function rspec_simple_job_with_retry () { local rspec_run_status=0 - rspec_simple_job "${1}" "${2}" || rspec_run_status=$? + rspec_simple_job "${1}" "${2}" "${3}" || rspec_run_status=$? handle_retry_rspec_in_new_process $rspec_run_status } @@ -265,13 +266,16 @@ function retry_failed_rspec_examples() { local default_knapsack_pattern="{,ee/,jh/}spec/{,**/}*_spec.rb" local knapsack_test_file_pattern="${KNAPSACK_TEST_FILE_PATTERN:-$default_knapsack_pattern}" + local json_retry_file="rspec/rspec-retry-${CI_JOB_ID}.json" + local junit_retry_file="rspec/rspec-retry-${CI_JOB_ID}.xml" # Retry only the tests that failed on first try - rspec_simple_job "--only-failures --pattern \"${knapsack_test_file_pattern}\"" "${JUNIT_RETRY_FILE}" + rspec_simple_job "--only-failures --pattern \"${knapsack_test_file_pattern}\"" "${json_retry_file}" "${junit_retry_file}" rspec_run_status=$? - # Merge the JUnit report from retry into the first-try report - junit_merge "${JUNIT_RETRY_FILE}" "${JUNIT_RESULT_FILE}" --update-only + # Merge the reports from retry into the first-try report + scripts/merge-reports "rspec/rspec-${CI_JOB_ID}.json" "${json_retry_file}" + junit_merge "${junit_retry_file}" "rspec/rspec-${CI_JOB_ID}.xml" --update-only if [[ $rspec_run_status -eq 0 ]]; then # The test is flaky because it succeeded after being retried. diff --git a/scripts/trigger-build.rb b/scripts/trigger-build.rb index c7c09557ff9..89a2bf034cc 100755 --- a/scripts/trigger-build.rb +++ b/scripts/trigger-build.rb @@ -19,7 +19,7 @@ module Trigger def self.variables_for_env_file(variables) variables.map do |key, value| - %Q(#{key}=#{value}) + %(#{key}=#{value}) end.join("\n") end diff --git a/scripts/utils.sh b/scripts/utils.sh index b41bc18deff..edfcf0f2dac 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -114,6 +114,8 @@ function yarn_install_script() { retry yarn install --frozen-lockfile + retry yarn storybook:install --frozen-lockfile + section_end "yarn-install" } @@ -290,13 +292,6 @@ function fail_pipeline_early() { fi } -function danger_as_local() { - # Force danger to skip CI source GitLab and fallback to "local only git repo". - unset GITLAB_CI - # We need to base SHA to help danger determine the base commit for this shallow clone. - bundle exec danger dry_run --fail-on-errors=true --verbose --base="${CI_MERGE_REQUEST_DIFF_BASE_SHA}" --head="${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA:-$CI_COMMIT_SHA}" --dangerfile="${DANGER_DANGERFILE:-Dangerfile}" -} - # We're inlining this function in `.gitlab/ci/package-and-test/main.gitlab-ci.yml` so make sure to reflect any changes there function assets_image_tag() { local cache_assets_hash_file="cached-assets-hash.txt" diff --git a/scripts/verify-tff-mapping b/scripts/verify-tff-mapping index 86ab7548b19..0bf4db52698 100755 --- a/scripts/verify-tff-mapping +++ b/scripts/verify-tff-mapping @@ -43,8 +43,13 @@ tests = [ { explanation: 'https://gitlab.com/gitlab-org/gitlab/-/issues/368628', - source: 'lib/gitlab/usage_data_counters/foo.rb', - expected: ['spec/lib/gitlab/usage_data_spec.rb'] + source: 'lib/gitlab/usage_data_counters/wiki_page_counter.rb', + expected: ['spec/lib/gitlab/usage_data_spec.rb', 'spec/lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb'] + }, + { + explanation: 'EE usage counters map to usage data spec', + source: 'ee/lib/gitlab/usage_data_counters/licenses_list.rb', + expected: ['ee/spec/lib/gitlab/usage_data_counters/licenses_list_spec.rb', 'spec/lib/gitlab/usage_data_spec.rb'] }, { @@ -85,8 +90,8 @@ tests = [ { explanation: 'Migration should map to its non-timestamped spec', - source: 'db/migrate/20221014034338_populate_releases_access_level_from_repository.rb', - expected: ['spec/migrations/populate_releases_access_level_from_repository_spec.rb'] + source: 'db/migrate/20221011062254_sync_new_amount_used_for_ci_project_monthly_usages.rb', + expected: ['spec/migrations/sync_new_amount_used_for_ci_project_monthly_usages_spec.rb'] }, # rubocop:disable Layout/LineLength { @@ -220,6 +225,17 @@ tests = [ explanation: 'https://gitlab.com/gitlab-org/quality/engineering-productivity/master-broken-incidents/-/issues/1683#note_1385966977', source: 'app/finders/members_finder.rb', expected: ['spec/finders/members_finder_spec.rb', 'spec/graphql/types/project_member_relation_enum_spec.rb'] + }, + + { + explanation: 'Map FOSS rake tasks', + source: 'lib/tasks/import.rake', + expected: ['spec/tasks/import_rake_spec.rb'] + }, + { + explanation: 'Map EE rake tasks', + source: 'ee/lib/tasks/geo.rake', + expected: ['ee/spec/tasks/geo_rake_spec.rb'] } ] @@ -241,7 +257,12 @@ class MappingTest end def failure_message - "#{explanation}: #{source}: Expected #{expected_set.to_a}, got #{actual_set.to_a}." + <<~MESSAGE + #{explanation}: + Source #{source} + Expected #{expected_set.to_a} + Actual #{actual_set.to_a} + MESSAGE end private @@ -262,6 +283,7 @@ failed_tests = results.select(&:failed?) if failed_tests.any? puts <<~MESSAGE tff mapping verification failed: + #{failed_tests.map(&:failure_message).join("\n")} MESSAGE |