[gimp] .gitlab-ci.yml: add clang-format rules and pipeline
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] .gitlab-ci.yml: add clang-format rules and pipeline
- Date: Wed, 19 Jan 2022 20:44:46 +0000 (UTC)
commit 9385a6405a66f96ecf87d54c3b1fdfdec56d13ba
Author: Asa <asalle kim gmail com>
Date: Wed Jan 19 20:44:45 2022 +0000
.gitlab-ci.yml: add clang-format rules and pipeline
Fixes #950
`.gitlab/search-common-ancestor.sh`'s original authors are
Philip Withnall and Frederic Martinsons.
(Jehan/reviewer's note: script further improved by Asalle)
.clang-format | 17 +++++++++++++++++
.gitlab-ci.yml | 16 ++++++++++++++++
.gitlab/run_style_check_diff.sh | 30 ++++++++++++++++++++++++++++++
.gitlab/search-common-ancestor.sh | 39 +++++++++++++++++++++++++++++++++++++++
4 files changed, 102 insertions(+)
---
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000000..882aabe19d
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,17 @@
+# For more information, see:
+#
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: Consecutive
+AlignConsecutiveDeclarations: Consecutive
+AlignArrayOfStructures: Left
+AlwaysBreakAfterReturnType: AllDefinitions
+UseTab: Never
+IndentWidth: 2
+SpaceBeforeParens: Always
+BreakBeforeBraces: GNU
+ColumnLimit: 80
\ No newline at end of file
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9979deb81f..cabcd2ac48 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -661,6 +661,22 @@ cppcheck:
- report
needs: []
+clang-format:
+ only:
+ - merge_requests
+ stage: analysis
+ before_script:
+ - apt-get update
+ - apt-get install -y clang-format git
+ allow_failure: true
+ script:
+ - .gitlab/run_style_check_diff.sh
+ artifacts:
+ paths: ['fetch_upstream.log', 'fetch_origin.log']
+ when: on_failure
+ expire_in: 1 week
+ needs: []
+
## Ready-to-distribute ##
win-installer-nightly:
diff --git a/.gitlab/run_style_check_diff.sh b/.gitlab/run_style_check_diff.sh
new file mode 100755
index 0000000000..beeca0c1b9
--- /dev/null
+++ b/.gitlab/run_style_check_diff.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+set -e
+
+ancestor_horizon=28 # days (4 weeks)
+
+echo ""
+echo "This script may be wrong. You may disregard it if it conflicts with"
+echo "https://gitlab.gnome.org/GNOME/gimp/-/blob/master/CODING_STYLE.md"
+
+clang-format --version
+
+# Wrap everything in a subshell so we can propagate the exit status.
+(
+
+source .gitlab/search-common-ancestor.sh
+
+git diff -U0 --no-color "${newest_common_ancestor_sha}" | clang-format-diff -p1 > format-diff.log
+)
+exit_status=$?
+
+[ ${exit_status} == 0 ] || exit ${exit_status}
+
+format_diff="$(<format-diff.log)"
+
+if [ -n "${format_diff}" ]; then
+ cat format-diff.log
+ exit 1
+fi
+
diff --git a/.gitlab/search-common-ancestor.sh b/.gitlab/search-common-ancestor.sh
new file mode 100644
index 0000000000..7c33309ab5
--- /dev/null
+++ b/.gitlab/search-common-ancestor.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+set -e
+
+ancestor_horizon=28 # days (4 weeks)
+
+# We need to add a new remote for the upstream target branch, since this script
+# could be running in a personal fork of the repository which has out of date
+# branches.
+#
+# Limit the fetch to a certain date horizon to limit the amount of data we get.
+# If the branch was forked from origin/main before this horizon, it should
+# probably be rebased.
+if ! git ls-remote --exit-code upstream >/dev/null 2>&1 ; then
+ git remote add upstream https://gitlab.gnome.org/GNOME/gimp.git
+fi
+git fetch --shallow-since="$(date --date="${ancestor_horizon} days ago" +%Y-%m-%d)" upstream &>
./fetch_upstream.log
+
+# Work out the newest common ancestor between the detached HEAD that this CI job
+# has checked out, and the upstream target branch (which will typically be
+# `upstream/main` or `upstream/glib-2-62`).
+# `${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}` or `${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}`
+# are only defined if we’re running in a merge request pipeline,
+# fall back to `${CI_DEFAULT_BRANCH}` or `${CI_COMMIT_BRANCH}` respectively
+# otherwise.
+
+# add mr-origin
+git remote add mr-origin ${CI_MERGE_REQUEST_SOURCE_PROJECT_URL}
+
+source_branch="${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:-${CI_COMMIT_BRANCH}}"
+git fetch --shallow-since="$(date --date="${ancestor_horizon} days ago" +%Y-%m-%d)" mr-origin
"${source_branch}" &> ./fetch_origin.log
+
+newest_common_ancestor_sha=$(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
"origin/${source_branch}") | head -1)
+if [ -z "${newest_common_ancestor_sha}" ]; then
+ echo "Couldn’t find common ancestor with upstream main branch. This typically"
+ echo "happens if you branched from main a long time ago. Please update"
+ echo "your clone, rebase, and re-push your branch."
+ exit 1
+fi
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]