All Projects → lpenz → ghaction-cmake

lpenz / ghaction-cmake

Licence: MIT license
cmake swiss army knife github docker action

Programming Languages

python
139335 projects - #7 most used programming language
Dockerfile
14818 projects
shell
77523 projects

Projects that are alternatives of or similar to ghaction-cmake

cmake-init
The missing CMake project initializer
Stars: ✭ 1,071 (+5536.84%)
Mutual labels:  coverage, cppcheck, clang-tidy
tarpaulin
📈 GitHub Action for code coverage reporting with tarpaulin
Stars: ✭ 69 (+263.16%)
Mutual labels:  coverage, github-actions
mylib
Шаблон кросплатформенного CMake-проекта для языка C++ 🇬🇧 Modern CMake crossplatform project template for C++
Stars: ✭ 49 (+157.89%)
Mutual labels:  coverage, github-actions
shell-linter
A Github Action for ShellCheck
Stars: ✭ 58 (+205.26%)
Mutual labels:  lint, github-actions
redis-github-action
Use Redis in GitHub Actions
Stars: ✭ 56 (+194.74%)
Mutual labels:  github-actions, github-actions-docker
latex-action
GitHub Action to compile LaTeX documents
Stars: ✭ 123 (+547.37%)
Mutual labels:  github-actions, github-actions-docker
pytest-coverage-comment
Comments a pull request with the pytest code coverage badge and full report
Stars: ✭ 32 (+68.42%)
Mutual labels:  coverage, github-actions
django-github-digitalocean
Continuously Deploying Django to DigitalOcean with Docker and GitHub Actions
Stars: ✭ 45 (+136.84%)
Mutual labels:  github-actions, github-actions-docker
chart-testing-action
A GitHub Action to lint and test Helm charts
Stars: ✭ 139 (+631.58%)
Mutual labels:  lint, github-actions
code-coverage-action
GitHub Action that generates code coverage reports
Stars: ✭ 28 (+47.37%)
Mutual labels:  coverage, github-actions
jacoco-badge-generator
Coverage badges, and pull request coverage checks, from JaCoCo reports in GitHub Actions
Stars: ✭ 53 (+178.95%)
Mutual labels:  coverage, github-actions
bake-action
GitHub Action to use Docker Buildx Bake as a high-level build command
Stars: ✭ 52 (+173.68%)
Mutual labels:  github-actions, github-actions-docker
assign-one-project-github-action
Automatically add an issue or pull request to specific GitHub Project(s) when you create and/or label them.
Stars: ✭ 140 (+636.84%)
Mutual labels:  github-actions, github-actions-docker
intellij-platform-plugin-verifier-action
GitHub Action for executing the intellij-plugin-verifier
Stars: ✭ 20 (+5.26%)
Mutual labels:  github-actions, github-actions-docker
action-ssh
GitHub Action for executing SSH commands on remote servers
Stars: ✭ 60 (+215.79%)
Mutual labels:  github-actions, github-actions-docker
jacoco-report
Github action that publishes the JaCoCo report as a comment in the Pull Request
Stars: ✭ 31 (+63.16%)
Mutual labels:  coverage, github-actions
Github-Android-Action
Android Github Action that builds Android project, runs unit tests and generates debug APK, builds for Github Actions hackathon
Stars: ✭ 29 (+52.63%)
Mutual labels:  github-actions, github-actions-docker
rubocop-linter-action
Rubocop Linter Action: A GitHub Action to run Rubocop against your code!
Stars: ✭ 86 (+352.63%)
Mutual labels:  lint, github-actions
metadata-action
GitHub Action to extract metadata (tags, labels) from Git reference and GitHub events for Docker
Stars: ✭ 492 (+2489.47%)
Mutual labels:  github-actions, github-actions-docker
codeclimate-action
GitHub Action to send your code coverage to CodeClimate
Stars: ✭ 145 (+663.16%)
Mutual labels:  coverage, github-actions

marketplace CI github docker

ghaction-cmake

ghaction-cmake is a github action for projects that use cmake. By default, it builds, tests and installs the project - but it can as easily run linters, tests with coverage, valgrind or sanitizers, by using presets.

