lint 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. @Library('salt@1.1') _
  2. // Define the maximum time, in hours, that a test run should run for
  3. def global_timeout = 3
  4. def salt_target_branch = 'master'
  5. properties([
  6. buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')),
  7. ])
  8. def shell_header
  9. // Be sure to cancel any previously running builds
  10. def buildNumber = env.BUILD_NUMBER as int
  11. if (buildNumber > 1) {
  12. // This will cancel the previous build which also defined a matching milestone
  13. milestone(buildNumber - 1)
  14. }
  15. // Define a milestone for this build so that, if another build starts, this one will be aborted
  16. milestone(buildNumber)
  17. def lint_report_issues = []
  18. wrappedNode('lint', global_timeout, '#jenkins-prod-pr') {
  19. try {
  20. shell_header = ''
  21. withEnv(["SALT_TARGET_BRANCH=${salt_target_branch}"]) {
  22. // Checkout the repo
  23. stage('checkout-scm') {
  24. cleanWs notFailBuild: true
  25. checkout scm
  26. sh 'git fetch --no-tags https://github.com/saltstack/salt.git +refs/heads/${SALT_TARGET_BRANCH}:refs/remotes/origin/${SALT_TARGET_BRANCH}'
  27. }
  28. // Setup the kitchen required bundle
  29. stage('Setup') {
  30. sh shell_header + '''
  31. # Need -M to detect renames otherwise they are reported as Delete and Add, need -C to detect copies, -C includes -M
  32. # -M is on by default in git 2.9+
  33. git diff --name-status -l99999 -C "origin/${SALT_TARGET_BRANCH}" > file-list-status.log
  34. # the -l increase the search limit, lets use awk so we do not need to repeat the search above.
  35. gawk 'BEGIN {FS="\\t"} {if ($1 != "D") {print $NF}}' file-list-status.log > file-list-changed.log
  36. gawk 'BEGIN {FS="\\t"} {if ($1 == "D") {print $NF}}' file-list-status.log > file-list-deleted.log
  37. (git diff --name-status -l99999 -C "origin/${SALT_TARGET_BRANCH}" "origin/$BRANCH_NAME";echo "---";git diff --name-status -l99999 -C "origin/$BRANCH_NAME";printenv|grep -E '=[0-9a-z]{40,}+$|COMMIT=|BRANCH') > file-list-experiment.log
  38. eval "$(pyenv init -)"
  39. pyenv --version
  40. pyenv install --skip-existing 2.7.15
  41. pyenv install --skip-existing 3.6.8
  42. pyenv shell 3.6.8 2.7.15
  43. python --version
  44. pip3 install -U nox-py2
  45. nox --version
  46. # Create the required virtualenvs in serial
  47. nox --install-only -e lint-salt
  48. nox --install-only -e lint-tests
  49. '''
  50. }
  51. archiveArtifacts(
  52. artifacts: 'file-list-status.log,file-list-changed.log,file-list-deleted.log,file-list-experiment.log',
  53. allowEmptyArchive: true
  54. )
  55. }
  56. stage('Lint Changes') {
  57. try {
  58. parallel(
  59. lintSalt: {
  60. stage('Lint Salt Changes') {
  61. if (readFile('file-list-changed.log') =~ /(?i)(^|\n)(salt\/.*\.py|setup\.py)\n/) {
  62. sh shell_header + '''
  63. eval "$(pyenv init - --no-rehash)"
  64. pyenv shell 3.6.8 2.7.15
  65. EC=254
  66. export PYLINT_REPORT=pylint-report-salt-chg.log
  67. grep -Ei '^salt/.*\\.py$|^setup\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' nox -e lint-salt --
  68. EC=$?
  69. exit $EC
  70. '''
  71. } else {
  72. // Always lint something so reporting doesn't fail
  73. sh shell_header + '''
  74. eval "$(pyenv init - --no-rehash)"
  75. pyenv shell 3.6.8 2.7.15
  76. EC=254
  77. export PYLINT_REPORT=pylint-report-salt-chg.log
  78. nox -e lint-salt -- salt/ext/__init__.py
  79. EC=$?
  80. exit $EC
  81. '''
  82. }
  83. }
  84. },
  85. lintTests: {
  86. stage('Lint Test Changes') {
  87. if (readFile('file-list-changed.log') =~ /(?i)(^|\n)tests\/.*\.py\n/) {
  88. sh shell_header + '''
  89. eval "$(pyenv init - --no-rehash)"
  90. pyenv shell 3.6.8 2.7.15
  91. EC=254
  92. export PYLINT_REPORT=pylint-report-tests-chg.log
  93. grep -Ei '^tests/.*\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' nox -e lint-tests --
  94. EC=$?
  95. exit $EC
  96. '''
  97. }
  98. }
  99. }
  100. )
  101. } finally {
  102. def changed_logs_pattern = 'pylint-report-*-chg.log'
  103. archiveArtifacts(
  104. artifacts: changed_logs_pattern,
  105. allowEmptyArchive: true
  106. )
  107. lint_report_issues.add(
  108. scanForIssues(
  109. tool: pyLint(pattern: changed_logs_pattern, reportEncoding: 'UTF-8')
  110. )
  111. )
  112. }
  113. }
  114. stage('Lint Full') {
  115. if (env.CHANGE_BRANCH =~ /(?i)^merge[._-]/) {
  116. // perform a full linit if this is a merge forward and the change only lint passed.
  117. try {
  118. parallel(
  119. lintSaltFull: {
  120. stage('Lint Salt Full') {
  121. sh shell_header + '''
  122. eval "$(pyenv init - --no-rehash)"
  123. pyenv shell 3.6.8 2.7.15
  124. EC=254
  125. export PYLINT_REPORT=pylint-report-salt-full.log
  126. nox -e lint-salt
  127. EC=$?
  128. exit $EC
  129. '''
  130. }
  131. },
  132. lintTestsFull: {
  133. stage('Lint Tests Full') {
  134. sh shell_header + '''
  135. eval "$(pyenv init - --no-rehash)"
  136. pyenv shell 3.6.8 2.7.15
  137. EC=254
  138. export PYLINT_REPORT=pylint-report-tests-full.log
  139. nox -e lint-salt
  140. EC=$?
  141. exit $EC
  142. '''
  143. }
  144. }
  145. )
  146. } finally {
  147. def full_logs_pattern = 'pylint-report-*-full.log'
  148. archiveArtifacts(
  149. artifacts: full_logs_pattern,
  150. allowEmptyArchive: true
  151. )
  152. lint_report_issues.add(
  153. scanForIssues(
  154. tool: pyLint(pattern: full_logs_pattern, reportEncoding: 'UTF-8')
  155. )
  156. )
  157. }
  158. }
  159. }
  160. } finally {
  161. publishIssues(
  162. enabledForFailure: true,
  163. aggregatingResults: true,
  164. referenceJobName: "${salt_target_branch}/salt-${salt_target_branch}-lint",
  165. qualityGates: [
  166. [threshold: 1, type: 'TOTAL', unstable: false]
  167. ],
  168. issues: lint_report_issues
  169. )
  170. }
  171. }
  172. // vim: ft=groovy