-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
50 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,80 @@ | ||
name: clang_tidy_format | ||
name: Clang Tidy and Format | ||
|
||
on: | ||
pull_request: # This triggers the workflow for pull requests | ||
push: | ||
branches: | ||
- main # Run tests for pull requests targeting the "main" branch | ||
- main | ||
paths: | ||
- 'src/**' | ||
- 'testing/**' | ||
- 'vmsdk/src/**' | ||
- 'vmsdk/testing/**' | ||
|
||
push: | ||
branches: | ||
- main # Optional: Run tests for direct pushes to "main" | ||
pull_request: | ||
paths: | ||
- 'src/**' | ||
- 'testing/**' | ||
- 'vmsdk/src/**' | ||
- 'vmsdk/testing/**' | ||
|
||
workflow_dispatch: # allow manual triggering | ||
|
||
concurrency: | ||
group: codeql-${{ github.head_ref || github.ref }} | ||
group: clang-${{ github.head_ref || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
bazel-tests: | ||
process-files: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checkout the code from the repository | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
# Set up Docker to build and run the container | ||
- name: Set up Docker | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
# Build the Docker image from the Dockerfile in your repo | ||
- name: Build Docker Image | ||
run: docker build -t clang-tidy-format-image -f .devcontainer/Dockerfile . | ||
|
||
- name: Run clang-tidy/format | ||
run: | | ||
git fetch origin main | ||
docker run --rm -v "$(pwd):/workspace" --user "$(id -u):$(id -g)" clang-tidy-format-image bash -c "bazel build //... && ci/check_changes.sh origin/main" | ||
- 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.ref }}" != "refs/heads/main" ]]; 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 \ | ||
bash -c "bazel build //... && 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." |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,42 @@ | ||
#!/bin/bash | ||
set -e | ||
bazel run @hedron_compile_commands//:refresh_all | ||
set +e | ||
#bazel run @hedron_compile_commands//:refresh_all | ||
|
||
git_args="" | ||
for arg in "$@"; do | ||
git_args+=" \"$arg\"" | ||
done | ||
# Get the list of modified or new files | ||
files=$(eval "git diff --name-only --diff-filter=AM $git_args"| grep -E '\.cc$|\.h$') | ||
files=$(eval "git diff --name-only --diff-filter=AM $git_args"| grep -E '\.cc$|\.h$' || echo "") | ||
|
||
# Check if there are any files to process | ||
if [ -z "$files" ]; then | ||
exit 0 | ||
fi | ||
|
||
execute_command() { | ||
local command="$1" # The command to run | ||
local output # Variable to store the command output | ||
|
||
# Run the command and capture the output | ||
output=$(eval "$command" 2>&1) | ||
|
||
# Check if the command was successful | ||
if [ $? -eq 0 ]; then | ||
# Print OK in green if the command succeeded | ||
echo -e "\033[0;32mOK\033[0m" | ||
else | ||
# Print Error in red and the command output if it failed | ||
echo -e "\033[0;31mError\033[0m" | ||
echo "$output" | ||
fi | ||
} | ||
|
||
for file in $files; do | ||
#echo "file: $file" | ||
clang-tidy --quiet -p compile_commands.json "$file" 2>&1 | tail -n +3 | ||
ci/check_clang_format.sh "$file" | ||
echo "Checking $file" | ||
echo -n "clang-tidy: " | ||
execute_command "clang-tidy --quiet -p compile_commands.json $file 2>&1 | tail -n +3" | ||
echo -n "clang-format: " | ||
execute_command "ci/check_clang_format.sh $file" | ||
done | ||
|