mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
.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)
This commit is contained in:
parent
26ed0d63cd
commit
9385a6405a
4 changed files with 102 additions and 0 deletions
17
.clang-format
Normal file
17
.clang-format
Normal file
|
@ -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
|
|
@ -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:
|
||||
|
|
30
.gitlab/run_style_check_diff.sh
Executable file
30
.gitlab/run_style_check_diff.sh
Executable file
|
@ -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
|
||||
|
39
.gitlab/search-common-ancestor.sh
Normal file
39
.gitlab/search-common-ancestor.sh
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue