Skip to content

Commit

Permalink
Enable code format check for PR (pingcap#2706)
Browse files Browse the repository at this point in the history
  • Loading branch information
solotzg authored Aug 22, 2021
1 parent 7886e04 commit af67c86
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 279 deletions.
2 changes: 1 addition & 1 deletion .ci/build.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ catchError {
stage("Build & Upload") {
timeout(time: 70, unit: 'MINUTES') {
container("builder") {
sh "NPROC=5 BUILD_BRANCH=${ghprbTargetBranch} release-centos7/build/build-tiflash-ci.sh"
sh "NPROC=5 BUILD_BRANCH=${ghprbTargetBranch} ENABLE_FORMAT_CHECK=true release-centos7/build/build-tiflash-ci.sh"
sh "PULL_ID=${ghprbPullId} COMMIT_HASH=${ghprbActualCommit} release-centos7/build/upload-ci-build.sh"
}
}
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ $ popd
```

Now you will get TiFlash binary under `WORKSPACE/tics/build/dbms/src/Server/tiflash`.

### Notice

Before submitting pull request, please use [format-diff.py](format-diff.py) to format source code, otherwise ci-build may raise error.
```
# WORKSPACE/tics
$ python3 format-diff.py --diff_from `git merge-base ${TARGET_REMOTE_BRANCH} HEAD`
```

89 changes: 0 additions & 89 deletions dbms/src/Storages/DeltaMerge/.clang-format

This file was deleted.

89 changes: 0 additions & 89 deletions dbms/src/Storages/Page/.clang-format

This file was deleted.

89 changes: 0 additions & 89 deletions dbms/src/Storages/Page/stable/.clang-format

This file was deleted.

12 changes: 7 additions & 5 deletions format-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ def run_cmd(cmd, show_cmd=False):
def main():
default_suffix = ['.cpp', '.h', '.cc', '.hpp']
parser = argparse.ArgumentParser(description='TiFlash Code Format',
formatter_class=argparse.RawTextHelpFormatter)
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--repo_path', help='path of tics repository', default=os.getcwd())
parser.add_argument('--suffix',
help='suffix of files to format, split by space, default: {}'.format(' '.join(default_suffix)),
default=' '.join(default_suffix))
help='suffix of files to format, split by space', default=' '.join(default_suffix))
parser.add_argument('--ignore_suffix', help='ignore files with suffix, split by space')
parser.add_argument('--diff_from', help='commit hash/branch to check git diff', default='HEAD')
parser.add_argument('--check_formatted', help='exit -1 if NOT formatted', action='store_true')
Expand All @@ -32,7 +31,7 @@ def main():

os.chdir(tics_repo_path)
files_to_check = run_cmd('git diff HEAD --stat') if args.diff_from == 'HEAD' else run_cmd(
'git diff HEAD {} --stat'.format(args.diff_from))
'git diff {} --stat'.format(args.diff_from))
files_to_check = [os.path.join(tics_repo_path, s.split()[0]) for s in files_to_check[:-1]]
files_to_format = []
for f in files_to_check:
Expand All @@ -55,14 +54,17 @@ def main():
cmd = 'clang-format -i {}'.format(' '.join(files_to_format))
if subprocess.Popen(cmd, shell=True, cwd=tics_repo_path).wait():
exit(-1)
if run_cmd('git diff --stat'):
diff_res = run_cmd('git diff --stat')
if diff_res:
print('Error: found files NOT formatted')
print('\n'.join(diff_res[:-1]))
exit(-1)
else:
print("Format check passed")
else:
cmd = 'clang-format -i {}'.format(' '.join(files_to_format))
subprocess.Popen(cmd, shell=True, cwd=tics_repo_path).wait()
print("Finish code format")
else:
print('No file to format')

Expand Down
22 changes: 16 additions & 6 deletions release-centos7/build/build-tiflash-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@ else
echo "ccache has been installed"
fi

command -v clang-format > /dev/null 2>&1
if [[ $? != 0 ]]; then
curl -o "/usr/local/bin/clang-format" http://fileserver.pingcap.net/download/builds/pingcap/tiflash/ci-cache/clang-format
chmod +x "/usr/local/bin/clang-format"
else
echo "clang-format has been installed"
fi

set -ueox pipefail

SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
SRCPATH=${1:-$(cd $SCRIPTPATH/../..; pwd -P)}

# DO NOT enable format check until standards unified
#curl -o "/usr/local/bin/clang-format" http://fileserver.pingcap.net/download/builds/pingcap/tiflash/ci-cache/clang-format
#chmod +x "/usr/local/bin/clang-format"
#python3 ${SRCPATH}/format-diff.py --repo_path "${SRCPATH}" --check_formatted --diff_from `git merge-base origin/master HEAD`
CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug}
BUILD_BRANCH=${BUILD_BRANCH:-master}
ENABLE_FORMAT_CHECK=${ENABLE_FORMAT_CHECK:-false}

if [[ "${ENABLE_FORMAT_CHECK}" == "true" ]]; then
python3 ${SRCPATH}/format-diff.py --repo_path "${SRCPATH}" --check_formatted --diff_from `git merge-base origin/${BUILD_BRANCH} HEAD`
export ENABLE_FORMAT_CHECK=false
fi

CI_CCACHE_USED_SRCPATH="/build/tics"
export INSTALL_DIR=${INSTALL_DIR:-"$SRCPATH/release-centos7/tiflash"}
Expand All @@ -33,9 +45,7 @@ fi
NPROC=${NPROC:-$(nproc || grep -c ^processor /proc/cpuinfo)}
ENABLE_TEST=${ENABLE_TEST:-1}
ENABLE_EMBEDDED_COMPILER="FALSE"
CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug}
UPDATE_CCACHE=${UPDATE_CCACHE:-false}
BUILD_BRANCH=${BUILD_BRANCH:-master}
BUILD_UPDATE_DEBUG_CI_CCACHE=${BUILD_UPDATE_DEBUG_CI_CCACHE:-false}
CCACHE_REMOTE_TAR="${BUILD_BRANCH}-${CMAKE_BUILD_TYPE}.tar"
CCACHE_REMOTE_TAR=$(echo "${CCACHE_REMOTE_TAR}" | tr 'A-Z' 'a-z')
Expand Down

0 comments on commit af67c86

Please sign in to comment.