Skip to content

Conversation

@vkucera
Copy link
Collaborator

@vkucera vkucera commented Apr 14, 2022

@TimoWilken @ktf @jgrosseo

This adds MegaLinter as a CI action to lint and format code other than C++ and CMake.

Fixes and formatting have been applied to the existing files to pass the tests, with the exception of Scripts/update_ccdb.py which requires some more than trivial fixes which I leave to the next editor.

The action is set to check only modified files with VALIDATE_ALL_CODEBASE: false.

If a PR passes the tests without errors but formatting is still required, a formatting commit is committed directly to the PR branch. This is set with APPLY_FIXES_MODE: commit. (The option to create a PR instead has some problems with GitHub tokens AFAIK.)

@vkucera vkucera marked this pull request as ready for review April 14, 2022 11:08
@vkucera vkucera requested review from a team, alibuild, iarsene, jgrosseo, ktf and pbuehler as code owners April 14, 2022 11:08
@vkucera vkucera requested a review from TimoWilken April 14, 2022 11:08
@davidrohr
Copy link
Contributor

I don't really like committing to peoples branches directly. I'd investigate the option to create a PR instead, and otherwise just drop it.

@vkucera
Copy link
Collaborator Author

vkucera commented Apr 14, 2022

I don't really like committing to peoples branches directly. I'd investigate the option to create a PR instead, and otherwise just drop it.

Hi @davidrohr , the advantage is that the PR author does not need to care about reading instructions on how to run formatting tools or to approve a PR in their fork repo. What disadvantage do you see there?

@davidrohr
Copy link
Contributor

I don't like to concept of pushing in other people's repository. Then I'll just mark my PRs as not editable by maintainers...

@davidrohr
Copy link
Contributor

Also, this adds a commit on top, which should normally be squashed, but the automatic commit cannot squash properly if the PR consists of multiple commits, and also this would require a force push to the user's repository, which I also think we should not do.

@vkucera
Copy link
Collaborator Author

vkucera commented Apr 14, 2022

Also, this adds a commit on top, which should normally be squashed, but the automatic commit cannot squash properly if the PR consists of multiple commits, and also this would require a force push to the user's repository, which I also think we should not do.

Squashing the automatic formatting commit with other commits in the PR works fine.

@jgrosseo
Copy link
Contributor

The clang formatter makes a PR which the user can import or not. I think this would be a good solution also here. What's speak against this solution?

@vkucera
Copy link
Collaborator Author

vkucera commented Apr 19, 2022

The clang formatter makes a PR which the user can import or not. I think this would be a good solution also here. What's speak against this solution?

Does it? I cannot find a single PR created by the formatting action.

@TimoWilken
Copy link
Contributor

TimoWilken commented Apr 19, 2022

Does it? I cannot find a single PR created by the formatting action.

These PRs are created in the PR author's fork. For example: vkucera/AliceO2#10. That is done by this code.

@vkucera
Copy link
Collaborator Author

vkucera commented Apr 19, 2022

Does it? I cannot find a single PR created by the formatting action.

These PRs are created in the PR author's fork. For example: vkucera/AliceO2#10. That is done by this code.

Thanks @TimoWilken , I am aware of this feature. My point is that I cannot find an example of it working in O2Physics.
If I look through the runs of the action where it failed, I don't see any that would create a PR in the author's branch.
For example: #650 clearly needed a formatting commit which was made and pushed by the author. The corresponding run of clang-format does not seem to have made any PR in the concerned branch though.
I only see errors of this kind:

 ! [remote rejected] HEAD -> alibot-cleanup-670 (refusing to allow a Personal Access Token to create or update workflow `.github/workflows/code-formatting.yml` without `workflow` scope)
error: failed to push some refs to 'https://github.com/alibuild/O2Physics.git'

@TimoWilken
Copy link
Contributor

Ah, right. The action had the wrong permissions -- that should be fixed now.

@vkucera
Copy link
Collaborator Author

vkucera commented Apr 19, 2022

Ah, right. The action had the wrong permissions -- that should be fixed now.

