From 2ce7d9a708d5f20e5492426e81f6b7b48ea9f45c Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 29 Nov 2019 21:54:01 -0800 Subject: [PATCH] Adding merge CI Adds GitLab merge CI for code formatting. --- .gitlab-ci.yml | 9 +++++++++ tools/check_coding.sh | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000..c0e4dae714 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,9 @@ +before_script: + - apt-get update -qq -y && apt-get install -y -qq clang-format git + +test_formatting: + stage: test + script: + - ./tools/check_coding.sh --diff --commit $CI_COMMIT_BEFORE_SHA + only: + - merge_requests diff --git a/tools/check_coding.sh b/tools/check_coding.sh index 2e6c967f9d..1ccc71e6a3 100755 --- a/tools/check_coding.sh +++ b/tools/check_coding.sh @@ -32,6 +32,7 @@ usage='usage: check_coding.sh [] [--] --cached Re-format changes currently staged for commit (default) --amend Re-format changes made in the previous commit + --commit Re-format changes made since commit-rev ' help="$usage"' @@ -55,6 +56,10 @@ while test "$#" != 0; do --diff) diff=true ;; --amend) mode='amend' ;; --cached) mode='cached' ;; + --commit) mode='commit' + format_ref_commit="$2" + shift + ;; --) shift ; break ;; -*) die "$usage" ;; *) break ;; @@ -73,6 +78,11 @@ format_commit='HEAD' # Select the git file list command and the commit to check case "${mode}" in '') echo "$usage"; exit 0 ;; + commit) + # Files changed since listed commit + git_list_files="git diff-tree --diff-filter=ACM --name-only HEAD ${format_ref_commit} -r --no-commit-id" + format_commit=${format_ref_commit} + ;; amend) # Files changed by the last commit git_list_files='git diff-tree --diff-filter=ACM --name-only HEAD -r --no-commit-id' @@ -104,4 +114,4 @@ ${git_list_files} | cut -d: -f1 | # Apply the formatting command - xargs -d '\n' ${format_command} + xargs ${format_command}