/action-cxx-toolkit

GitHub action providing a toolkit for building and checking C++ projects

Primary LanguagePythonMIT LicenseMIT

action-cxx-toolkit

GitHub action providing a toolkit for building and checking C++ projects. It allows build manually, with make, with cmake and conan. Then, it allows to run a series of checks: warnings, install, test, clang-format, clang-tidy, sanitize, cppcheck, iwyu, coverage

Avaiable checks

  • build -- the most basic check, that ensures that the source code builds
  • warnings -- ensures that the build process doesn't generate any warnings
  • install -- ensures that the built software can be installed
  • test -- runs tests on the built software (with ctest or make test)
  • clang-format -- ensures that the source code properly formatted (according to the rules specified in .clang-format file)
  • clang-tidy -- runs clang-tidy on the source code, and ensure that it doesn't generate warnings; supported only for cmake builds
  • sanitize=(address, memory, ...) -- runs the compilation with the sanitize flags; so that we can detect runtime errors when the tests are run
  • cppcheck -- runs cppcheck on the source code trying to detect extra errors; supported only for cmake builds
  • iwyu -- tests that the source files do not include more headers than what they should; supported only for cmake builds
  • coverage=codecov -- checks the coverage for running the tests, and tries to upload the coverage report to codecov.io; needs the codecov environment variables to be properly passed in (see https://docs.codecov.io/docs/testing-with-docker); supported only for cmake builds
  • coverage=lcov -- checks the coverage for running the tests, and makes a lcov.info report; supported only for cmake builds

Input parameters

checks

A space-separated list of checks that need to be run on the source code. See above for the list of checks available. If missing, the build and test will be implicitly added

dependencies

Ubuntu packges to install before building the software. May not be needed.

directory

The directory to start building from. If not specified, the build will be started from the repo main folder. Typically not used.

builddir

The directory containing the build artifacts. Used for CMake builds. Default is '/tmp/build'.

cc

The C compiler to use. Based on this parameter the corresponding C++ compiler is also selected.

Possible values: gcc, gcc-7, gcc-8, gcc-9, gcc-10, clang, clang-7, clang-8, clang-9, clang-10.

The default compiler is gcc (latest version).

cflags

The CFLAGS to be passed to the compilation. Typically not used.

cxxflags

The CXXFLAGS to be passed to the compilation. Typically not used.

conanflags

Extra flags to be passed to conan; used only when conan is used.

cmakeflags

Extra flags to be passed to cmake; used only when cmake build is used.

ctestflags

Extra flags to be passed to ctest; used only when cmake build is used.

makeflags

Flags to be passed when building the software; applies both to plain make projects and cmake builds.

iwyuflags

Extra flags to be passed to iwyu.

cppcheckflags

Extra flags to be passed to cppcheck.

clangtidyflags

Extra flags to be passed to clang-tidy.

clangformatdirs

The directories (relative to build dir) where to run clang-format.

prebuild_command

Command to be run before building starts. Can be useful to run any commands that prepare the compilation.

build_command

A command to build the software. If not used, then based on the content of the source code, the build system tries to use conan, cmake or make.

postbuild_command

Command to be run to after the software is built.

test_command

Command to be run to test the built software. If not used, and the build system is detected automatically, this will be generated by the build system.

Usage example

---
name: CI
on: push
jobs:
  build-gcc:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: lucteo/action-cxx-toolkit@master
        with:
          cc: gcc
          checks: build test install warnings
  build-clang:
    runs-on: ubuntu-latest
    strategy:
        matrix:
          cc: [ clang-7, clang-10 ]
    steps:
      - uses: actions/checkout@master
      - uses: lucteo/action-cxx-toolkit@master
        with:
          cc: ${{ matrix.cc }}
          conanflags: -s compiler.libcxx=libstdc++11
          checks: build test
  static-checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: lucteo/action-cxx-toolkit@master
        with:
          cc: gcc-9
          checks: cppcheck clang-tidy
          clangtidyflags: '-quiet'
          cppcheckflags: '--enable=warning,style,performance,portability --inline-suppr'
  clang-format:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: lucteo/action-cxx-toolkit@master
        with:
          checks: clang-format
          clangformatdirs: src include test
  sanitizer:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: lucteo/action-cxx-toolkit@master
        with:
          checks: sanitize=address sanitize=undefined
  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: lucteo/action-cxx-toolkit@master
        with:
          checks: coverage=codecov
        env:
          GITHUB_ACTION: ${GITHUB_ACTION}
          GITHUB_REF: ${GITHUB_REF}
          GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}
          GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}
          GITHUB_SHA: ${GITHUB_SHA}
          GITHUB_RUN_ID: ${GITHUB_RUN_ID}