Skip to content

Commit b2d5bab

Browse files
committed
Add local local running for foss projects
1 parent e9dde24 commit b2d5bab

6 files changed

Lines changed: 114 additions & 71 deletions

File tree

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,16 @@ jobs:
4646
- name: Generate dynamic project matrix
4747
id: generate_matrix
4848
run: |
49-
PATCH_DIR="./.github/workflows/patches/"
49+
PATCH_DIR="./test/foss/"
5050
TEMP_JSON_FILE=$(mktemp)
51-
find "$PATCH_DIR" -type f -name "*.sh" -print0 | while IFS= read -r -d $'\0' PATCH_SCRIPT_PATH; do
52-
# Extract project name from script path (e.g., "patch-yaml-cpp.sh" -> "yaml-cpp")
53-
PROJECT_NAME=$(basename "$PATCH_SCRIPT_PATH" | sed -E 's/^patch-(.*)\.sh$/\1/')
54-
55-
if [ -z $PROJECT_NAME ]; then
56-
PROJECT_NAME="UNKNOWN"
57-
fi
51+
find "$PATCH_DIR" -maxdepth 1 -mindepth 1 -type d ! -name "templates" -print0 | while IFS= read -r -d $'\0' PROJECT_FOLDER; do
52+
# Extract project name from folder name
53+
PROJECT_NAME=$(basename "$PROJECT_FOLDER")
5854
5955
jq -n -c \
6056
--arg name "$PROJECT_NAME" \
61-
--arg patch_script "$PATCH_SCRIPT_PATH" \
62-
'{ name: $name, patch_script: $patch_script }' >> "$TEMP_JSON_FILE"
57+
--arg folder "$PROJECT_FOLDER" \
58+
'{ name: $name, folder: $folder }' >> "$TEMP_JSON_FILE"
6359
6460
echo "Added $PROJECT_NAME to matrix."
6561
done
@@ -92,18 +88,18 @@ jobs:
9288
- name: Setup environment
9389
uses: ./.github/actions/env_setup
9490

95-
- name: Patching codechecker_bazel targets onto test_project
91+
- name: Initializing test
9692
run: |
97-
sh ${{ matrix.project.patch_script }} ${{ github.repository }} ${{ github.ref }}
93+
sh ${{ matrix.project.folder }}/init.sh
9894
9995
# Running bazel with test will signal failure because CodeChecker found problems
10096
- name: Run Monolithic Bazel CodeChecker
10197
run: |
102-
cd test-proj
98+
cd ${{ matrix.project.folder }}/test-proj
10399
bazel test :codechecker_test || [ $? -eq 3 ] && exit 0 || exit $?
104100
105101
# Running bazel with test will signal failure because CodeChecker found problems
106102
- name: Run Per File Bazel CodeChecker
107103
run: |
108-
cd test-proj
104+
cd ${{ matrix.project.folder }}/test-proj
109105
bazel test :code_checker_test || [ $? -eq 3 ] && exit 0 || exit $?

test/foss/templates/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.5.0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#----------------------------------------------------
2+
3+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
4+
5+
local_repository(
6+
name = "bazel_codechecker",
7+
path = "../../../../",
8+
)
9+
10+
load(
11+
"@bazel_codechecker//src:tools.bzl",
12+
"register_default_codechecker",
13+
"register_default_python_toolchain",
14+
)
15+
16+
register_default_python_toolchain()
17+
18+
register_default_codechecker()
19+
20+
#----------------------------------------------------
Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#!/bin/bash
2-
3-
FORK_REPO="$1"
4-
FORK_BRANCH="$2"
5-
62
git clone --recurse https://github.com/jbeder/yaml-cpp.git test-proj
73
cd test-proj
84
git checkout yaml-cpp-0.7.0
9-
5+
pwd
106
# This file must be in the root of the project to be analyzed for bazelisk to work
11-
cp ../.bazelversion ./.bazelversion
7+
cp ../../templates/.bazelversion ./.bazelversion
128

