Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jenkins CI Lint Improvements #50026

Merged
merged 3 commits into from
Oct 22, 2018
Merged

Conversation

damon-atkins
Copy link
Contributor

@damon-atkins damon-atkins commented Oct 13, 2018

What does this PR do?

Improvements in .ci/lint

  • Change the output extension from .xml to .log (plain text) so Jenkins sends the correct mime type to browsers.
  • Remove the colour escape codes from the logs, so Artifact does not contain them, but the console output record by Jenkins does.
  • Store an Artifact of which files have changed, and also the files which have been deleted, for debugging/verifying the files that have been reviewed by pylint.
    *Remove the need to use find to scan the file system and call git multiple times. (small decrease in overhead)
    *Only run a stage if required.

What issues does this PR fix or reference?

Some general improvements.

@damon-atkins
Copy link
Contributor Author

damon-atkins commented Oct 13, 2018

Best I could do is a syntax check to check if it will work.

Testing which needs to be performed:

  • Not sure how readFile() handles line feeds, have left out \\n or $ in the regex due to this.
  • General testing like create/alter a python file.

Another option is consider, is testing if people have submitted new code with .PY or .pY or .Py extension, as the original code would skip these files. (not that many people would use anything other than .py)

@damon-atkins damon-atkins changed the title [WIP] CI Improvement CI Lint Improvements Oct 13, 2018
@gtmanfred gtmanfred requested a review from KaiSforza October 14, 2018 00:21
@cachedout cachedout requested a review from dubb-b October 16, 2018 09:30
.ci/lint Outdated
@@ -22,6 +22,10 @@ pipeline {
stage('setup') {
steps {
sh '''
git diff --name-status "origin/$CHANGE_TARGET" "origin/$BRANCH_NAME" > file-list-status.log
git diff --name-only '--diff-filter=ACMRTUXB' "origin/$CHANGE_TARGET" "origin/$BRANCH_NAME" > file-list-changed.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should just be --diff-filter=d so we don't get deleted files.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line below should cover that correct? He is doing 2 logs 1 for status, 1 for changes, and one for deleted files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should, but I would prefer using the not-operator so if anything changes, we'll be fine.

.ci/lint Outdated
else
tox -e pylint-salt ${_FILES} | tee pylint-report.xml
fi
egrep -i '^salt/.*\\.py$|^setup\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' tox -e pylint-salt | tee pylint-report-salt.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use grep -E.

.ci/lint Outdated
else
tox -e pylint-tests ${_FILES} | tee pylint-report-tests.xml
fi
egrep -i '^tests/.*\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' tox -e pylint-tests | tee pylint-report-tests.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep -E again

@KaiSforza
Copy link
Contributor

Also, if we can squash some of the commits that would be great. (the ones where you just fix syntax, squash those)

@dubb-b
Copy link

dubb-b commented Oct 16, 2018

@damon-atkins I like having all three log files archived. We could patch the server to allow/send the correct mime type. https://issues.jenkins-ci.org/browse/JENKINS-3803

What I would like to see here before we merge is some better testing ran against it.

@KaiSforza Can you please test this out on a few PR's by doing a replay or setting up some sort of test?

@KaiSforza
Copy link
Contributor

Yep I'll get on it

@damon-atkins
Copy link
Contributor Author

Change the names to *.log as this is configured https://github.com/jenkinsci/jenkins/blob/master/war/src/main/webapp/WEB-INF/web.xml#L225

The file contents are not xml.

@damon-atkins
Copy link
Contributor Author

Should be right now. I am not a trusted user in Jenkins so its still running the old ci/lint.

@damon-atkins damon-atkins changed the title CI Lint Improvements Jenkins CI Lint Improvements Oct 17, 2018
.ci/lint Outdated
else
tox -e pylint-salt ${_FILES} | tee pylint-report.xml
fi
egrep -Ei '^salt/.*\\.py$|^setup\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' tox -e pylint-salt | tee pylint-report-salt.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not egrep -E, just grep -E.

.ci/lint Outdated
else
tox -e pylint-tests ${_FILES} | tee pylint-report-tests.xml
fi
egrep -Ei '^tests/.*\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' tox -e pylint-tests | tee pylint-report-tests.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

.ci/lint Outdated Show resolved Hide resolved
@KaiSforza
Copy link
Contributor

I'd love these to be squashed down to one or two commits, honestly.

.ci/lint Outdated
egrep -i '^salt/.*\\.py$|^setup\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' tox -e pylint-salt | tee pylint-report-salt.log
egrep -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay explain to me what this is actually needed for? the colors are automatically removed when pylint is piped to something, unless something is getting through.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save the current xml version and you will see them. I suspect PY_COLOR forces it. And is done so, so the console out put looks nice in Jenkins

.ci/lint Outdated
else
tox -e pylint-salt ${_FILES} | tee pylint-report.xml
fi
egrep -E '^salt/.*\\.py$|^setup\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' tox -e pylint-salt | tee pylint-report-salt.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're still doing egrep here, please remove that first e, it should be just grep -E.

.ci/lint Outdated
else
tox -e pylint-tests ${_FILES} | tee pylint-report-tests.xml
fi
egrep -E '^tests/.*\\.py$' file-list-changed.log | xargs -r '--delimiter=\\n' tox -e pylint-tests | tee pylint-report-tests.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@damon-atkins
Copy link
Contributor Author

damon-atkins commented Oct 18, 2018

FYI egrep is more common use than grep -E as not all platforms support grep -E i.e. Non-Linux/Non-GNU grep, but 99% of platforms support egrep which is the same as grep -E. So when writing portable code egrep is a better choice.

@damon-atkins
Copy link
Contributor Author

All updates ask for completed.

@damon-atkins
Copy link
Contributor Author

Current Open Pull Requests against 2017.7 are

  • 50128 Aug 19 Workaround for py2 builtin, =<3.3 imp and >=3.4 libimport quirks (Has Passed Lint Test)
  • 46713 Mar 27 Don't refresh modules twice per sync or refresh ops
  • 45839 Feb 2 Don't call close on singletons

So if this was merged into 2017.7 and issues occurred it would be manageable.

@dubb-b
Copy link

dubb-b commented Oct 19, 2018

@damon-atkins I ran this against a few PR's

I didn't dive too much into the reasoning. But there seems to be some discrepancies.

https://jenkinsci.saltstack.com/view/Pull%20Requests/job/pr-lint/view/change-requests/job/PR-50124/

Notice #5 and #6

5 is a replay with the new suggested changes and 6 is the old linting pipeline code. I don't have time to dig in at the moment, although it may give you an idea as to what's wrong.

@damon-atkins
Copy link
Contributor Author

I will have a look at then when clause, should be able to emulate it in any jenkins server, see why its not returning true.

…iff to find files, instead of find, report on status, changed and deleted files, lint only changed files.
@damon-atkins
Copy link
Contributor Author

@dubb-b that should do the job.

@damon-atkins
Copy link
Contributor Author

Go Go Jenkins!

@dubb-b
Copy link

dubb-b commented Oct 22, 2018

@damon-atkins I ran it against this: https://jenkinsci.saltstack.com/view/Pull%20Requests/job/pr-lint/view/change-requests/job/PR-50152/2/

Build #1 was successful and not it fails. Looking through the logs, it seems to have found 3 warnings. Can you validate that is what you'd expect. It looks right to me.

@damon-atkins
Copy link
Contributor Author

Looks Good.

@damon-atkins
Copy link
Contributor Author

damon-atkins commented Oct 22, 2018

So with all the recent changes to lint, the next step is only allow the other tests when the lint succeeds. This will reduce the testing load as per the example in #50026 (comment) However "Go Go Jenkins!" should override this (if possible)

@dubb-b
Copy link

dubb-b commented Oct 22, 2018

That is definitely on the roadmap. Not sure as to when we will get it in. But thanks for the work here. Much appreciated.

Copy link

@dubb-b dubb-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tested this on a number of PR's and it looks to be stable and working as it should.

@gtmanfred gtmanfred merged commit 622bb51 into saltstack:2017.7 Oct 22, 2018
@damon-atkins damon-atkins deleted the jenkins_pylint branch October 22, 2018 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants