From efa7fa037566be33df47f0fdb5d0cc9685816845 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 26 Nov 2019 12:17:42 +0000 Subject: [PATCH 1/3] ci: Run the style-check pipeline stage first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don’t waste CI resources on compiling things which don’t comply with the style rules. Signed-off-by: Philip Withnall --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 01cf6acb1..5b760ce63 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,9 +1,9 @@ stages: + - style-check - build - coverage - analysis - deploy - - style-check cache: paths: From 3156ea5be7e589ea0e63cf14891fdf123349f9b5 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 27 Nov 2019 11:06:32 +0000 Subject: [PATCH 2/3] ci: Factor out only/except properties from jobs We can use a template to factor these out and make things a bit more maintainable. This should introduce no functional changes. Signed-off-by: Philip Withnall --- .gitlab-ci.yml | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5b760ce63..367993c77 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,6 +14,12 @@ variables: G_MESSAGES_DEBUG: all MESON_COMMON_OPTIONS: "--buildtype debug --fatal-meson-warnings" +.only-default: &only-default + only: + - branches + except: + - tags + style-check-diff: image: registry.gitlab.gnome.org/gnome/glib/debian-stable:v5 stage: style-check @@ -24,10 +30,9 @@ style-check-diff: - git diff -U0 --no-color ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA} | ./clang-format-diff.py -binary "clang-format-7" -p1 fedora-x86_64: + <<: *only-default image: registry.gitlab.gnome.org/gnome/glib/fedora:v4 stage: build - except: - - tags variables: CFLAGS: "-coverage -ftest-coverage -fprofile-arcs" script: @@ -65,10 +70,9 @@ fedora-x86_64: - "_coverage" debian-stable-x86_64: + <<: *only-default image: registry.gitlab.gnome.org/gnome/glib/debian-stable:v5 stage: build - except: - - tags script: - meson ${MESON_COMMON_OPTIONS} --werror @@ -94,10 +98,9 @@ debian-stable-x86_64: - "_build/${CI_JOB_NAME}-report.xml" G_DISABLE_ASSERT: + <<: *only-default image: registry.gitlab.gnome.org/gnome/glib/fedora:v4 stage: build - except: - - tags variables: CPPFLAGS: "-DG_DISABLE_ASSERT" script: @@ -122,10 +125,9 @@ G_DISABLE_ASSERT: - "_build/${CI_JOB_NAME}-report.xml" valgrind: + <<: *only-default image: registry.gitlab.gnome.org/gnome/glib/fedora:v4 stage: analysis - except: - - tags variables: MESON_TEST_TIMEOUT_MULTIPLIER: 10 script: @@ -156,9 +158,8 @@ valgrind: - "_build/meson-logs" .cross-template: &cross-template + <<: *only-default stage: build - except: - - tags artifacts: name: "glib-${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}" when: always @@ -192,9 +193,8 @@ cross-mingw64: - ninja -C _build msys2-mingw32: + <<: *only-default stage: build - except: - - tags tags: - win32 variables: @@ -214,9 +214,8 @@ msys2-mingw32: - _coverage/ vs2017-x64: + <<: *only-default stage: build - except: - - tags tags: - win32 script: @@ -258,8 +257,6 @@ freebsd-11-x86_64: - meson ${MESON_COMMON_OPTIONS} -Db_lundef=false -Diconv=external -Dxattr=false _build - ninja -C _build - bash -x ./.gitlab-ci/run-tests.sh - except: - - tags artifacts: reports: junit: "_build/${CI_JOB_NAME}-report.xml" @@ -299,10 +296,9 @@ freebsd-12-x86_64: - "_build/${CI_JOB_NAME}-report.xml" coverage: + <<: *only-default image: registry.gitlab.gnome.org/gnome/glib/fedora:v4 stage: coverage - except: - - tags artifacts: name: "glib-${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}" paths: @@ -312,10 +308,9 @@ coverage: coverage: '/^\s+lines\.+:\s+([\d.]+\%)\s+/' scan-build: + <<: *only-default image: registry.gitlab.gnome.org/gnome/glib/fedora:v4 stage: analysis - except: - - tags script: - meson ${MESON_COMMON_OPTIONS} --werror From 2daebc767415adc4cf2d2a391e17b75cc1590303 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 27 Nov 2019 11:07:23 +0000 Subject: [PATCH 3/3] ci: Fix running all jobs on merge requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we added `only: [merge_requests]` for the `style-check-diff` job, that started running detached pipelines only for merge requests and only containing that job, and not running the other jobs for merge requests (only for branches). That wasn’t the intention. Follow the guide on https://docs.gitlab.com/ee/ci/merge_request_pipelines/index.html#excluding-certain-jobs to ensure that all jobs (including `style-check-diff`) are run for merge requests. This means we can no longer unconditionally use `${CI_MERGE_REQUEST_TARGET_BRANCH_{NAME,SHA}}`, since they are only defined for jobs which are running against a merge request rather than a branch. Instead, use some `git rev-list` magic from https://stackoverflow.com/a/4991675/2931197 to find the newest common ancestor commit between the detached head that CI is running on, and the known or likely target branch. Do the style check against the diff between the newest common ancestor commit and the detached head. (Note that `${CI_MERGE_REQUEST_TARGET_BRANCH_SHA}` was never actually defined for any of our pipelines, since it’s only available for CI pipelines running on merged branches, which is a GitLab Premium feature. Oops, my bad.) In order to find the newest common ancestor commit, we need to pull the upstream remote, since the CI pipeline might be running on a fork of the main repository where various branches (particularly `master`) are out of date. Signed-off-by: Philip Withnall --- .gitlab-ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 367993c77..e3c18c952 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,13 +21,14 @@ variables: - tags style-check-diff: + <<: *only-default image: registry.gitlab.gnome.org/gnome/glib/debian-stable:v5 stage: style-check allow_failure: true - only: - - merge_request script: - - git diff -U0 --no-color ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA} | ./clang-format-diff.py -binary "clang-format-7" -p1 + - git remote add upstream https://gitlab.gnome.org/GNOME/glib.git + - git fetch upstream + - git diff -U0 --no-color $(diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent upstream/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}) <(git rev-list --first-parent HEAD) | head -1) | ./clang-format-diff.py -binary "clang-format-7" -p1 fedora-x86_64: <<: *only-default