Skip to content

Add a small test project to run codechecker_bazel on #8

Add a small test project to run codechecker_bazel on

Add a small test project to run codechecker_bazel on #8

Workflow file for this run

name: codechecker-bazel-tests
# Triggers the workflow on push or pull request events.
on: [push, pull_request]
permissions: read-all
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
rules_test:
name: Analysis
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/env_setup
- name: Print versions
run: |
bazel version
CodeChecker version
echo "[NOTE]: If you are debugging, its possible that " \
"CodeChecker finds different analyzers when running in " \
"bazel's sandbox environment!"
CodeChecker analyzers
# Prepares matrix used to generate jobs in project_test_runner
# This job assumes that every project patch file is in the .github/workflows/patches directory
# and the name of these scripts follows this rule: patch-project_name.sh
# patches must clone their repository into folder: test-proj
prepare_project_matrix:
runs-on: ubuntu-24.04
name: Collecting Projects
outputs:
project_configurations: ${{ steps.generate_matrix.outputs.matrix_json }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate dynamic project matrix
id: generate_matrix
run: |
PATCH_DIR="./test/foss/"
TEMP_JSON_FILE=$(mktemp)
find "$PATCH_DIR" -maxdepth 1 -mindepth 1 -type d ! -name "templates" -print0 | while IFS= read -r -d $'\0' PROJECT_FOLDER; do
# Extract project name from folder name
PROJECT_NAME=$(basename "$PROJECT_FOLDER")
jq -n -c \
--arg name "$PROJECT_NAME" \
--arg folder "$PROJECT_FOLDER" \
'{ name: $name, folder: $folder }' >> "$TEMP_JSON_FILE"
echo "Added $PROJECT_NAME to matrix."
done
if [ -s "$TEMP_JSON_FILE" ]; then
FINAL_MATRIX_JSON="[$(paste -s -d ',' "$TEMP_JSON_FILE")]"
else
FINAL_MATRIX_JSON="[]"
fi
echo "Generated matrix: $FINAL_MATRIX_JSON"
echo "matrix_json=$FINAL_MATRIX_JSON" >> "$GITHUB_OUTPUT"
shell: bash
project_test_runner:
# Test the bazel rules introduced by repository on an independent open-source projects.
runs-on: ubuntu-24.04
needs: prepare_project_matrix
strategy:
fail-fast: false
max-parallel: 2 # limit number of concurrent jobs
matrix:
project: ${{ fromJson(needs.prepare_project_matrix.outputs.project_configurations) }}
name: "Test On Project: ${{ matrix.project.name }}"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/env_setup
- name: Initializing test
run: |
cd ${{ matrix.project.folder }}
sh ./init.sh
# Running bazel with test will signal failure because CodeChecker found problems
- name: Run Monolithic Bazel CodeChecker
run: |
cd ${{ matrix.project.folder }}/test-proj
bazel test :codechecker_test || [ $? -eq 3 ] && exit 0 || exit $?
# Running bazel with test will signal failure because CodeChecker found problems
- name: Run Per File Bazel CodeChecker
run: |
cd ${{ matrix.project.folder }}/test-proj
bazel test :code_checker_test || [ $? -eq 3 ] && exit 0 || exit $?