139
# Add codechecker to the project
1410
cat <<EOF >> BUILD.bazel
@@ -42,26 +38,5 @@ code_checker_test(
4238
#-------------------------------------------------------
4339
EOF
4440

45-
cat <<EOF >> WORKSPACE
46-
#----------------------------------------------------
47-
48-
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
49-
50-
git_repository(
51-
name = "bazel_codechecker",
52-
remote = "https://github.com/${FORK_REPO}",
53-
branch = "${FORK_BRANCH}",
54-
)
55-
56-
load(
57-
"@bazel_codechecker//src:tools.bzl",
58-
"register_default_codechecker",
59-
"register_default_python_toolchain",
60-
)
61-
62-
register_default_python_toolchain()
63-
64-
register_default_codechecker()
65-
66-
#----------------------------------------------------
67-
EOF
41+
# Add codechecker_bazel repo to WORKSPACE
42+
cat ../../templates/WORKSPACE.template >> WORKSPACE
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#!/bin/bash
2-
3-
FORK_REPO="$1"
4-
FORK_BRANCH="$2"
5-
62
git clone --recurse https://github.com/madler/zlib.git test-proj
73
cd test-proj
84
git checkout 5a82f71ed1dfc0bec044d9702463dbdf84ea3b71
95

106
# This file must be in the root of the project to be analyzed for bazelisk to work
11-
cp ../.bazelversion ./.bazelversion
7+
cp ../../templates/.bazelversion ./.bazelversion
128

139
# Add codechecker to the project
1410
cat <<EOF >> BUILD.bazel
@@ -42,26 +38,5 @@ code_checker_test(
4238
#-------------------------------------------------------
4339
EOF
4440

45-
cat <<EOF >> WORKSPACE
46-
#----------------------------------------------------
47-
48-
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
49-
50-
git_repository(
51-
name = "bazel_codechecker",
52-
remote = "https://github.com/${FORK_REPO}",
53-
branch = "${FORK_BRANCH}",
54-
)
55-
56-
load(
57-
"@bazel_codechecker//src:tools.bzl",
58-
"register_default_codechecker",
59-
"register_default_python_toolchain",
60-
)
61-
62-
register_default_python_toolchain()
63-
64-
register_default_codechecker()
65-
66-
#----------------------------------------------------
67-
EOF
41+
# Add codechecker_bazel repo to WORKSPACE
42+
cat ../../templates/WORKSPACE.template >> WORKSPACE

test/foss_test.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
FOSS_BASE_DIR="./foss"
3+
if [ ! -d "$FOSS_BASE_DIR" ]; then
4+
echo "Error: The directory '$FOSS_BASE_DIR' does not exist."
5+
exit 1
6+
fi
7+
8+
if [ "$1" == "clean" ]; then
9+
find "$FOSS_BASE_DIR" -maxdepth 2 -mindepth 2 -type d -name "test-proj" ! -path "*/templates/*" -print -exec rm -rf {} +
10+
exit $?
11+
fi
12+
13+
echo "Starting Bazel build process for projects in '$FOSS_BASE_DIR'..."
14+
echo "-----------------------------------------------------------------"
15+
find "$FOSS_BASE_DIR" -maxdepth 1 -mindepth 1 -type d | while read -r project_dir; do
16+
if ! command -v CodeChecker &> /dev/null; then
17+
echo "CodeChecker isn't available! Terminating..."
18+
echo "-----------------------------------------------------------------"
19+
exit 1
20+
fi
21+
project_name=$(basename "$project_dir")
22+
23+
if [ "$project_name" == "templates" ]; then
24+
echo "Skipping 'templates' directory: $project_dir"
25+
continue
26+
fi
27+
28+
echo ""
29+
echo "Processing project: $project_name ($project_dir)"
30+
echo "-----------------------------------------------------------------"
31+
32+
pushd "$project_dir" > /dev/null || { echo "Error: Could not change to $project_dir. Skipping."; continue; }
33+
34+
if [ ! -d "test-proj" ]; then
35+
echo " Running ./init.sh..."
36+
if [ -f "./init.sh" ]; then
37+
./init.sh > /dev/null
38+
if [ $? -ne 0 ]; then
39+
echo " Warning: ./init.sh failed for $project_name. Skipping."; popd > /dev/null; continue;
40+
fi
41+
else
42+
echo " Warning: ./init.sh not found in $project_name. Skipping."; popd > /dev/null; continue;
43+
fi
44+
else
45+
echo "test-proj already exists. Skipping init.sh for $project_name"
46+
fi
47+
48+
if [ -d "test-proj" ]; then
49+
pushd "test-proj" > /dev/null || { echo "Error: Could not change to test-proj in $project_name. Skipping."; popd > /dev/null; continue; }
50+
51+
echo " Running bazel build :codechecker_test..."
52+
bazel build :codechecker_test
53+
if [ $? -ne 0 ]; then
54+
echo " Error: 'bazel build :codechecker_test' failed for $project_name. Check logs above."
55+
fi
56+
57+
echo " Running bazel build :code_checker_test..."
58+
bazel build :code_checker_test
59+
if [ $? -ne 0 ]; then
60+
echo " Error: 'bazel build :code_checker_test' failed for $project_name. Check logs above."
61+
fi
62+
63+
popd > /dev/null
64+
else
65+
echo " Error: 'test-proj' directory not found in $project_name. Skipping Bazel builds."
66+
fi
67+
68+
popd > /dev/null
69+
70+
echo "-----------------------------------------------------------------"
71+
echo "Finished processing project: $project_name"
72+
done
73+
74+
echo ""
75+
echo "-----------------------------------------------------------------"
76+
echo "Bazel build process completed."

0 commit comments

Comments
 (0)