Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GitHub: Investigate GitHub Actions for clang-format and validate #521

@StephanTLavavej

Description

@StephanTLavavej

We currently use Azure Pipelines to check whether PRs follow our clang-format and other conventions:

- 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'

"%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

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    infrastructureRelated to repository automationwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions