From 017888e70861a3898acbe38e4b860d5fb5d5b90c Mon Sep 17 00:00:00 2001 From: Srinivas Vasudevan Date: Wed, 29 May 2024 16:28:25 -0700 Subject: [PATCH] Add Clang format and Continuous Integration --- .github/workflows/clang_format.yml | 22 ++++++++++++++ .github/workflows/continuous-integration.yml | 23 +++++++++++++++ .github/workflows/python-package.yml | 30 -------------------- check.sh | 2 +- cxx/tests/test_util_math.cc | 25 ---------------- 5 files changed, 46 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/clang_format.yml create mode 100644 .github/workflows/continuous-integration.yml delete mode 100644 .github/workflows/python-package.yml delete mode 100644 cxx/tests/test_util_math.cc diff --git a/.github/workflows/clang_format.yml b/.github/workflows/clang_format.yml new file mode 100644 index 0000000..78bad35 --- /dev/null +++ b/.github/workflows/clang_format.yml @@ -0,0 +1,22 @@ +name: Clang Format +on: + push: + pull_request: +jobs: + clang-format: + runs-on: ubuntu-latest + defaults: + run: + shell: bash + timeout-minutes: 1 + if: | + contains(github.event.pull_request.body, 'FORCE_TEST_ACTIONS') + steps: + - name: Checking out repository + uses: actions/checkout@v4 + - name: Install dependencies + run : | + sudo apt-get update && sudo apt-get install -yq clang clang-format + - name: Run clang-format # Use pipx to get version that apt doesn't have by default + run: clang-format --dry-run -Werror --verbose \ + $(git diff --name-only origin/main HEAD -- '*.cc' '*.hh' '*.hpp' diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..2ce92cf --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,23 @@ +# This workflow will run tests. + +name: Tests +on: + push: + pull_request: +jobs: + run_tests: + name: Run tests + runs-on: ubunut-latest + timeout-minutes: 5 + steps: + - name: Checking out repository + uses: actions/checkout@v4 + - name: Install dependencies + run : | + sudo apt-get update && sudo apt-get install -yq clang clang-format + - name: Build everything + run: | + bazel build //... + - name: Test C++ + run: | + bazel test //... diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml deleted file mode 100644 index 3c16fc2..0000000 --- a/.github/workflows/python-package.yml +++ /dev/null @@ -1,30 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Python package - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.8] - - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Test Python and C++ - run: | - python -m pip install --upgrade pip - python -m pip install . - ./check.sh diff --git a/check.sh b/check.sh index c00d795..b32ae87 100755 --- a/check.sh +++ b/check.sh @@ -17,7 +17,7 @@ root=$(cd -- "$(dirname -- "$0")" && pwd) if [ $# -eq 0 ]; then # (Default) Run tests/ ./pythenv.sh "$PYTHON" -m pytest --pyargs hirm - cd cxx && make tests + cd cxx && bazel test :all elif [ ${1} = 'coverage' ]; then # Generate coverage report. ./pythenv.sh coverage run --source=build/ -m pytest --pyargs hirm diff --git a/cxx/tests/test_util_math.cc b/cxx/tests/test_util_math.cc deleted file mode 100644 index 59a410e..0000000 --- a/cxx/tests/test_util_math.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2021 MIT Probabilistic Computing Project -// Apache License, Version 2.0, refer to LICENSE.txt - -#include -#include -#include - -#include "util_math.hh" - -int main(int argc, char **argv) { - std::vector> x {{1}, {2, 3}, {1, 10, 11}}; - - auto cartesian = product(x); - assert(cartesian.size() == 6); - assert((cartesian.at(0) == std::vector{1, 2, 1})); - assert((cartesian.at(1) == std::vector{1, 2, 10})); - assert((cartesian.at(2) == std::vector{1, 2, 11})); - assert((cartesian.at(3) == std::vector{1, 3, 1})); - assert((cartesian.at(4) == std::vector{1, 3, 10})); - assert((cartesian.at(5) == std::vector{1, 3, 11})); - - x.push_back({}); - cartesian = product(x); - assert(cartesian.size() == 0); -}