-
Notifications
You must be signed in to change notification settings - Fork 275
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
base: trunk
Are you sure you want to change the base?
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. |
# allows the `separator` to actually be a newline (see tj-actions/changed-files#2148) | ||
safe_output: false |
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.
Whoops!
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.
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? |
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?