-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
github/workflows/format-comment: init #121379
Conversation
There should probably also be a second workflow that checks if the changes in every commit are properly formatted. I'm willing to build this, but don't have time today. |
Hmm, I wasn't expecting that we'd end up with another I'm planning to rewrite the rebase action to use repo dispatch via another action. This would allow us to drop the boilerplate and have more reliable commands. (would also cut down on GHA CI usage as the currently each command would run it's own CI job for a few seconds on every comment) It would be much easier to only need to rewrite and test one action rather than two but I'm not going to have time to deal with it at least for a couple of weeks. |
It won't run automatically after the |
Originally I wanted to add an action that pushes a format commit if it isn't properly formatted, but this seemed like the less intrusive option. I'm still open to suggestions for other approaches tho!
This shouldn't alter the semantics, so if we trust nixpkgs-fmt enough that wouldn't be necessary. Whether we do is something that's above my pay grade.
Oh hmm, I assumed the
Give me a ping when you do, I'll see if I can rewrite this based on that. |
I wonder if this goes a step too far. If there's a CI build failure, then whoever submitted the PR should deal with fixing the issue. Maintainers can then simply ignore PRs with a ❎, rather than being tasked with fixing errors on behalf of someone else - it's not like they aren't overloaded with work anyway ;) |
I marked this as stale due to inactivity. → More info |
git show $CURRENT_BASE..$PR_BRANCH --name-status \ | ||
| egrep ^[AM] | grep .nix | cut -f2 \ | ||
| sort | uniq > /tmp/changed_files |
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.
This one should have less false-positive:
git show $CURRENT_BASE..$PR_BRANCH --name-status \ | |
| egrep ^[AM] | grep .nix | cut -f2 \ | |
| sort | uniq > /tmp/changed_files | |
git show $CURRENT_BASE..$PR_BRANCH --name-status \ | |
| awk '/^(M|A)\t.*\.nix$/ { print $2 }' | sort -u \ | |
> /tmp/changed_files |
| sort | uniq > /tmp/changed_files | ||
|
||
# https://serverfault.com/questions/609886/shell-command-to-filter-out-non-existing-files-in-a-pipe | ||
FILTER_SCRIPT="cat /tmp/changed_files | perl -ne 'chomp(); if (-e \$_) {print \"\$_\\n\"}' | xargs -d '\n' -- nixpkgs-fmt" |
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.
null-terminated handling is slightly more robust here:
FILTER_SCRIPT="cat /tmp/changed_files | perl -ne 'chomp(); if (-e \$_) {print \"\$_\\n\"}' | xargs -d '\n' -- nixpkgs-fmt" | |
FILTER_SCRIPT="perl -ne 'chomp; print \"\$_\\0\" if (-e \$_)' < /tmp/changed_files | xargs -0 nixpkgs-fmt" |
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.
on the other hands we already use perl to read in newline separated files...
I think this should also use |
I marked this as stale due to inactivity. → More info |
I don't think we need this anymore with the full tree formatted soon and nixfmt ci checks in place. Closing, feel free to re-open, if you disagree. |
Motivation for this change
Workflow to format the changes made in a PR when someone with write access
comments
/format
. Uses git-filter-tree to not insert any unneeded commitsbut rather rewrite such that all commits appear as if they've always been
properly formatted. Based on the
/rebase
workflow.Can be seen in action here: Synthetica9/nixpkgs-format-testbed#13
Related: #120832 #121306
cc @domenkozar