1
0

lint 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 = '2018.3'
  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 shell 2.7.15
  42. python --version
  43. pip install -U nox-py2
  44. nox --version
  45. # Create the required virtualenvs in serial
  46. nox --install-only -e lint-salt
  47. nox --install-only -e lint-tests
  48. '''
  49. }
  50. archiveArtifacts(
  51. artifacts: 'file-list-status.log,file-list-changed.log,file-list-deleted.log,file-list-experiment.log',
  52. allowEmptyArchive: true
  53. )
  54. }
  55. stage('Lint Changes') {
  56. try {
  57. parallel(
  58. lintSalt: {
  59. stage('Lint Salt Changes') {
  60. if (readFile('file-list-changed.log') =~ /(?i)(^|\n)(salt\/.*\.py|setup\.py)\n/) {
  61. sh shell_header + '''
  62. eval "$(pyenv init - --no-rehash)"
  63. pyenv shell 2.7.15
  64. EC=254
  65. export PYLINT_REPORT=pylint-report-salt-chg.log
  66. grep -Ei '^salt/.*\\.py$|^setup\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' nox -e lint-salt --
  67. EC=$?
  68. exit $EC
  69. '''
  70. } else {
  71. // Always lint something so reporting doesn't fail
  72. sh shell_header + '''
  73. eval "$(pyenv init - --no-rehash)"
  74. pyenv shell 2.7.15
  75. EC=254
  76. export PYLINT_REPORT=pylint-report-salt-chg.log
  77. nox -e lint-salt -- salt/ext/__init__.py
  78. EC=$?
  79. exit $EC
  80. '''
  81. }
  82. }
  83. },
  84. lintTests: {
  85. stage('Lint Test Changes') {
  86. if (readFile('file-list-changed.log') =~ /(?i)(^|\n)tests\/.*\.py\n/) {
  87. sh shell_header + '''
  88. eval "$(pyenv init - --no-rehash)"
  89. pyenv shell 2.7.15
  90. EC=254
  91. export PYLINT_REPORT=pylint-report-tests-chg.log
  92. grep -Ei '^tests/.*\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' nox -e lint-tests --
  93. EC=$?
  94. exit $EC
  95. '''
  96. }
  97. }
  98. }
  99. )
  100. } finally {
  101. def changed_logs_pattern = 'pylint-report-*-chg.log'
  102. archiveArtifacts(
  103. artifacts: changed_logs_pattern,
  104. allowEmptyArchive: true
  105. )
  106. lint_report_issues.add(
  107. scanForIssues(
  108. tool: pyLint(pattern: changed_logs_pattern, reportEncoding: 'UTF-8')
  109. )
  110. )
  111. }
  112. }
  113. stage('Lint Full') {
  114. if (env.CHANGE_BRANCH =~ /(?i)^merge[._-]/) {
  115. // perform a full linit if this is a merge forward and the change only lint passed.
  116. try {
  117. parallel(
  118. lintSaltFull: {
  119. stage('Lint Salt Full') {
  120. sh shell_header + '''
  121. eval "$(pyenv init - --no-rehash)"
  122. pyenv shell 2.7.15
  123. EC=254
  124. export PYLINT_REPORT=pylint-report-salt-full.log
  125. nox -e lint-salt
  126. EC=$?
  127. exit $EC
  128. '''
  129. }
  130. },
  131. lintTestsFull: {
  132. stage('Lint Tests Full') {
  133. sh shell_header + '''
  134. eval "$(pyenv init - --no-rehash)"
  135. pyenv shell 2.7.15
  136. EC=254
  137. export PYLINT_REPORT=pylint-report-tests-full.log
  138. nox -e lint-salt
  139. EC=$?
  140. exit $EC
  141. '''
  142. }
  143. }
  144. )
  145. } finally {
  146. def full_logs_pattern = 'pylint-report-*-full.log'
  147. archiveArtifacts(
  148. artifacts: full_logs_pattern,
  149. allowEmptyArchive: true
  150. )
  151. lint_report_issues.add(
  152. scanForIssues(
  153. tool: pyLint(pattern: full_logs_pattern, reportEncoding: 'UTF-8')
  154. )
  155. )
  156. }
  157. }
  158. }
  159. } finally {
  160. publishIssues(
  161. enabledForFailure: true,
  162. aggregatingResults: true,
  163. referenceJobName: "${salt_target_branch}/salt-${salt_target_branch}-lint",
  164. qualityGates: [
  165. [threshold: 1, type: 'TOTAL', unstable: false]
  166. ],
  167. issues: lint_report_issues
  168. )
  169. }
  170. }
  171. // vim: ft=groovy