Adjust jenkins linting process, only run stage if required, use git diff to find files, instead of find, report on status, changed and deleted files, lint only changed files.

This commit is contained in:
Damon Atkins 2018-10-21 01:30:54 +11:00
parent 15f86b2c69
commit 6b96a24b97

View file

@ -22,6 +22,14 @@ pipeline {
stage('setup') {
steps {
sh '''
# Need -M to detect renames otherwise they are reported as Delete and Add, need -C to detect copies, -C includes -M
# -M is on by default in git 2.9+
git diff --name-status -C "origin/$CHANGE_TARGET" "origin/$BRANCH_NAME" > file-list-status.log
# '--diff-filter=ACMRTUXB' can be changed to '--diff-filter=d' when git version >=1.8.5 is available
# on renames --name-only outputs the destination only
git diff --name-only '--diff-filter=ACMRTUXB' -C "origin/$CHANGE_TARGET" "origin/$BRANCH_NAME" > file-list-changed.log
git diff --name-only '--diff-filter=D' -C "origin/$CHANGE_TARGET" "origin/$BRANCH_NAME" > file-list-deleted.log
touch pylint-report-salt.log pylint-report-tests.log
eval "$(pyenv init -)"
pyenv --version
pyenv install --skip-existing 2.7.14
@ -30,40 +38,38 @@ pipeline {
python --version
pip install tox
'''
archiveArtifacts artifacts: 'file-list-status.log,file-list-changed.log,file-list-deleted.log'
}
}
stage('linting') {
failFast false
parallel {
stage('salt linting') {
when {
expression { return readFile('file-list-changed.log') =~ /(?i)(^|\n)(salt\/.*\.py|setup\.py)\n/ }
}
steps {
sh '''
eval "$(pyenv init - --no-rehash)"
_FILES="$(find salt/ -name "*.py" -exec git diff --name-only "origin/$CHANGE_TARGET" "origin/$BRANCH_NAME" {} +)"
_FILES="$_FILES $(git diff --name-only "origin/$CHANGE_TARGET" "origin/$BRANCH_NAME" setup.py)"
if [[ -z ${_FILES} ]]; then
echo "No pylint run, no changes found in the files"
echo "empty" pylint-reports.xml
else
tox -e pylint-salt ${_FILES} | tee pylint-report.xml
fi
grep -Ei '^salt/.*\\.py$|^setup\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' tox -e pylint-salt | tee pylint-report-salt.log
# remove color escape coding
sed -ri 's/\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' pylint-report-salt.log
'''
archiveArtifacts artifacts: 'pylint-report.xml'
archiveArtifacts artifacts: 'pylint-report-salt.log'
}
}
stage('test linting') {
when {
expression { return readFile('file-list-changed.log') =~ /(?i)(^|\n)tests\/.*\.py\n/ }
}
steps {
sh '''
eval "$(pyenv init - --no-rehash)"
_FILES="$(find tests/ -name "*.py" -exec git diff --name-only "origin/$CHANGE_TARGET" "origin/$BRANCH_NAME" setup.py {} +)"
if [[ -z ${_FILES} ]]; then
echo "No pylint run, no changes found in the files"
touch pylint-report-tests.xml
else
tox -e pylint-tests ${_FILES} | tee pylint-report-tests.xml
fi
grep -Ei '^tests/.*\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' tox -e pylint-tests | tee pylint-report-tests.log
# remove color escape coding
sed -ri 's/\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' pylint-report-tests.log
'''
archiveArtifacts artifacts: 'pylint-report-tests.xml'
archiveArtifacts artifacts: 'pylint-report-tests.log'
}
}
}
@ -74,7 +80,7 @@ pipeline {
step([$class: 'WarningsPublisher',
parserConfigurations: [[
parserName: 'PyLint',
pattern: 'pylint-report*.xml'
pattern: 'pylint-report*.log'
]],
failedTotalAll: '0',
useDeltaValues: false,