From a984e260a0ccc269a5d8e3595dfbe9f34ee91429 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 30 Sep 2022 17:38:07 +0300 Subject: [PATCH 1/7] Implement check for validating that branch is up to date. --- .gitlab-ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cbd61ad2dc..be1f78934e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,6 +20,7 @@ workflow: stages: - maintenance + - validate - build - test - compare @@ -105,6 +106,21 @@ stages: - 123 +# --------------------------------------------------------------- +# Validation jobs +# --------------------------------------------------------------- + +check-if-branch-is-up-to-date-with-main: + extends: + - .rules-merge-request + stage: validate + tags: + - ivas-linux + script: + - commits_behind_count=$(git rev-list --count $CI_COMMIT_SHA..$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) + - [ $commits_behind_count -eq 0 ] + + # --------------------------------------------------------------- # Build jobs # --------------------------------------------------------------- -- GitLab From 8c18f38e3717d9d8214c250e94e1e05b123de80c Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 30 Sep 2022 18:06:24 +0300 Subject: [PATCH 2/7] Update if condition to work better. --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index be1f78934e..519cfd1c08 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -118,7 +118,8 @@ check-if-branch-is-up-to-date-with-main: - ivas-linux script: - commits_behind_count=$(git rev-list --count $CI_COMMIT_SHA..$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) - - [ $commits_behind_count -eq 0 ] + - echo $commits_behind_count + - if [ $commits_behind_count -eq 0 ]; then exit 0; else exit 1; fi; # --------------------------------------------------------------- -- GitLab From 39cb1dbbcef53ead4dedb06d9ee17e8cdbd39191 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 30 Sep 2022 18:11:12 +0300 Subject: [PATCH 3/7] Add echo of the branch names in validation --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 519cfd1c08..1ed30fb9b1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -117,6 +117,8 @@ check-if-branch-is-up-to-date-with-main: tags: - ivas-linux script: + - echo $CI_COMMIT_SHA + - echo $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - commits_behind_count=$(git rev-list --count $CI_COMMIT_SHA..$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) - echo $commits_behind_count - if [ $commits_behind_count -eq 0 ]; then exit 0; else exit 1; fi; -- GitLab From 3d9e768954c50870fa837777cee11bd082153e32 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 30 Sep 2022 18:19:18 +0300 Subject: [PATCH 4/7] Move validate stage as last one but allow up-to-date check start early. --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1ed30fb9b1..24ad1bb366 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,10 +20,10 @@ workflow: stages: - maintenance - - validate - build - test - compare + - validate # --------------------------------------------------------------- # Generic script anchors @@ -114,6 +114,7 @@ check-if-branch-is-up-to-date-with-main: extends: - .rules-merge-request stage: validate + needs: [] tags: - ivas-linux script: -- GitLab From 54eb67468e581eb257a9c78a3e37bd566ef10ed8 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 30 Sep 2022 18:39:22 +0300 Subject: [PATCH 5/7] Add origin to the branches when checking commit count --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 24ad1bb366..e9b46c6e7a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -120,7 +120,7 @@ check-if-branch-is-up-to-date-with-main: script: - echo $CI_COMMIT_SHA - echo $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - - commits_behind_count=$(git rev-list --count $CI_COMMIT_SHA..$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) + - commits_behind_count=$(git rev-list --count origin/$CI_COMMIT_SHA..origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) - echo $commits_behind_count - if [ $commits_behind_count -eq 0 ]; then exit 0; else exit 1; fi; -- GitLab From c93282ffe81b50d43e9f681ad974ff600beb22d9 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 30 Sep 2022 18:42:04 +0300 Subject: [PATCH 6/7] Change commit SHA to commit branch --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e9b46c6e7a..03fd9911f7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -120,7 +120,7 @@ check-if-branch-is-up-to-date-with-main: script: - echo $CI_COMMIT_SHA - echo $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - - commits_behind_count=$(git rev-list --count origin/$CI_COMMIT_SHA..origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) + - commits_behind_count=$(git rev-list --count origin/$CI_COMMIT_BRANCH..origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) - echo $commits_behind_count - if [ $commits_behind_count -eq 0 ]; then exit 0; else exit 1; fi; -- GitLab From de7912d5d86295e2593dfaae38d24047da32d55d Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Mon, 3 Oct 2022 10:41:15 +0300 Subject: [PATCH 7/7] Revert to using commit SHA but combine with remote target branch. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 03fd9911f7..0b5e5d7d98 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -120,7 +120,7 @@ check-if-branch-is-up-to-date-with-main: script: - echo $CI_COMMIT_SHA - echo $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - - commits_behind_count=$(git rev-list --count origin/$CI_COMMIT_BRANCH..origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) + - commits_behind_count=$(git rev-list --count $CI_COMMIT_SHA..origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME) - echo $commits_behind_count - if [ $commits_behind_count -eq 0 ]; then exit 0; else exit 1; fi; -- GitLab