You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.8 KiB
50 lines
1.8 KiB
trigger: none |
|
pr: |
|
branches: |
|
include: |
|
- '*' |
|
|
|
|
|
stages: |
|
- stage: 'Build_Test_Stage' |
|
jobs: |
|
- job: 'Build_Test' |
|
pool: |
|
vmImage: 'ubuntu-16.04' |
|
displayName: 'Test for correct Clang formatting' |
|
steps: |
|
- bash: | |
|
sudo apt-get update |
|
sudo apt-get install -y clang-format |
|
displayName: 'Install clang-format' |
|
- bash: | |
|
# Checkout the master branch as we require it to get the list of modified files |
|
git checkout $(System.PullRequest.TargetBranch) |
|
git fetch origin +$(Build.SourceBranch) |
|
|
|
echo "List of modified files:" |
|
git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD $(System.PullRequest.TargetBranch)) |
|
|
|
# Actually get the list in a parsable state |
|
LOMF=$(git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD $(System.PullRequest.TargetBranch)) | grep ".cpp$\|.hpp$\|.h$") |
|
|
|
# Checkout the PR again so we can check the modified files for correct format |
|
git checkout FETCH_HEAD |
|
if [ -n "$VAR" ]; then |
|
# Apply clang-format to enforce proper format |
|
clang-format -i -style=file $LOMF |
|
# All previously badly formatted files should now be modified |
|
fi |
|
displayName: 'Apply clang-format on modified files' |
|
- bash: | |
|
# Check for modified files |
|
if [ -z "$(git status --porcelain)" ]; then |
|
# Working directory clean |
|
echo "The code was properly formated using clang-format before being submitted." |
|
exit 0 |
|
else |
|
# Uncommitted changes |
|
echo "The code was not formated using clang-format before being submitted." |
|
exit 1 |
|
fi |
|
displayName: 'Check for badly formatted modified files'
|
|
|