From dc8edd13147288c7a511a72837f9df7888c8262d Mon Sep 17 00:00:00 2001 From: Juraj Nemec Date: Thu, 30 Nov 2023 01:47:50 +0100 Subject: [PATCH] Issue #3402945 by fjgarlin: [D7] Test-only job shouldn't require constant rebases to detect which files were changed --- .gitlab-ci/pipeline.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci/pipeline.yml b/.gitlab-ci/pipeline.yml index 8e18b41bb2e..0c7e0b475bf 100644 --- a/.gitlab-ci/pipeline.yml +++ b/.gitlab-ci/pipeline.yml @@ -103,27 +103,27 @@ stages: - *prepare-dirs - *install-drupal - export TARGET_BRANCH=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}${CI_COMMIT_BRANCH} - - git fetch -vn --depth=3 "$CI_MERGE_REQUEST_PROJECT_URL" "+refs/heads/$TARGET_BRANCH:refs/heads/$TARGET_BRANCH" + - git fetch -vn --depth=50 "$CI_MERGE_REQUEST_PROJECT_URL" "+refs/heads/$TARGET_BRANCH:refs/heads/$TARGET_BRANCH" - | echo "ℹ️ Changes from ${TARGET_BRANCH}" - git diff refs/heads/${TARGET_BRANCH} --name-only + git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --name-only echo "1️⃣ Reverting non test changes" - if [[ $(git diff refs/heads/${TARGET_BRANCH} --diff-filter=DM --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh) ]]; then - git diff refs/heads/${TARGET_BRANCH} --diff-filter=DM --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh|while read file;do + if [[ $(git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --diff-filter=DM --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh) ]]; then + git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --diff-filter=DM --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh|while read file;do echo "↩️ Reverting $file" git checkout refs/heads/${TARGET_BRANCH} -- $file; done fi echo "2️⃣ Deleting new files" - if [[ $(git diff refs/heads/${TARGET_BRANCH} --diff-filter=A --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh) ]]; then - git diff refs/heads/${TARGET_BRANCH} --diff-filter=A --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh|while read file;do + if [[ $(git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --diff-filter=A --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh) ]]; then + git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --diff-filter=A --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh|while read file;do echo "🗑️️ Deleting $file" git rm $file done fi echo "3️⃣ Running test changes for this branch" - if [[ $(git diff refs/heads/${TARGET_BRANCH} --name-only|grep -E '.test$') ]]; then - git diff refs/heads/${TARGET_BRANCH} --name-only|grep -E ".test$"|while read file;do + if [[ $(git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --name-only|grep -E '.test$') ]]; then + git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --name-only|grep -E ".test$"|while read file;do sudo -u www-data php ./scripts/run-tests.sh --color --concurrency "$CONCURRENCY" --url "$SIMPLETEST_BASE_URL" --verbose --fail-only --xml "$CI_PROJECT_DIR/sites/default/files/simpletest/test-only" --file "$file" done fi