-
Notifications
You must be signed in to change notification settings - Fork 279
Fix the Ormolu auto-format GH workflow step #5641
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
Conversation
The previous step (which collects the names of changed files) was missing its `id`, so the Ormolu step couldn’t retrieve the list of changed files. This commit also introduces some mis-formattings in the files modified by unisonweb#5640 to test those changes and this re-enabling of the workflow.
These two are still necessary, but overlooked because CI wasn’t actually running Ormolu.
c0e26a2
to
1a5c9ed
Compare
Previously, only the last file ended up getting formatted, because the filenames ended up joined on a single line.
The Ormolu job apparently doesn’t work on forks or protected branches[^1], so have it do `check` instead of `inplace` in those cases. [^1]: I’m a bit confused by this, because when I put up an earlier version of the PR, it _did_ create a commit (which only formatted one of the files), but then I couldn’t get it to do the same on subsequent pushes.
943ddef
to
23dc00e
Compare
Oh, thanks. I was subconsciously wondering about this. |
if: | | ||
always() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember why this was here, but we may discover a reason later. It probably belongs somewhere else if anywhere,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I couldn’t figure out why it would be useful to run this step if an earlier one failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a theory on this. I think always()
was being used as a formatting guide, like using
true
&& command1
&& command2
rather than
command1
&& command2
Can we detect when a |
I don't think automatic commits trigger another run unfortunately. Am I wrong? Although it's okay as long as we're careful to check which tests ran before merging a PR |
I don’t know what kind of introspection we have.
No, you’re right – I always forget that. I feel like having this job run on push is maybe just the wrong thing. Doing either |
I'm good with trying any/all of that — is there anything I should do or just sit tight? |
This allows auto-committed formatting to only run on pull-requests, not all pushes.
This is also run by ./scripts/check.sh.
This shows the shortcomings of the previous push-based workflow. In bee1f7a, the push-based run was triggered, but it only ran on the files that were updated by the single merge commit prior to the automatic run. It didn’t affect files that were changed by other commits in the PR (like Stack.hs, which is updated here and caused the pull-request based check to fail).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I did a few of the things
- there is now ./scripts/check-formatting, which will run Ormolu over the entire repo (and can either check or format)
- ./scripts/check.sh now runs
check-formatting
at the end if everything else has passed - the CI job now only runs on pull-requests, avoiding the unhelpful single-commit behavior of
on: push
./scripts/check-formatting tries to be well-behaved – it won’t run an Ormolu other than the version we expect, and it won’t fail if there’s no Ormolu to run. Also, if the user has Nix, it’ll check that the script & versions.nix agree on the Ormolu version, but won’t complain if the user doesn’t have Nix.
if: | | ||
always() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a theory on this. I think always()
was being used as a formatting guide, like using
true
&& command1
&& command2
rather than
command1
&& command2
What do we think about the separate workflow idea? Run ormolu 1x/day on the whole codebase? and beyond that forget about making external contributors conform on formatting? |
I think it sounds like a good compromise. We could still run the One thing that can be annoying when making changes is when format-on-save triggers a bunch of formatting outside of the code you’ve changed, making for noisier commits. But, with once-a-day formatting, you’re still much less likely to run into it than without auto-formatting, especially with it still being done on internal PRs. Footnotes
|
Should we start with what’s here, and see how much the Ormolu job gets in the way of contributions? Or is that just not a good experience for contributors? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok let's try it!
It's not a good experience for contributors if the Ormolu job gets in the way, but since you're a contributor you can test it out for us ;-) Though you're also a committer, so that may complicate things |
Overview
The Ormolu check in CI was not working. Now it does.
Implementation notes
There were a few issues:
id
, so the Ormolu step couldn’t retrieve the list of changed files.Interesting/controversial decisions
Fixing the first two issues is pretty straightforward, but the third one isn’t.
The job can’t create a commit on either protected branches, or on a fork. So, third-party contributors & their reviewers get no feedback that their code isn’t formatted correctly. However, the job runs on both PRs and pushes. The push job actually runs on the fork itself, and thus can create the commit.
So, you push everything once, and make a PR? Bob’s your uncle – the autoformatting gets done on your push job and the PR job either silently fails to format or succeeds because the automated commit has already happened.
Except … if you push incrementally, or add additional commits after the initial push, the push job will only look at the last commit (not even the entire push), whereas the PR job always looks a the entire PR. So, the confusing situation I found myself in was that when I first put up the PR, the auto-commit happened (based on my push, not the PR), but later commits didn’t have the same effect, and the PR jobs (which are the only ones I realized were happening) just skipped the “push a commit” step.
So, the way I finally did it is to run Ormolu
inplace
and make the commit if possible, but to otherwise run Ormolucheck
and fail the job if formatting was incorrect. From that, I expect contributors to see one of these behaviors:It’s not perfect, but it at least seems better than the previous situation that would just always pass and never make any changes.
Test coverage
This PR introduces a mis-formatting to trigger the auto- formatting in order to test the workflow change. It doesn‘t actually work that way though (see the previous section), so there is a final commit that fixes the build based on the failing ormolu check in CI.
Loose ends
Hopefully there’s a better way to manage the auto-commit thing. I would think having “Allow edits and access to secrets by maintainers” on the PR would be enough to allow the auto-commit to happen on the PR in some way, and having this done on pushes is probably wrong (but doing the rest of CI on pushes is probably nice, and we don’t want to throw out the baby with the bathwater) – so maybe the ormolu job should just be in a separate workflow or something?