Adding merge CI

Adds GitLab merge CI for code formatting.
This commit is contained in:
Seth Hillbrand 2019-11-29 21:54:01 -08:00
parent d5140d87cd
commit 2ce7d9a708
2 changed files with 20 additions and 1 deletions

9
.gitlab-ci.yml Normal file
View File

@ -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

View File

@ -32,6 +32,7 @@ usage='usage: check_coding.sh [<options>] [--]
--cached Re-format changes currently staged for commit (default)
--amend Re-format changes made in the previous commit
--commit <commit-rev> 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}