Skip to content
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

Merged
merged 7 commits into from
Dec 19, 2024

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Dec 19, 2024

Pull request overview

Pull Request Author

Labels:

  • If change to an IDD file, add the label IDDChange

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@jmarrec jmarrec self-assigned this Dec 19, 2024
@jmarrec jmarrec requested a review from wenyikuang December 19, 2024 14:25
Copy link
Collaborator Author

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

Comment on lines +27 to +45
- 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
Copy link
Collaborator Author

@jmarrec jmarrec Dec 19, 2024

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

Comment on lines +54 to +71
- 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
Copy link
Collaborator Author

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

Copy link
Collaborator Author

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).

@kbenne @DavidGoldwasser @joseph-robertson

Comment on lines +151 to +156

# [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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CI did this!

@jmarrec
Copy link
Collaborator Author

jmarrec commented Dec 19, 2024

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

@jmarrec jmarrec merged commit f3ca5f7 into develop Dec 19, 2024
2 checks passed
@jmarrec jmarrec deleted the clang-format branch December 19, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CI] clang-format is tripping
1 participant