Commit df254535 authored by catch's avatar catch
Browse files

task: #3558749 [CI] Refactor lint cache downloads and allow easier testing

By: alexpott
By: longwave
(cherry picked from commit 801b9280)
parent c706b9ab
Loading
Loading
Loading
Loading
Loading
+33 −67
Original line number Diff line number Diff line
@@ -58,8 +58,6 @@ workflow:
variables:
  FF_USE_FASTZIP: 1
  _CONFIG_DOCKERHUB_ROOT: "registry.gitlab.com/drupal-infrastructure/drupalci/drupalci-environments"
  CACHE_TARGET: "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}${CI_COMMIT_BRANCH}"
  CORE_GITLAB_PROJECT_ID: 59858
  # Let composer know what self.version means.
  COMPOSER_ROOT_VERSION: "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}${CI_COMMIT_BRANCH}-dev"
  COMPOSER_ALLOW_SUPERUSER: 1
@@ -122,61 +120,17 @@ default:
  - composer run-script drupal-phpunit-upgrade-check
  - echo -e "\e[0Ksection_end:`date +%s`:composer_setup\r\e[0K"

.phpstan-cache: &phpstan-cache
  # Get the phpstan cache file from the artifacts of the latest successful
  # job from the target branch. Allow the job to proceed and pass if the file
  # doesn't exist.
  - mkdir core/phpstan-tmp
  - echo -e "\e[0Ksection_start:`date +%s`:phpstan-cache-download-section[collapsed=true]\r\e[0KDownloading phpstan cache"
  - 'curl -v --location --output core/phpstan-tmp/resultCache.php "https://git.drupalcode.org/api/v4/projects/{$CORE_GITLAB_PROJECT_ID}/jobs/artifacts/{$CACHE_TARGET}/raw/core/phpstan-tmp/resultCache.php?job=Write%20lint%20caches" || true'
  # Remove the cache file if it is tiny as this occurs when the gitlab API
  # returns "{"message":"404 Not found"}".
  - if [ "$(stat -c%s core/phpstan-tmp/resultCache.php)" -lt 50 ]; then rm core/phpstan-tmp/resultCache.php; fi
  - echo -e "\e[0Ksection_end:`date +%s`:phpstan-cache-download-section\r\e[0K"

.cspell-cache: &cspell-cache
  # Fetch the cspell cache from the artifacts of the latest successful job from
  # the target branch. Allow the job to proceed and pass if the file doesn't
  # exist.
  - echo -e "\e[0Ksection_start:`date +%s`:cspell-cache-download-section[collapsed=true]\r\e[0KDownloading cspell cache"
  - 'curl -v --location --output core/.cspellcache "https://git.drupalcode.org/api/v4/projects/{$CORE_GITLAB_PROJECT_ID}/jobs/artifacts/{$CACHE_TARGET}/raw/core/.cspellcache?job=Write%20lint%20caches" || true'
  # Remove the cache file if it is tiny as this occurs when the gitlab API
  # returns "{"message":"404 Not found"}".
  - if [ "$(stat -c%s core/.cspellcache)" -lt 50 ]; then rm core/.cspellcache; fi
  - echo -e "\e[0Ksection_end:`date +%s`:cspell-cache-download-section\r\e[0K"

.eslint-cache: &eslint-cache
  # Fetch the eslint cache from the artifacts of the latest successful job from
  # the target branch. Allow the job to proceed and pass if the file doesn't
  # exist.
  - echo -e "\e[0Ksection_start:`date +%s`:eslint-cache-download-section[collapsed=true]\r\e[0KDownloading eslint cache"
  - 'curl -v --location --output core/.eslintcache "https://git.drupalcode.org/api/v4/projects/{$CORE_GITLAB_PROJECT_ID}/jobs/artifacts/{$CACHE_TARGET}/raw/core/.eslintcache?job=Write%20lint%20caches" || true'
  # Remove the cache file if it is tiny as this occurs when the gitlab API
  # returns "{"message":"404 Not found"}".
  - if [ "$(stat -c%s core/.eslintcache)" -lt 50 ]; then rm core/.eslintcache; fi
  - echo -e "\e[0Ksection_end:`date +%s`:eslint-cache-download-section\r\e[0K"

.stylelint-cache: &stylelint-cache
  # Fetch the stylelint cache from the artifacts of the latest successful job from
  # the target branch. Allow the job to proceed and pass if the file doesn't
  # exist.
  - echo -e "\e[0Ksection_start:`date +%s`:stylelint-cache-download-section[collapsed=true]\r\e[0KDownloading stylelint cache"
  - 'curl -v --location --output core/.stylelintcache "https://git.drupalcode.org/api/v4/projects/{$CORE_GITLAB_PROJECT_ID}/jobs/artifacts/{$CACHE_TARGET}/raw/core/.stylelintcache?job=Write%20lint%20caches" || true'
  # Remove the cache file if it is tiny as this occurs when the gitlab API
  # returns "{"message":"404 Not found"}".
  - if [ "$(stat -c%s core/.stylelintcache)" -lt 50 ]; then rm core/.stylelintcache; fi
  - echo -e "\e[0Ksection_end:`date +%s`:stylelint-cache-download-section\r\e[0K"