Phases

ghaction-cmake runs in phases:

  • setup: optionally install dependencies and go to a specified directory.
  • cmake: run cmake in an empty directory, pointing to the source directory, with all other arguments appended. This guarantees that out-of-tree builds work.
  • build: customizable, make VERBOSE=1 by default (build commands are shown).
  • test: customizable, ctest --output-on-failure . by default.
  • post: customizable, empty by default.

Inputs

preset

Set a preset, more information on the Presets section below.

  • Phase: can changes the default command of any number of phases.

working-directory

Use this directory as the source dir for cmake. Mostly used when the cmake project is in a subdirectory of the repository.

  • Phase: setup
  • Preset behavior: unaffected.

pre_command

Custom command to run before dependencies are installed. Use this to add third-party Debian repositories or increment the setup phase in other ways.

  • Phase: setup
  • Preset behavior: unaffected.

dependencies_debian

Project dependencies as Debian packages to install in the container, separated by spaces.

  • Phase: setup
  • Preset behavior: unaffected.

cmakeflags

Flags for cmake. -DSOME_OPTION=On, for instance, to pass an option to CMakeLists.txt.

  • Phase: cmake
  • Preset behavior: most presets append to this input.

build_command

Custom test command. Defaults to make VERBOSE=1.

  • Phase: build
  • Preset behavior: some presets change or remove the default build command.

test_command

Custom test command. Defaults to ctest --output-on-failure . if no preset is used.

  • Phase: test
  • Preset behavior: some presets change or remove the default test command.

post_command

Custom command to run after tests. Empty by default, if no preset is used.

  • Phase: post
  • Preset behavior: some presets add a default post command.

Presets

cmake is a very versatile tool that can do a lot of different things given the appropriate arguments. To make matrix builds easier, ghaction-cmake provides presets that configure those options for specific modes.

The available presets are:

  • cppcheck: run cppcheck static analysis.

    • cmake: append -DCMAKE_C/CXX_CPPCHECK=cppcheck to cmakeflags.
    • test: clear default.
  • iwyu: run include-what-you-use static analysis.

    • cmake: append -DCMAKE_C/CXX_INCLUDE_WHAT_YOU_USE=iwyu to cmakeflags.
    • test: clear default.
  • install: test installation.

    • cmake: append '-DCMAKE_INSTALL_PREFIX' to cmakeflags.
    • test: use make install as a test.
    • post: use find to show all installed files.
  • clang-tidy: run clang-tidy static analysis.

    • cmake: append -DCMAKE_C/CXX_CLANG_TIDY=clang-tidy to cmakeflags.
    • test: clear default.
  • clang-sanitize-<sanitizer>: compile with one of the clang sanitizers and run the tests.

    • cmake: append -DCMAKE_C/CXX_COMPILER=clang/clang++ -DCMAKE_C/CXX_FLAGS=-fno-omit-frame-pointer -fsanitize=<sanitizer> to cmakeflags.
  • gcc-sanitize-<sanitizer>: compile with one of the gcc sanitizers and run the tests.

    • cmake: append -DCMAKE_C/CXX_COMPILER=gcc/g++ -DCMAKE_C/CXX_FLAGS=-fno-omit-frame-pointer -fsanitize=<sanitizer> to cmakeflags.
  • valgrind: run the tests with valgrind.

    • test: set default test phase to ctest -DExperimentalMemCheck --output-on-failure .
  • cpack: runs cpack after the build.

    • test: cpack
  • coverage: runs the tests with coverage.

    • cmake: append -DCMAKE_C/CXX_FLAGS=--coverage to cmakeflags
    • post: set default post phase to run lcov with lcov -c -d . -o lcov.info

    This preset works well with github actions that upload coverage data results to online services like codecov and coveralls. The example below shows how that can be done.

The table below summarizes the changes specific to each preset:

