-
Notifications
You must be signed in to change notification settings - Fork 194
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
Fix #5330 - Clang format: run for entire codebase on push to develop and commit autocorrects #5331
Conversation
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.
Moved .clang-format and .clang-tidy from src/ to root, because we have code in ruby/
and python/
now
- name: Run clang-format for entire codebase | ||
if: ${{ github.event_name == 'push' }} | ||
shell: bash | ||
run: | | ||
clang-format --version | ||
find . \( -name "*.hpp" -o -name "*.h" -o -name "*.hh" -o -name "*.cc" -o -name "*.cpp" -o -name "*.c" \) | xargs -P $(nproc) -I '{}' clang-format -style=file -i -fallback-style=none "{}" | ||
# clang-format will auto correct files so prepare the diff and use this as artifact | ||
git diff > clang_format.patch | ||
|
||
# Delete if nothing otherwise exit 1 to indicate a failed job | ||
if [ ! -s clang_format.patch ]; then | ||
rm clang_format.patch | ||
exit 0 | ||
else | ||
echo "clang-format auto corrected files:" | ||
git diff --name-only | ||
echo -e "\nPlease correct these files. You can run ci/clang-format.sh locally and commit changes" | ||
exit 1 | ||
fi |
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.
When push to develop/master, it runs for the entire codebase, which takes 1 min. total. See https://github.com/NREL/OpenStudio/actions/runs/12414354976/job/34658277864
- name: Commit Auto-corrections | ||
shell: bash | ||
if: ${{ always() && github.event_name == 'push' }} | ||
run: | | ||
git add -u | ||
if [[ $(git diff --cached --exit-code) ]]; then | ||
echo "Commiting Lint Autocorrects" | ||
git config --global user.email 'github-lint-actions[bot]@users.noreply.github.com' | ||
git config --global user.name 'github-lint-actions[bot]' | ||
git commit -m "[chore] Commit clang-format autocorrects" | ||
echo '' >> .git-blame-ignore-revs | ||
git log -n1 --pretty='format:# %C(auto)%s [%an, %as]%n%H%n' >> .git-blame-ignore-revs | ||
git add .git-blame-ignore-revs | ||
git commit -m "Add clang-format autocorrects to git-blame-ignore-revs" | ||
git push | ||
else | ||
echo "No Autocorrect needed" | ||
fi |
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.
It will then create two commits:
- The [chore] one, that has the clang format
- An extra commit that adds the previous one to to .git-blame-ignore-revs so it's excluded from blaming on github and most IDEs
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.
Note: I enabled the autocorrect (pushing clang-format changes to github directly) feature ONLY for push to develop/master.
My idea was that on a feature branch, I would most likely want to git fixup
the commit that I failed to format properly and force push so we don't pollute the commit history for no reason (and anyone who ever had to git bisect
in the past would probably be appreciative).
|
||
# [chore] Commit clang-format autocorrects [github-lint-actions[bot], 2024-12-19] | ||
b3d2e94e3ae1160f447af2035a1ffabaec4b3423 | ||
|
||
# [chore] Commit clang-format autocorrects [github-lint-actions[bot], 2024-12-19] | ||
77309e0db461ce64a0cca1e1a0f2bbda29ff7a66 |
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.
CI did this!
I'm going to let this one fly as it's bothering me to see false positives on PRs, but we should still decide whether we agree with the way I set up autocorrect/push only for develop branch |
Pull request overview
Pull Request Author
Labels:
IDDChange
Review Checklist
This will not be exhaustively relevant to every PR.