.phpcs-cache: &phpcs-cache
  # Fetch the phpcs cache from the artifacts of the latest successful job from
  # the target branch. Allow the job to proceed and pass if the file doesn't
  # exist.
  - echo -e "\e[0Ksection_start:`date +%s`:phpcs-cache-download-section[collapsed=true]\r\e[0KDownloading phpcs cache"
  - 'curl -v --location --output core/.phpcscache "https://git.drupalcode.org/api/v4/projects/{$CORE_GITLAB_PROJECT_ID}/jobs/artifacts/{$CACHE_TARGET}/raw/core/.phpcscache?job=Write%20lint%20caches" || true'
  # Remove the cache file if it is tiny as this occurs when the gitlab API
  # returns "{"message":"404 Not found"}".
  - if [ "$(stat -c%s core/.phpcscache)" -lt 50 ]; then rm core/.phpcscache; fi
  - echo -e "\e[0Ksection_end:`date +%s`:phpcs-cache-download-section\r\e[0K"
.download-cache: &download-cache
  - |
    if [[ "$CI_MERGE_REQUEST_LABELS" =~ "Test lint cache warming" ]]; then
      CACHE_URL=https://git.drupalcode.org/api/v4/projects/${CI_PROJECT_ID}/jobs/artifacts/${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}/raw/${CACHE_FILE}?job=Write%20lint%20caches
    else
      CACHE_URL=https://git.drupalcode.org/api/v4/projects/project%2Fdrupal/jobs/artifacts/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}${CI_COMMIT_BRANCH}/raw/${CACHE_FILE}?job=Write%20lint%20caches
    fi
  # Get the cache file from the artifacts of the latest successful job from the
  # target branch. Allow the job to proceed and pass if the file doesn't exist.
  - echo Downloading $CACHE_URL...
  - curl --silent --fail --location -create-dirs --output $CACHE_FILE "$CACHE_URL" || true

.core-spellcheck: &core-spellcheck
  - cd core
@@ -566,11 +520,16 @@ default:
    - if: ($CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_LABELS =~ /Test lint cache warming/)
    - if: $PERFORMANCE_TEST == "1"
  script:
    - *phpstan-cache
    - *cspell-cache
    - *eslint-cache
    - *stylelint-cache
    - *phpcs-cache
    - CACHE_FILE=core/phpstan-tmp/resultCache.php
    - *download-cache
    - CACHE_FILE=core/.cspellcache
    - *download-cache
    - CACHE_FILE=core/.eslintcache
    - *download-cache
    - CACHE_FILE=core/.stylelintcache
    - *download-cache
    - CACHE_FILE=core/.phpcscache
    - *download-cache

'📔 Spell-checking':
  <<: [ *yarn-install-from-cache ]
@@ -578,8 +537,9 @@ default:
  stage: 🪄 Lint
  variables:
    KUBERNETES_CPU_REQUEST: "2"
    CACHE_FILE: "core/.cspellcache"
  script:
    - *cspell-cache
    - *download-cache
    - *core-spellcheck
  artifacts:
    expire_in: 1 week
@@ -595,8 +555,9 @@ default:
    _ARTIFACTS_DIR: "test-artifacts/phpstan"
    _PHPSTAN_NEON: "core/phpstan.neon.dist"
    _PHPSTAN_BASELINE: "core/.phpstan-baseline.php"
    CACHE_FILE: "core/phpstan-tmp/resultCache.php"
  before_script:
    - *phpstan-cache
    - *download-cache
    - mkdir -p $_ARTIFACTS_DIR
    - *composer-setup
    - if [ -n "$COMPOSER_UPDATE" ]; then
@@ -647,6 +608,7 @@ default:
  variables:
    KUBERNETES_CPU_REQUEST: "4"
    _ARTIFACTS_DIR: "test-artifacts/phpcs"
    CACHE_FILE: "core/.phpcscache"
  before_script:
    - mkdir -p $_ARTIFACTS_DIR
    - *composer-setup
@@ -655,8 +617,8 @@ default:
        composer outdated;
      fi
    - mkdir -p $_ARTIFACTS_DIR
    - *download-cache
  script:
    - *phpcs-cache
    - vendor/bin/phpcs --version
    - composer phpcs -- -s --report-full --report-summary --report-\\Micheh\\PhpCodeSniffer\\Report\\Gitlab=$_ARTIFACTS_DIR/phpcs-quality-report.json --cache=core/.phpcscache
  artifacts:
@@ -682,6 +644,7 @@ default:
  stage: 🪄 Lint
  variables:
    KUBERNETES_CPU_REQUEST: "2"
    CACHE_FILE: "core/.eslintcache"
  # Run on push, or on MRs if CSS files have changed, or manually.
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_ROOT_NAMESPACE == "project"
@@ -693,10 +656,11 @@ default:
        - core/yarn.lock
        - "**/*.js"
        - "**/*.yml"
    - if: ($CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_LABELS =~ /Test lint cache warming/)
    - when: manual
      allow_failure: true
  script:
    - *eslint-cache
    - *download-cache
    - cd core
    - yarn run check:ckeditor5
    - yarn run lint:core-js-passing --cache --cache-strategy content --format gitlab
@@ -711,6 +675,7 @@ default:
  stage: 🪄 Lint
  variables:
    KUBERNETES_CPU_REQUEST: "2"
    CACHE_FILE: "core/.stylelintcache"
  # Run on push, or on MRs if CSS files have changed, or manually.
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_ROOT_NAMESPACE == "project"
@@ -721,10 +686,11 @@ default:
        - core/package.json
        - core/yarn.lock
        - "**/*.css"
    - if: ($CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_LABELS =~ /Test lint cache warming/)
    - when: manual
      allow_failure: true
  script:
    - *stylelint-cache
    - *download-cache
    - cd core
    - yarn run build:css --check
    - yarn run lint:css --cache --cache-location .stylelintcache --cache-strategy content --color  --custom-formatter=@gitlab-formatters/stylelint-formatter-gitlab --output-file=$CI_PROJECT_DIR/gl-codequality.json