Thanks! I will try to put that in this one.

@vkucera vkucera force-pushed the megalinter branch 2 times, most recently from 7d36dcf to 6246108 Compare April 20, 2022 15:36
@vkucera vkucera marked this pull request as draft April 21, 2022 09:29
@github-actions
Copy link

This PR has not been updated in the last 30 days. Is it still needed? Unless further action is taken, it will be closed in 5 days.

@github-actions github-actions bot added the stale label May 22, 2022
@vkucera vkucera force-pushed the megalinter branch 2 times, most recently from 796e84d to b5ceac8 Compare May 22, 2022 22:41
Copy link
Contributor

@TimoWilken TimoWilken left a comment

Choose a reason for hiding this comment

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

Looks pretty good overall, though I have a few questions -- see below.

Comment on lines +76 to +82
- name: Exit with error if the PR is not clean
run: |
case "${{ steps.ml.outputs.has_updated_sources }}" in
0) echo 'PR clean' ; exit 0 ;;
1) echo 'PR not clean' ; exit 1 ;;
esac
Copy link
Contributor

Choose a reason for hiding this comment

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

How is the case handled where MegaLinter finds problems, but does not have automatic fixes for them? In that case, we still want to exit with an error, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, in case of errors, the MegaLinter step fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, the automatic PR with any fixes that MegaLinter does produce wouldn't be created, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is correct. The formatting PR should be created only if MegaLinter did not find any errors, which I think is the intended behaviour, right?

@github-actions github-actions bot closed this May 30, 2022
@vkucera vkucera reopened this May 30, 2022
Copy link
Contributor

@TimoWilken TimoWilken left a comment

Choose a reason for hiding this comment

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

Looks good to me. If the current codebase (with changes in this PR) passes MegaLinter, then let's merge and try it out!

@vkucera vkucera marked this pull request as ready for review June 2, 2022 11:42
@vkucera
Copy link
Collaborator Author

vkucera commented Jun 2, 2022

Looks good to me. If the current codebase (with changes in this PR) passes MegaLinter, then let's merge and try it out!

Thanks @TimoWilken

@jgrosseo
Copy link
Contributor

jgrosseo commented Jun 2, 2022

Looks good to me. If the current codebase (with changes in this PR) passes MegaLinter, then let's merge and try it out!

How do we check this? Let me know, I can then merge it.

@vkucera
Copy link
Collaborator Author

vkucera commented Jun 2, 2022

@TimoWilken Is the action supposed to run already on this PR itself?
The original version which was set to run on push and pull_request did run but now it is set to run on pull_request_target only.

@vkucera
Copy link
Collaborator Author

vkucera commented Jun 2, 2022

@TimoWilken Is the action supposed to run already on this PR itself? The original version which was set to run on push and pull_request did run but now it is set to run on pull_request_target only.

Otherwise, the current code passes all the tests except for a few bandit issues which should be addressed at the next modification of Scripts/update_ccdb.py .

@TimoWilken
Copy link
Contributor

Seeing as the new linter checks passed before, let's merge it and see what happens.

@TimoWilken TimoWilken merged commit 5f3eaca into AliceO2Group:master Jun 7, 2022
@vkucera vkucera deleted the megalinter branch June 7, 2022 12:30
@TimoWilken
Copy link
Contributor

FYI: I had to add one more thing (92b5340) to make the automatic cleanup PRs work. Apart from that, looks like it runs OK.

@vkucera
Copy link
Collaborator Author

vkucera commented Jun 7, 2022

FYI: I had to add one more thing (92b5340) to make the automatic cleanup PRs work. Apart from that, looks like it runs OK.

Thanks @TimoWilken . I'm glad it seems to work now.

robincaron13 pushed a commit to robincaron13/O2Physics that referenced this pull request Jun 10, 2022
* Add MegaLinter

* Fix YAML

* Fix formatting

* Add Flake8 config file

* Check only modified files

* Allow formatting commits on push events

* Integrate alisw/pull-request

* Comments by Timo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants