Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/foss.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/unit_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 16 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
Szelethus marked this conversation as resolved.
1 change: 1 addition & 0 deletions test/foss/templates/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.5.0
20 changes: 20 additions & 0 deletions test/foss/templates/WORKSPACE.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#----------------------------------------------------

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

local_repository(
name = "bazel_codechecker",
path = "../../../../",
)
Comment thread
furtib marked this conversation as resolved.

load(
"@bazel_codechecker//src:tools.bzl",
"register_default_codechecker",
"register_default_python_toolchain",
)

register_default_python_toolchain()

register_default_codechecker()

#----------------------------------------------------
57 changes: 57 additions & 0 deletions test/foss/yaml-cpp/init.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF >> 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