Preset cmake test post
cppcheck
-DCMAKE_C/CXX_CPPCHECK=cppcheck
(delete)
iwyu
-DCMAKE_C/CXX_INCLUDE_WHAT_YOU_USE=iwyu
(delete)
install
-DCMAKE_INSTALL_PREFIX=/tmp/_install
make install
find /tmp_install -type f
clang‑tidy
-DCMAKE_C/CXX_CLANG_TIDY=clang-tidy
(delete)
clang‑sanitize‑<sanitizer>
-DCMAKE_C/CXX_COMPILER=clang/clang++
-DCMAKE_C/CXX_FLAGS=-fno-omit-frame-pointer -fsanitize=<sanitizer>
valgrind
-DExperimentalMemCheck
cpack
cpack
coverage
-DCMAKE_C/CXX_FLAGS=--coverage
lcov -c -d . -o lcov.info

Keep in mind that presets override the defaults, and are overriden by the other more specific inputs build_command, test_command and post_command.

Example:

The workflow below shows how to use presets in a matrix job:

---
name: CI
on: [push, pull_request]
jobs:
  # Regular C build with two compilers, using the environment:
  build_using_compiler_in_environment:
    strategy:
        matrix:
          compiler:
            - [gcc, g++]
            - [clang, clang++]
    runs-on: ubuntu-latest
    # We can use cmakeflags for this, or we can just use
    # regular environment variables, as they are already
    # supported by github actions:
    env:
      - CC: ${{ matrix.compiler[0] }}
      - CXX: ${{ matrix.compiler[1] }}
    steps:
      - uses: actions/checkout@v2
      - uses: docker://lpenz/ghaction-cmake:0.16
  # Regular C build with two compilers, using cmakeflags:
  build_using_compiler_in_cmakeflags:
    strategy:
        matrix:
          compiler:
            - gcc
            - clang
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      # This examples uses the appropriate cmakeflags
      - uses: docker://lpenz/ghaction-cmake:0.16
        with:
          cmakeflags: ${{ format('-DCMAKE_C_COMPILER={0}', matrix.compiler) }}
  # Coverage with codecov:
  codecov:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: docker://lpenz/ghaction-cmake:0.16
        with:
          preset: coverage
      # ghaction-cmake works well with the github action
      # provided by codecov:
      - uses: codecov/codecov-action@v1
        with:
          fail_ci_if_error: true
  # Coverage with coveralls:
  coveralls:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: docker://lpenz/ghaction-cmake:0.16
        with:
          preset: coverage
      # ghaction-cmake works well with the github action
      # provided by coveralls if you pass path-to-lcov:
      - uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          path-to-lcov: lcov.info
  # Static analyzers:
  linters:
    strategy:
        matrix:
          preset: [ cppcheck, iwyu, clang-tidy ]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: docker://lpenz/ghaction-cmake:0.16
        with:
          preset: ${{ matrix.preset }}
  # Tests with various sanitizers and valgrind:
  test:
    strategy:
        matrix:
          preset:
            - clang-sanitize-address
            - clang-sanitize-memory
            - clang-sanitize-undefined
            - clang-sanitize-dataflow
            - clang-sanitize-safe-stack
            - valgrind
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: docker://lpenz/ghaction-cmake:0.16
        with:
          preset: ${{ matrix.preset }}
  # Test installation:
  install:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: docker://lpenz/ghaction-cmake:0.16
        with:
          preset: install

Note that the file above splits static analyzers from sanitizers, but they can actually be in the same matrix job, as the rest of the parameters is the same.

Using in other environments

This github action is actually a docker image that can be used locally or even in travis-ci. To do that, first download the image from docker hub:

docker pull lpenz/ghaction-cmake:0.16

Then, run a container in the project's directory, for instance:

docker run --rm -t -u "$UID" -w "$PWD" -v "${PWD}:${PWD}" -e INPUT_PRESET=valgrind lpenz/ghaction-cmake:0.16

It's worth pointing out that action parameters are passed as upper case environment variables, prefixed with INPUT_.

The following .travis.yml runs the same thing in travis-ci:

---
language: generic
jobs:
  include:
    - install: docker pull lpenz/ghaction-cmake:0.16
    - script: docker run --rm -t -u "$UID" -w "$PWD" -v "${PWD}:${PWD}" -e INPUT_PRESET=valgrind lpenz/ghaction-cmake:0.16
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].