diff --git a/.github/workflows/foss.yaml b/.github/workflows/foss.yaml new file mode 100644 index 00000000..3a9c0e3f --- /dev/null +++ b/.github/workflows/foss.yaml @@ -0,0 +1,80 @@ +# 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. + +name: codechecker-bazel-foss-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: + # TODO: Generalize to handle multiple projects + # TODO: Add script to run tests locally + foss_ubuntu_test: + name: "Test rules on FOSS project: yaml-cpp" + runs-on: ubuntu-24.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup environment + uses: ./.github/platform_environment_setup/ubuntu + + - name: Setup yaml-cpp + run: | + cd test/foss/yaml-cpp + sh init.sh + + - name: Run Bazel CodeChecker + run: | + cd test/foss/yaml-cpp/test-proj + bazel build :codechecker_test + + - name: Run Per-File Bazel CodeChecker + run: | + cd test/foss/yaml-cpp/test-proj + bazel build :code_checker_test + + foss_rhel_test: + name: "Test rules on FOSS project: yaml-cpp" + runs-on: ubuntu-24.04 + container: redhat/ubi9:latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup environment + uses: ./.github/platform_environment_setup/rhel9 + + - name: Setup yaml-cpp + run: | + cd test/foss/yaml-cpp + sh init.sh + + - name: Run Bazel CodeChecker + run: | + cd test/foss/yaml-cpp/test-proj + bazel build :codechecker_test + + - name: Run Per-File Bazel CodeChecker + run: | + cd test/foss/yaml-cpp/test-proj + bazel build :code_checker_test diff --git a/.github/workflows/unit_test.yaml b/.github/workflows/unit_test.yaml index ecc3eea9..f1208e50 100644 --- a/.github/workflows/unit_test.yaml +++ b/.github/workflows/unit_test.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: codechecker-bazel-tests +name: codechecker-bazel-unit-tests # Triggers the workflow on push or pull request events. on: [push, pull_request] diff --git a/test/README.md b/test/README.md index f5092dd2..79c96424 100644 --- a/test/README.md +++ b/test/README.md @@ -67,3 +67,19 @@ python3 -m unittest discover unit/my_test_dir -vvv > ``` **For a test template look into unit/template** + +## Testing on open source projects + +## Add a new open source project: + +1. Create a folder in the foss folder with the name of the project. +2. The folder should contain: + - init.sh + +3. The init.sh script should: + - Clone the test project into a folder named `test-proj`. + - To ensure the project doesn't change over time, check out a specific tag or commit instead of a branch! + - Copy the .bazelversion file from the templates directory into the test-proj directory. + - Append the WORKSPACE.template file to the WORKSPACE file of the project. + - Append the codechecker rules to the BUILD file of the project. + - There can be only two targets, codechecker_test and code_checker_test diff --git a/test/foss/templates/.bazelversion b/test/foss/templates/.bazelversion new file mode 100644 index 00000000..f22d756d --- /dev/null +++ b/test/foss/templates/.bazelversion @@ -0,0 +1 @@ +6.5.0 diff --git a/test/foss/templates/WORKSPACE.template b/test/foss/templates/WORKSPACE.template new file mode 100644 index 00000000..6b73e87f --- /dev/null +++ b/test/foss/templates/WORKSPACE.template @@ -0,0 +1,20 @@ +#---------------------------------------------------- + +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +local_repository( + name = "bazel_codechecker", + path = "../../../../", +) + +load( + "@bazel_codechecker//src:tools.bzl", + "register_default_codechecker", + "register_default_python_toolchain", +) + +register_default_python_toolchain() + +register_default_codechecker() + +#---------------------------------------------------- diff --git a/test/foss/yaml-cpp/init.sh b/test/foss/yaml-cpp/init.sh new file mode 100755 index 00000000..f86d5160 --- /dev/null +++ b/test/foss/yaml-cpp/init.sh @@ -0,0 +1,57 @@ +#!/bin/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. + +git clone --recurse https://github.com/jbeder/yaml-cpp.git test-proj +cd test-proj +git checkout yaml-cpp-0.7.0 + +# This file must be in the root of the project to be analyzed for bazelisk to work +cp ../../templates/.bazelversion ./.bazelversion + +# Add codechecker to the project +cat <> BUILD.bazel +#------------------------------------------------------- + +# codechecker rules +load( + "@bazel_codechecker//src:codechecker.bzl", + "codechecker_test", +) +load( + "@bazel_codechecker//src:code_checker.bzl", + "code_checker_test", +) + + +codechecker_test( + name = "codechecker_test", + targets = [ + ":yaml-cpp", + ], +) + +code_checker_test( + name = "code_checker_test", + targets = [ + ":yaml-cpp", + ], +) + +#------------------------------------------------------- +EOF + +# Add codechecker_bazel repo to WORKSPACE +cat ../../templates/WORKSPACE.template >> WORKSPACE