{"id":21034647,"url":"https://github.com/lpenz/ghaction-cmake","last_synced_at":"2025-05-15T13:32:58.689Z","repository":{"id":37099513,"uuid":"208466660","full_name":"lpenz/ghaction-cmake","owner":"lpenz","description":"cmake swiss army knife github docker action","archived":false,"fork":false,"pushed_at":"2025-02-27T22:06:48.000Z","size":79,"stargazers_count":22,"open_issues_count":8,"forks_count":13,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-18T14:53:24.930Z","etag":null,"topics":["clang-sanitizers","clang-tidy","cmake","coverage","cppcheck","docker","github-actions","github-actions-docker","iwyu","lint","valgrind"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lpenz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-14T16:12:44.000Z","updated_at":"2025-02-26T22:59:45.000Z","dependencies_parsed_at":"2024-06-21T13:13:12.012Z","dependency_job_id":"254d6f45-269b-4b0a-b4a3-1c552fe5de34","html_url":"https://github.com/lpenz/ghaction-cmake","commit_stats":{"total_commits":68,"total_committers":3,"mean_commits":"22.666666666666668","dds":0.07352941176470584,"last_synced_commit":"51f463a9d5856e96c730d443e412da8fbea469fa"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpenz%2Fghaction-cmake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpenz%2Fghaction-cmake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpenz%2Fghaction-cmake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpenz%2Fghaction-cmake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lpenz","download_url":"https://codeload.github.com/lpenz/ghaction-cmake/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254349638,"owners_count":22056387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clang-sanitizers","clang-tidy","cmake","coverage","cppcheck","docker","github-actions","github-actions-docker","iwyu","lint","valgrind"],"created_at":"2024-11-19T13:07:51.462Z","updated_at":"2025-05-15T13:32:58.677Z","avatar_url":"https://github.com/lpenz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![marketplace](https://img.shields.io/badge/marketplace-cmake--swiss--army--knife-blue?logo=github)](https://github.com/marketplace/actions/cmake-swiss-army-knife)\n[![CI](https://github.com/lpenz/ghaction-cmake/actions/workflows/ci.yml/badge.svg)](https://github.com/lpenz/ghaction-cmake/actions/workflows/ci.yml)\n[![github](https://img.shields.io/github/v/release/lpenz/ghaction-cmake?include_prereleases\u0026label=release\u0026logo=github)](https://github.com/lpenz/ghaction-cmake/releases)\n[![docker](https://img.shields.io/docker/v/lpenz/ghaction-cmake?label=release\u0026logo=docker\u0026sort=semver)](https://hub.docker.com/repository/docker/lpenz/ghaction-cmake)\n\n\n# ghaction-cmake\n\n**ghaction-cmake** is a github action for projects that\nuse [cmake](https://cmake.org/). By default, it builds, tests and\ninstalls the project - but it can as easily run linters, tests with\ncoverage, valgrind or sanitizers, by using [presets](#preset).\n\n\n## Phases\n\n*ghaction-cmake* runs in phases:\n- *setup*: optionally install dependencies and go to a specified\n  directory.\n- *cmake*: run cmake in an empty directory, pointing to the source\n  directory, with all other arguments appended. This guarantees that\n  out-of-tree builds work.\n- *build*: customizable, `make VERBOSE=1` by default (build commands are shown).\n- *test*: customizable, `ctest --output-on-failure .` by default.\n- *post*: customizable, empty by default.\n\n\n## Inputs\n\n### `preset`\n\nSet a preset, more information on the [Presets](#presets) section below.\n\n- Phase: can changes the default command of any number of phases.\n\n### `working-directory`\n\nUse this directory as the source dir for cmake. Mostly used when the\ncmake project is in a subdirectory of the repository.\n\n- Phase: *setup*\n- Preset behavior: unaffected.\n\n### `pre_command`\n\nCustom command to run before dependencies are installed. Use this to\nadd third-party Debian repositories or increment the setup phase in\nother ways.\n\n- Phase: *setup*\n- Preset behavior: unaffected.\n\n### `dependencies_debian`\n\nProject dependencies as Debian packages to install in the container,\nseparated by spaces.\n\n- Phase: *setup*\n- Preset behavior: unaffected.\n\n### `cmakeflags`\n\nFlags for cmake. `-DSOME_OPTION=On`, for instance, to pass an option\nto CMakeLists.txt.\n\n- Phase: *cmake*\n- Preset behavior: most presets append to this input.\n\n### `build_command`\n\nCustom test command. Defaults to `make VERBOSE=1`.\n\n- Phase: *build*\n- Preset behavior: some presets change or remove the default build\n  command.\n\n### `test_command`\n\nCustom test command. Defaults to `ctest --output-on-failure .` if no preset is used.\n\n- Phase: *test*\n- Preset behavior: some presets change or remove the default test\n  command.\n\n### `post_command`\n\nCustom command to run after tests. Empty by default, if no preset is used.\n\n- Phase: *post*\n- Preset behavior: some presets add a default post command.\n\n## \u003ca name=\"presets\"\u003e\u003c/a\u003e Presets\n\n`cmake` is a very versatile tool that can do a lot of different things given\nthe appropriate arguments. To make matrix builds easier, *ghaction-cmake*\nprovides **presets** that configure those options for specific modes.\n\nThe available presets are:\n- *cppcheck*: run [cppcheck](http://cppcheck.sourceforge.net/) static\n  analysis.\n  - *cmake*: append `-DCMAKE_C/CXX_CPPCHECK=cppcheck` to `cmakeflags`.\n  - *test*: clear default.\n- *iwyu*: run\n  [include-what-you-use](https://include-what-you-use.org/) static\n  analysis.\n  - *cmake*: append `-DCMAKE_C/CXX_INCLUDE_WHAT_YOU_USE=iwyu` to `cmakeflags`.\n  - *test*: clear default.\n- *install*: test installation.\n  - *cmake*: append `'-DCMAKE_INSTALL_PREFIX'` to `cmakeflags`.\n  - *test*: use `make install` as a test.\n  - *post*: use `find` to show all installed files.\n- *clang-tidy*: run\n  [clang-tidy](https://clang.llvm.org/extra/clang-tidy/) static\n  analysis.\n  - *cmake*: append `-DCMAKE_C/CXX_CLANG_TIDY=clang-tidy` to `cmakeflags`.\n  - *test*: clear default.\n- *clang-sanitize-\u0026lt;sanitizer\u0026gt;*: compile with one of the\n  [clang sanitizers](https://clang.llvm.org/docs/index.html) and\n  run the tests.\n  - *cmake*: append `-DCMAKE_C/CXX_COMPILER=clang/clang++ -DCMAKE_C/CXX_FLAGS=-fno-omit-frame-pointer -fsanitize=\u003csanitizer\u003e` to `cmakeflags`.\n- *gcc-sanitize-\u0026lt;sanitizer\u0026gt;*: compile with one of the\n  [gcc sanitizers](https://devdocs.io/gcc~10/instrumentation-options) and\n  run the tests.\n  - *cmake*: append `-DCMAKE_C/CXX_COMPILER=gcc/g++ -DCMAKE_C/CXX_FLAGS=-fno-omit-frame-pointer -fsanitize=\u003csanitizer\u003e` to `cmakeflags`.\n- *valgrind*: run the tests with [valgrind](https://valgrind.org/).\n  - *test*: set default test phase to `ctest -DExperimentalMemCheck --output-on-failure .`\n- *cpack*: runs [cpack](https://cmake.org/cmake/help/latest/module/CPack.html)\n  after the build.\n  - *test*: cpack\n- *coverage*: runs the tests with coverage.\n  - *cmake*: append `-DCMAKE_C/CXX_FLAGS=--coverage` to `cmakeflags`\n  - *post*: set default post phase to run\n    [lcov](http://ltp.sourceforge.net/coverage/lcov.php) with\n    `lcov -c -d . -o lcov.info`\n\n  This preset works well with github actions that upload coverage data\n  results to online services like\n  [codecov](https://github.com/marketplace/actions/codecov) and\n  [coveralls](https://github.com/marketplace/actions/coveralls-github-action).\n  The [example](#example) below shows how that can be done.\n\n\nThe table below summarizes the changes specific to each preset:\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003ePreset\u003c/th\u003e\n\u003cth\u003ecmake\u003c/th\u003e\n\u003cth\u003etest\u003c/th\u003e\n\u003cth\u003epost\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003ecppcheck\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003e-DCMAKE_C/CXX_CPPCHECK=cppcheck\u003c/pre\u003e\u003c/td\u003e\n\u003ctd\u003e(delete)\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eiwyu\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003e-DCMAKE_C/CXX_INCLUDE_WHAT_YOU_USE=iwyu\u003c/pre\u003e\u003c/td\u003e\n\u003ctd\u003e(delete)\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003einstall\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003e-DCMAKE_INSTALL_PREFIX=/tmp/_install\u003c/pre\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003emake install\u003c/pre\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003efind /tmp_install -type f\u003c/pre\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eclang\u0026#8209;tidy\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003e-DCMAKE_C/CXX_CLANG_TIDY=clang-tidy\u003c/pre\u003e\u003c/td\u003e\n\u003ctd\u003e(delete)\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eclang\u0026#8209;sanitize\u0026#8209;\u0026lt;sanitizer\u0026gt;\u003c/td\u003e\n\u003ctd\u003e\n\u003cpre\u003e-DCMAKE_C/CXX_COMPILER=clang/clang++\n-DCMAKE_C/CXX_FLAGS=-fno-omit-frame-pointer -fsanitize=\u0026lt;sanitizer\u0026gt;\u003c/pre\u003e\n\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003evalgrind\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003e-DExperimentalMemCheck\u003c/pre\u003e\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003ecpack\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003ecpack\u003c/pre\u003e\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003ecoverage\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003e-DCMAKE_C/CXX_FLAGS=--coverage\u003c/pre\u003e\u003c/td\u003e\n\u003ctd\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cpre\u003elcov -c -d . -o lcov.info\u003c/pre\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nKeep in mind that presets override the defaults, and are overriden by\nthe other more specific inputs `build_command`, `test_command` and\n`post_command`.\n\n\n## \u003ca name=\"example\"\u003e\u003c/a\u003e Example:\n\nThe workflow below shows how to use presets in a matrix job:\n\n```yml\n---\nname: CI\non: [push, pull_request]\njobs:\n  # Regular C build with two compilers, using the environment:\n  build_using_compiler_in_environment:\n    strategy:\n        matrix:\n          compiler:\n            - [gcc, g++]\n            - [clang, clang++]\n    runs-on: ubuntu-latest\n    # We can use cmakeflags for this, or we can just use\n    # regular environment variables, as they are already\n    # supported by github actions:\n    env:\n      - CC: ${{ matrix.compiler[0] }}\n      - CXX: ${{ matrix.compiler[1] }}\n    steps:\n      - uses: actions/checkout@v2\n      - uses: docker://lpenz/ghaction-cmake:0.21.2\n  # Regular C build with two compilers, using cmakeflags:\n  build_using_compiler_in_cmakeflags:\n    strategy:\n        matrix:\n          compiler:\n            - gcc\n            - clang\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      # This examples uses the appropriate cmakeflags\n      - uses: docker://lpenz/ghaction-cmake:0.21.2\n        with:\n          cmakeflags: ${{ format('-DCMAKE_C_COMPILER={0}', matrix.compiler) }}\n  # Coverage with codecov:\n  codecov:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: docker://lpenz/ghaction-cmake:0.21.2\n        with:\n          preset: coverage\n      # ghaction-cmake works well with the github action\n      # provided by codecov:\n      - uses: codecov/codecov-action@v1\n        with:\n          fail_ci_if_error: true\n  # Coverage with coveralls:\n  coveralls:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: docker://lpenz/ghaction-cmake:0.21.2\n        with:\n          preset: coverage\n      # ghaction-cmake works well with the github action\n      # provided by coveralls if you pass path-to-lcov:\n      - uses: coverallsapp/github-action@master\n        with:\n          github-token: ${{ secrets.GITHUB_TOKEN }}\n          path-to-lcov: lcov.info\n  # Static analyzers:\n  linters:\n    strategy:\n        matrix:\n          preset: [ cppcheck, iwyu, clang-tidy ]\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: docker://lpenz/ghaction-cmake:0.21.2\n        with:\n          preset: ${{ matrix.preset }}\n  # Tests with various sanitizers and valgrind:\n  test:\n    strategy:\n        matrix:\n          preset:\n            - clang-sanitize-address\n            - clang-sanitize-memory\n            - clang-sanitize-undefined\n            - clang-sanitize-dataflow\n            - clang-sanitize-safe-stack\n            - valgrind\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: docker://lpenz/ghaction-cmake:0.21.2\n        with:\n          preset: ${{ matrix.preset }}\n  # Test installation:\n  install:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: docker://lpenz/ghaction-cmake:0.21.2\n        with:\n          preset: install\n  # Create the .deb in Ubuntu Jammy:\n  install:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: docker://lpenz/ghaction-cmake:0.21.2-ubuntu-jammy-amd64\n        with:\n          preset: cpack\n```\n\nNote that the file above splits static analyzers from sanitizers, but\nthey can actually be in the same matrix job, as the rest of the\nparameters is the same.\n\n\n## Using in other environments\n\nThis github action is actually a docker image that can be used locally\nor even in [travis-ci](https://travis-ci.com). To do that, first\ndownload the image from\n[docker hub](https://hub.docker.com/r/lpenz/ghaction-cmake):\n\n```sh\ndocker pull lpenz/ghaction-cmake:0.16\n```\n\nThen, run a container in the project's directory, for instance:\n\n```sh\ndocker run --rm -t -u \"$UID\" -w \"$PWD\" -v \"${PWD}:${PWD}\" -e INPUT_PRESET=valgrind lpenz/ghaction-cmake:0.16\n```\n\nIt's worth pointing out that action parameters are passed as\nupper case environment variables, prefixed with `INPUT_`.\n\nThe following `.travis.yml` runs the same thing in travis-ci:\n\n```yml\n---\nlanguage: generic\njobs:\n  include:\n    - install: docker pull lpenz/ghaction-cmake:0.16\n    - script: docker run --rm -t -u \"$UID\" -w \"$PWD\" -v \"${PWD}:${PWD}\" -e INPUT_PRESET=valgrind lpenz/ghaction-cmake:0.16\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpenz%2Fghaction-cmake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flpenz%2Fghaction-cmake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpenz%2Fghaction-cmake/lists"}