-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
We currently use Azure Pipelines to check whether PRs follow our clang-format and other conventions:
STL/azure-devops/run_build.yml
Lines 52 to 67 in fffbd8f
| - task: BatchScript@1 | |
| displayName: 'Enforce clang-format' | |
| timeoutInMinutes: 60 | |
| condition: eq('${{ parameters.targetPlatform }}', 'x64') | |
| inputs: | |
| filename: 'azure-devops/enforce-clang-format.cmd' | |
| failOnStandardError: true | |
| arguments: '$(Build.ArtifactStagingDirectory)/tools/parallelize/parallelize.exe' | |
| - task: BatchScript@1 | |
| displayName: 'Validate Files' | |
| timeoutInMinutes: 2 | |
| condition: eq('${{ parameters.targetPlatform }}', 'x64') | |
| inputs: | |
| filename: 'azure-devops/validate-files.cmd' | |
| failOnStandardError: true | |
| arguments: '$(Build.ArtifactStagingDirectory)/tools/validate/validate.exe' |
STL/azure-devops/enforce-clang-format.cmd
Lines 3 to 12 in fffbd8f
| "%1" "clang-format.exe -style=file -i" ^ | |
| stl/inc ^ | |
| stl/src ^ | |
| tests ^ | |
| tools | |
| @echo If your build fails here, you need to format the following files with: | |
| @clang-format.exe --version | |
| @git status --porcelain stl tests tools 1>&2 | |
| @echo clang-format will produce the following diff: | |
| @git diff stl tests tools 1>&2 |
STL/tools/validate/validate.cpp
Lines 140 to 146 in fffbd8f
| if (has_utf8_bom) { | |
| fwprintf(stderr, L"Validation failed: %s contains UTF-8 BOM characters.\n", filepath.c_str()); | |
| } | |
| if (tab_policy == TabPolicy::Forbidden && tab_characters != 0) { | |
| fwprintf(stderr, L"Validation failed: %s contains %zu tab characters.\n", filepath.c_str(), tab_characters); | |
| } |
This is extremely useful, but suboptimal. The user experience is somewhat non-intuitive for new contributors, as we perform these checks within the x64 build. (Edit: #682 improved this, running Code Format Validation separately.) While their error messages are informative, they're hidden behind a Details link. Additionally, our clang-format enforcement complains about problems, but doesn't fix them - the user has to install and run clang-format themselves, or manually edit their files until clang-format is happy.
It appears that GitHub Actions could provide a better experience. They can post "check notices" on specific lines of PRs, and they can push changes to branches. They can also be triggered by comments. So, we could automatically push clang-format changes, and post check notices for validate.cpp failures (as those are less amenable to automatic fixing).
Originally suggested by @barcharcraz: #509 (comment)