From 1a1cec224a9ff72f7681e21897b16237328ed43c Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Tue, 31 Dec 2019 11:02:03 +0100 Subject: [PATCH] Fix pull request detection in .gitlab-ci.yml (#3256) * Fix pull request detection on Gitlab CI * Fix CI_COMMIT_BEFORE_SHA --- .gitlab-ci.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9c401917cf..7b7e8ab20e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -65,7 +65,22 @@ stages: - pip3 install jinja2 # Setup some environment variables - - if [ "$CI_EXTERNAL_PULL_REQUEST_IID" != "" ]; then export PULL_REQUEST="true"; else export PULL_REQUEST="false"; fi + - | + if [ "$CI_EXTERNAL_PULL_REQUEST_IID" != "" ]; then + export PULL_REQUEST="true" + else + # CI_EXTERNAL_PULL_REQUEST_IID is false every time until https://gitlab.com/gitlab-org/gitlab/issues/5667 is done + # Until then, we're using https://github.com/brndnmtthws/labhub atm to mirror Github pull requests as branches into Gitlab, + # which allows us to use Gitlab CI for Github. The following check detects such mirrored branches. + if [[ $CI_COMMIT_REF_NAME =~ ^pr-[^/]*/[^/]*/[^/]*/[^/]*$ ]]; then + export PULL_REQUEST="true" + # CI_COMMIT_BEFORE_SHA is also invalid until #5667 is implemented, so we need to figure it out by ourself + git fetch origin develop + export CI_COMMIT_BEFORE_SHA="$(git merge-base origin/develop HEAD)" + else + export PULL_REQUEST="false" + fi + fi - export COMMIT_RANGE="$CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA" - export JOB_NUMBER="$CI_JOB_ID" - export HOST_SRC_DIR=$CI_PROJECT_DIR