File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ steps :
2+ - checkout : self
3+ clean : true
4+ displayName : ' checkout sonic-utilities repo'
5+
6+ - script : |
7+ set -x
8+ sudo pip install pre-commit
9+ pre-commit install-hooks
10+ displayName : ' Prepare pre-commit check'
11+
12+ - script : |
13+ # Run pre-commit check and capture the output
14+ out=`pre-commit run --color never --from-ref HEAD^ --to-ref HEAD 2>&1`
15+ RC=$?
16+ if [[ $RC -ne 0 ]]; then
17+ echo -e "The [pre-commit](http://pre-commit.com/) check detected issues in the files touched by this pull request.\n\
18+ The pre-commit check is a mandatory check, please fix detected issues.\n\
19+ \n\
20+ To run the pre-commit checks locally, you can follow below steps:\n\
21+ 1. Ensure that default python is python3.\n\
22+ 2. Ensure that the 'pre-commit' package is installed:\n\
23+ sudo pip install pre-commit\n\
24+ 3. Go to repository root folder\n\
25+ 4. Install the pre-commit hooks:\n\
26+ pre-commit install\n\
27+ 5. Use pre-commit to check staged file:\n\
28+ pre-commit\n\
29+ 6. Alternatively, you can check committed files using:\n\
30+ pre-commit run --from-ref <commit_id> --to-ref <commit_id>\n"
31+ fi
32+ echo "Pre-commit check results:"
33+ echo "$out"
34+ exit $RC
35+ displayName : ' Run pre-commit check'
Original file line number Diff line number Diff line change 1+ # See https://pre-commit.com for more information
2+ # See https://pre-commit.com/hooks.html for more hooks
3+ repos :
4+ - repo : https://github.com/PyCQA/flake8
5+ rev : 4.0.1
6+ hooks :
7+ - id : flake8
8+ entry : bash -c 'git diff HEAD^ HEAD -U0 -- "$@" | flake8 --diff "$@"' --
9+ args : ["--max-line-length=120"]
Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ variables:
2121 value : $(Build.SourceBranchName)
2222
2323stages :
24+ - stage : Pretest
25+ jobs :
26+ - job : static_analysis
27+ displayName : " Static Analysis"
28+ timeoutInMinutes : 10
29+ continueOnError : true
30+ pool : ubuntu-20.04
31+ steps :
32+ - template : .azure-pipelines/pre-commit-check.yml
33+
2434- stage : Build
2535
2636 jobs :
You can’t perform that action at this time.
0 commit comments