Skip to content

Commit

Permalink
additional github workflow chnages
Browse files Browse the repository at this point in the history
  • Loading branch information
yairgott committed Jan 23, 2025
1 parent 7b8d240 commit 6b84fe1
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 50 deletions.
38 changes: 23 additions & 15 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ RUN wget -O /usr/local/bin/buildifier https://github.com/bazelbuild/buildtools/r
# Add bazel/buildifier to PATH
ENV PATH="/usr/local/bin:$PATH"
RUN echo '#!/bin/bash\n\
set +e\n\
LOCKFILE="/tmp/rebuild_comp_db.lock"\n\
if [ -e "$LOCKFILE" ] && kill -0 "$(cat "$LOCKFILE")" 2>/dev/null; then\n\
set +e\n\
LOCKFILE="/tmp/rebuild_comp_db.lock"\n\
if [ -e "$LOCKFILE" ] && kill -0 "$(cat "$LOCKFILE")" 2>/dev/null; then\n\
echo "Script is already running. Exiting."\n\
exit 1\n\
fi\n\
echo $$ > "$LOCKFILE"\n\
trap "rm -f $LOCKFILE" EXIT\n\
if [ ! -d "/workspaces/valkey-search" ]; then\n\
echo "Error: Directory /workspaces/valkey-search does not exist."\n\
exit 1\n\
fi\n\
cd /workspaces/valkey-search\n\
while sleep 1; do\n\
find src testing vmsdk/src vmsdk/testing -type f \\( -iname \\*.cc -o -iname \\*.h -o -iname BUILD \\) | entr -d bazel run @hedron_compile_commands//:refresh_all &> /dev/null\n\
done' > /usr/local/bin/refresh_comp_db.sh && chmod +x /usr/local/bin/refresh_comp_db.sh
fi\n\
echo $$ > "$LOCKFILE"\n\
trap "rm -f $LOCKFILE" EXIT\n\
if [ ! -d "/workspaces/valkey-search" ]; then\n\
echo "Error: Directory /workspaces/valkey-search does not exist."\n\
exit 1\n\
fi\n\
cd /workspaces/valkey-search\n\
while sleep 1; do\n\
find src testing vmsdk/src vmsdk/testing -type f \\( -iname \\*.cc -o -iname \\*.h -o -iname BUILD \\) | entr -d bazel run @hedron_compile_commands//:refresh_all &> /dev/null\n\
done' > /usr/local/bin/refresh_comp_db.sh && chmod +x /usr/local/bin/refresh_comp_db.sh
# Set working directory
WORKDIR /workspace

Expand All @@ -79,7 +79,15 @@ USER vscode

# Add an alias for 'vi' to point to 'vim' if 'vi' doesn't exist
RUN echo 'if ! command -v vi &> /dev/null; then alias vi="vim"; fi' >> /home/vscode/.bashrc
RUN echo 'refresh_comp_db.sh &> /dev/null &' >> /home/vscode/.bashrc


ARG ENABLE_COMP_DB_REFRESH=true
ENV ENABLE_COMP_DB_REFRESH=${ENABLE_COMP_DB_REFRESH}

RUN if [ "$ENABLE_COMP_DB_REFRESH" = "true" ]; then \
echo 'refresh_comp_db.sh &> /dev/null &' >> /home/vscode/.bashrc; \
fi

# Ensure the history file exists and configure permissions
RUN touch /home/vscode/.bash_history && chmod 600 /home/vscode/.bash_history

Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"ms-vscode-remote.remote-containers",
"ms-vscode-remote.remote-ssh",
"ms-vscode-remote.remote-ssh-edit",
"ms-vscode.remote-explorer"
"ms-vscode.remote-explorer",
"ms-azuretools.vscode-docker"
]
}
},
Expand Down
88 changes: 60 additions & 28 deletions .github/workflows/clang_tidy_format.yml
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."
32 changes: 26 additions & 6 deletions ci/check_changes.sh
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

0 comments on commit 6b84fe1

Please sign in to comment.