Clang Tidy and Format #10
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Clang Tidy and Format | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- '**/*.cc' | |
- '**/*.h' | |
pull_request: | |
paths: | |
- '**/*.cc' | |
- '**/*.h' | |
workflow_dispatch: # allow manual triggering | |
concurrency: | |
group: clang-${{ github.head_ref || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
process-files: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v2 | |
- name: Build Docker Image | |
run: docker build -t clang-tidy-format-image --build-arg ENABLE_COMP_DB_REFRESH=false -f .devcontainer/Dockerfile . | |
- name: Determine base branch | |
id: determine-base | |
run: | | |
# If it's a pull request, compare against the base branch. | |
# If it's a push to main, compare against the previous commit. | |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
echo "BASE_BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV | |
else | |
echo "BASE_BRANCH=$(git rev-parse HEAD~1)" >> $GITHUB_ENV | |
fi | |
- name: Build Comp Database | |
id: build-comp-db | |
run: | | |
echo "Building CompDB" | |
docker run --rm \ | |
-v "$(pwd):/workspace" \ | |
--user "$(id -u):$(id -g)" \ | |
clang-tidy-format-image \ | |
bazel run @hedron_compile_commands//:refresh_all | |
- name: Find and process modified files | |
run: | | |
echo "Finding modified or added .cc and .h files..." | |
MODIFIED_FILES=$(git diff --name-only --diff-filter=AM $BASE_BRANCH | grep -E '\.(cc|h)$' || echo "") | |
if [[ -z "$MODIFIED_FILES" ]]; then | |
echo "No .cc or .h files modified." | |
exit 0 | |
fi | |
echo "Processing the following files:" | |
echo "$MODIFIED_FILES" | |
for FILE in $MODIFIED_FILES; do | |
echo "Running script on $FILE" | |
docker run --rm \ | |
-v "$(pwd):/workspace" \ | |
--user "$(id -u):$(id -g)" \ | |
clang-tidy-format-image \ | |
bash -c "clang-tidy --quiet -p compile_commands.json "$FILE" 2>&1 | tail -n +3 && ci/check_clang_format.sh "$FILE"" | |
done | |
- name: Ensure script execution success | |
run: echo "Workflow completed successfully." |