From ae2ceb6514fa4b33f608b15f84dfdbcc6fd0fab9 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Wed, 3 Sep 2025 13:14:46 +0200 Subject: [PATCH 01/11] Add foss project discovery --- .github/workflows/foss.yaml | 83 +++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 9 deletions(-) diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index 55481f39..547a35b1 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -24,10 +24,53 @@ concurrency: cancel-in-progress: true jobs: - # TODO: Parallelize the running of projects + # 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 + + # TODO: Add script to run tests locally foss_ubuntu_test: - name: "Test rules on FOSS projects (ubuntu)" + name: "Test rules on FOSS project: ${{ matrix.project.name }}" 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) }} steps: - name: Checkout repository @@ -36,14 +79,28 @@ jobs: - name: Setup environment uses: ./.github/platform_environment_setup/ubuntu - - name: Run Test On Opensource Projects - working-directory: test - run: python3 -m unittest foss/test_foss.py -vvv + - name: Setup project + working-directory: ${{ matrix.project.folder }} + run: sh init.sh + + - name: Run Bazel CodeChecker + working-directory: ${{ matrix.project.folder }}/test-proj + run: bazel build :codechecker_test + + - name: Run Per-File Bazel CodeChecker + working-directory: ${{ matrix.project.folder }}/test-proj + run: bazel build :code_checker_test foss_rhel_test: - name: "Test rules on FOSS projects (RHEL)" + name: "Test rules on FOSS project: ${{ matrix.project.name }}" runs-on: ubuntu-24.04 container: redhat/ubi9:latest + 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) }} steps: - name: Checkout repository @@ -52,6 +109,14 @@ jobs: - name: Setup environment uses: ./.github/platform_environment_setup/rhel9 - - name: Run Test On Opensource Projects - working-directory: test - run: python3 -m unittest foss/test_foss.py -vvv + - name: Setup project + working-directory: ${{ matrix.project.folder }} + run: sh init.sh + + - name: Run Bazel CodeChecker + working-directory: ${{ matrix.project.folder }}/test-proj + run: bazel build :codechecker_test + + - name: Run Per-File Bazel CodeChecker + working-directory: ${{ matrix.project.folder }}/test-proj + run: bazel build :code_checker_test From f08b3524fbc9c4be851c5822dfc5d58425fc342a Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Wed, 3 Sep 2025 13:33:41 +0200 Subject: [PATCH 02/11] Update comment in foss.yaml --- .github/workflows/foss.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index 547a35b1..c07b3191 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -24,9 +24,9 @@ concurrency: cancel-in-progress: true jobs: - # 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 + # Prepares matrix used to generate jobs in foss_{$platform}_test + # This job assumes that every project initializer script is + # in `test/foss/project` and script name must be `init.sh` # patches must clone their repository into folder: test-proj prepare_project_matrix: runs-on: ubuntu-24.04 From 60a9a0b2ca18ea6d3eca0c0d8db0a6c92f989395 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Wed, 3 Sep 2025 13:34:01 +0200 Subject: [PATCH 03/11] Move project collector script to separate file --- .github/foss_project_collector.sh | 24 ++++++++++++++++++++++++ .github/workflows/foss.yaml | 22 +++------------------- 2 files changed, 27 insertions(+), 19 deletions(-) create mode 100755 .github/foss_project_collector.sh diff --git a/.github/foss_project_collector.sh b/.github/foss_project_collector.sh new file mode 100755 index 00000000..5d87758f --- /dev/null +++ b/.github/foss_project_collector.sh @@ -0,0 +1,24 @@ +#!/bin/env bash + +if [ -z "$PATCH_DIR" ]; then + # PATCH_DIR not set + exit 1 +fi + +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" +done +if [ -s "$TEMP_JSON_FILE" ]; then +FINAL_MATRIX_JSON="[$(paste -s -d ',' "$TEMP_JSON_FILE")]" +else +FINAL_MATRIX_JSON="[]" +fi +echo "matrix_json=$FINAL_MATRIX_JSON" diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index c07b3191..dee0f9b1 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -39,26 +39,10 @@ jobs: - name: Generate dynamic project matrix id: generate_matrix + env: + PATCH_DIR: "./test/foss/" 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" + ./.github/foss_project_collector.sh >> "$GITHUB_OUTPUT" shell: bash # TODO: Add script to run tests locally From d79e9e2c9e5ae4b7c76d5c73aa77ca443db61c6b Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Wed, 3 Sep 2025 14:56:52 +0200 Subject: [PATCH 04/11] Add license --- .github/foss_project_collector.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/foss_project_collector.sh b/.github/foss_project_collector.sh index 5d87758f..063d108e 100755 --- a/.github/foss_project_collector.sh +++ b/.github/foss_project_collector.sh @@ -1,5 +1,20 @@ #!/bin/env bash +# Copyright 2023 Ericsson AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + if [ -z "$PATCH_DIR" ]; then # PATCH_DIR not set exit 1 From f7d21ee42dd931eb91bad7ac9bc4985765bd84db Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 4 Sep 2025 13:31:51 +0200 Subject: [PATCH 05/11] Rename PROJECT_DIR variable --- .github/foss_project_collector.sh | 6 +++--- .github/workflows/foss.yaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/foss_project_collector.sh b/.github/foss_project_collector.sh index 063d108e..91eb7f76 100755 --- a/.github/foss_project_collector.sh +++ b/.github/foss_project_collector.sh @@ -15,13 +15,13 @@ # limitations under the License. -if [ -z "$PATCH_DIR" ]; then - # PATCH_DIR not set +if [ -z "$PROJECTS_DIR" ]; then + # PROJECTS_DIR not set exit 1 fi TEMP_JSON_FILE=$(mktemp) -find "$PATCH_DIR" -maxdepth 1 -mindepth 1 -type d ! -name \ +find "$PROJECTS_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 diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index dee0f9b1..b53acde2 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -40,7 +40,7 @@ jobs: - name: Generate dynamic project matrix id: generate_matrix env: - PATCH_DIR: "./test/foss/" + PROJECTS_DIR: "./test/foss/" run: | ./.github/foss_project_collector.sh >> "$GITHUB_OUTPUT" shell: bash From 6701bf203a689e2c55a1e2405479f7b042413b7f Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 4 Sep 2025 13:33:22 +0200 Subject: [PATCH 06/11] Add ERROR for not setting the PROJECTS_DIR variable --- .github/foss_project_collector.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/foss_project_collector.sh b/.github/foss_project_collector.sh index 91eb7f76..33b76bc4 100755 --- a/.github/foss_project_collector.sh +++ b/.github/foss_project_collector.sh @@ -17,6 +17,7 @@ if [ -z "$PROJECTS_DIR" ]; then # PROJECTS_DIR not set + echo "[ERROR] PROJECTS_DIR not set!" 1>&2 exit 1 fi From 766e4b3945031e0e70a55ae98660e9b19681bc76 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 4 Sep 2025 13:35:58 +0200 Subject: [PATCH 07/11] Link github documentation --- .github/workflows/foss.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index b53acde2..005b9ff4 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -25,6 +25,8 @@ concurrency: jobs: # Prepares matrix used to generate jobs in foss_{$platform}_test + # This is a best-practice solution detailed in: + # https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/run-job-variations # This job assumes that every project initializer script is # in `test/foss/project` and script name must be `init.sh` # patches must clone their repository into folder: test-proj From 657cb60639045bf8fba024122464cb3bc5ff9add Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Thu, 4 Sep 2025 13:43:42 +0200 Subject: [PATCH 08/11] Use python script instead of bash script --- .github/foss_project_collector.py | 49 +++++++++++++++++++++++++++++++ .github/foss_project_collector.sh | 40 ------------------------- .github/workflows/foss.yaml | 2 +- 3 files changed, 50 insertions(+), 41 deletions(-) create mode 100644 .github/foss_project_collector.py delete mode 100755 .github/foss_project_collector.sh diff --git a/.github/foss_project_collector.py b/.github/foss_project_collector.py new file mode 100644 index 00000000..3a819fcb --- /dev/null +++ b/.github/foss_project_collector.py @@ -0,0 +1,49 @@ +# Copyright 2023 Ericsson AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import json +import sys +import glob + + +IGNORED_FOLDER_LIST = [ + "templates", + "__pycache__", + ".pytest_cache", +] + +def main(): + projects_dir = os.getenv("PROJECTS_DIR") + if not projects_dir: + print("[ERROR] PROJECTS_DIR not set!", file=sys.stderr) + sys.exit(1) + + project_list = [] + + for project_folder in glob.glob(os.path.join(projects_dir, "*/")): + project_name = os.path.basename(os.path.normpath(project_folder)) + + if project_name not in IGNORED_FOLDER_LIST: + project_list.append( + {"name": project_name, "folder": project_folder} + ) + + final_matrix_json = json.dumps(project_list) + + print(f"matrix_json={final_matrix_json}") + + +if __name__ == "__main__": + main() diff --git a/.github/foss_project_collector.sh b/.github/foss_project_collector.sh deleted file mode 100755 index 33b76bc4..00000000 --- a/.github/foss_project_collector.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/env bash - -# Copyright 2023 Ericsson AB -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -if [ -z "$PROJECTS_DIR" ]; then - # PROJECTS_DIR not set - echo "[ERROR] PROJECTS_DIR not set!" 1>&2 - exit 1 -fi - -TEMP_JSON_FILE=$(mktemp) -find "$PROJECTS_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" -done -if [ -s "$TEMP_JSON_FILE" ]; then -FINAL_MATRIX_JSON="[$(paste -s -d ',' "$TEMP_JSON_FILE")]" -else -FINAL_MATRIX_JSON="[]" -fi -echo "matrix_json=$FINAL_MATRIX_JSON" diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index 005b9ff4..245765a7 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -44,7 +44,7 @@ jobs: env: PROJECTS_DIR: "./test/foss/" run: | - ./.github/foss_project_collector.sh >> "$GITHUB_OUTPUT" + python3 ./.github/foss_project_collector.py >> "$GITHUB_OUTPUT" shell: bash # TODO: Add script to run tests locally From 5a70700258ac4139bae7424fbe94b4e84b81f760 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Sep 2025 15:49:25 +0200 Subject: [PATCH 09/11] Add platform tags --- .github/workflows/foss.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index 245765a7..2e461a7d 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -49,7 +49,7 @@ jobs: # TODO: Add script to run tests locally foss_ubuntu_test: - name: "Test rules on FOSS project: ${{ matrix.project.name }}" + name: "Test rules on FOSS project: ${{ matrix.project.name }} (Ubuntu)" runs-on: ubuntu-24.04 needs: prepare_project_matrix strategy: @@ -78,7 +78,7 @@ jobs: run: bazel build :code_checker_test foss_rhel_test: - name: "Test rules on FOSS project: ${{ matrix.project.name }}" + name: "Test rules on FOSS project: ${{ matrix.project.name }} (RHEL)" runs-on: ubuntu-24.04 container: redhat/ubi9:latest needs: prepare_project_matrix From 06cda1e8d2927840c60d83e95b648069d207808b Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 7 Oct 2025 12:36:59 +0200 Subject: [PATCH 10/11] Remove todo, this functionality have been added long ago --- .github/workflows/foss.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index 2e461a7d..9da57feb 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -47,7 +47,6 @@ jobs: python3 ./.github/foss_project_collector.py >> "$GITHUB_OUTPUT" shell: bash - # TODO: Add script to run tests locally foss_ubuntu_test: name: "Test rules on FOSS project: ${{ matrix.project.name }} (Ubuntu)" runs-on: ubuntu-24.04 From f3394b6a39ab0a1aa66b805b2b35979a553a9d8f Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 7 Oct 2025 12:38:47 +0200 Subject: [PATCH 11/11] Fix build invocation --- .github/workflows/foss.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml index 9da57feb..442df830 100644 --- a/.github/workflows/foss.yaml +++ b/.github/workflows/foss.yaml @@ -74,7 +74,7 @@ jobs: - name: Run Per-File Bazel CodeChecker working-directory: ${{ matrix.project.folder }}/test-proj - run: bazel build :code_checker_test + run: bazel build :per_file_test foss_rhel_test: name: "Test rules on FOSS project: ${{ matrix.project.name }} (RHEL)" @@ -104,4 +104,4 @@ jobs: - name: Run Per-File Bazel CodeChecker working-directory: ${{ matrix.project.folder }}/test-proj - run: bazel build :code_checker_test + run: bazel build :per_file_test