This repository includes a number of useful GitHub actions to test C libraries. Part of the difficulty to test C libraries comes from the diversity of the C++ ecosystem. Our intention is to create a common and resilient set of actions that can work on as many environments as possible.
Note
|
READ THE DOCS: https://alandefreitas.github.io/cpp-actions/ |
This action installs dependencies from multiple package managers for a workflow.
If vcpkg dependencies are required and vcpkg is not available, it will be installed. Both vcpkg and its dependencies are cached.
Example 1:
steps:
- name: Install packages
uses: alandefreitas/cpp-actions/package-install@master
id: package-install
with:
vcpkg: fmt
apt-get: g++-11
cxx: g++-11
cc: gcc-11
Example 2 (apt-get-ignore-missing
):
steps:
- name: Install packages
uses: alandefreitas/cpp-actions/package-install@master
id: package-install
with:
vcpkg: fmt
apt-get: g++-4.8 sudo software-properties-common tzdata wget curl apt-transport-https
make apt-file unzip libssl-dev build-essential autotools-dev autoconf automake
g++ libc++-helpers python ruby cpio gcc-multilib g++-multilib pkgconf python3
ccache libpython-dev python3-distutils python3-pip git cmake
apt-get-ignore-missing: 'true'
cxx: g++-4.8
cc: gcc-4.8
Parameter |
Description |
Default |
|
List of packages we should install with vcpkg. (Whitespace-separated). |
|
|
List of packages we should install with apt-get. (Whitespace-separated). |
|
|
C compiler used by vcpkg. Setting the compiler is particularly important in Linux workflows that use `clang`, since `clang` might link
`libc` or This would cause conflict in workflows that later attempt to use vcpkg dependencies. . |
|
|
C compiler used by vcpkg. |
|
|
The triplet used by vcpkg to install packages. |
|
|
The directory where vcpkg should be cloned and installed. |
|
|
vcpkg branch we should use. |
|
|
Number of times we should retry when apt-get fails. |
|
|
List of sources for apt-get. |
|
|
List of source keys for apt-get. |
|
|
Whether apt-get should ignore missing packages. |
|
This action runs a complete CMake workflow from source files. A workflow is composed of the following steps:
-
Configure
-
Build
-
Test
-
Install
The action also sets up the environment for the workflow:
-
It validates the CMake version installed in the system,
-
Updates CMake if the library has a different minimum version,
-
Identifies what features the current CMake version supports, and
-
Runs a complete cmake workflow
The action will adjusts the parameters as needed according to the features that CMake version supports. For instance,
-
If the CMake version does not support the
-S … -B …
syntax, the action will create the build directory and run the configuration step from there. -
If the specified or default generator is multi-config,
CMAKE_CONFIGURATION_TYPES
will be used instead ofCMAKE_BUILD_TYPE
, since the later is ignored by these generators. -
If the CMake version does not support the
cmake --install
syntax, thecmake --build --target install
will be use instead. -
If the CMake version does not support multiple targets in the
cmake --build
syntax, the action will run the build step once for each target.
The action also creates GitHub annotations when warnings or errors are emitted at any of these steps. This includes annotations for CMake errors at the configure step and build errors emitted from the compiler at the build step.
Example 1:
steps:
- name: CMake Workflow
uses: alandefreitas/cpp-actions/cmake-workflow@master
with:
cmake-version: '>=3.8'
source-dir: tests
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}
run-tests: 'true'
install-prefix: $GITHUB_WORKSPACE/.local
cxxstd: 17,20
cxx: g++-11
cc: gcc-11
extra-args: -D BOOST_SRC_DIR=$GITHUB_WORKSPACE/boost-root
ref-source-dir: .
Example 2 (cmake-min-version
):
steps:
- name: CMake Workflow
uses: alandefreitas/cpp-actions/cmake-workflow@master
with:
cmake-version: '>=3.8'
cmake-min-version: '3.8'
source-dir: tests
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}
run-tests: 'true'
install-prefix: $GITHUB_WORKSPACE/.local
cxxstd: '11'
cxx: g++-4.8
cc: gcc-4.8
extra-args: -D BOOST_SRC_DIR=$GITHUB_WORKSPACE/boost-root
ref-source-dir: .
Example 3 (build-type
, generator
):
steps:
- name: CMake Workflow
uses: alandefreitas/cpp-actions/cmake-workflow@master
with:
cmake-version: '>=3.8'
source-dir: tests
generator: Unix Makefiles
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}
build-type: Debug
run-tests: 'true'
install-prefix: $GITHUB_WORKSPACE/.local
extra-args: -D BOOST_SRC_DIR=$GITHUB_WORKSPACE/boost-root
ref-source-dir: .
Example 4 (cxxflags
):
steps:
- name: CMake Workflow
uses: alandefreitas/cpp-actions/cmake-workflow@master
with:
cmake-version: '>=3.8'
source-dir: tests
toolchain: ${{ steps.package-install.outputs.vcpkg-toolchain }}
run-tests: 'true'
install-prefix: $GITHUB_WORKSPACE/.local
cxxstd: 17,20
cxx: clang++-12
cxxflags: -stdlib=libc++
cc: clang-12
extra-args: -D BOOST_SRC_DIR=$GITHUB_WORKSPACE/boost-root
ref-source-dir: .
Parameter |
Description |
Default |
|
The cmake executable. |
|
|
A semver range string with the cmake versions supported by this workflow. If the existing version in the environment does not satisfy this requirement, the action attempts to install or update CMake using cmake-min-version. If this input is undefined, the version ">= cmake-min-version" is considered. This should usually match the |
|
|
Set the minimum cmake version for this workflow when the cmake-version requirement is not satisfied. If the existing version in the environment does not satisfy this cmake-version requirement, the action attempts to install or update CMake using this cmake-min-version. If cmake-version is not set, this option overrides the If cmake-min-version is not defined, the action attempts to extract the cmake-min-version from CMakeLists.txt. If a minimum version cannot be found in CMakeLists.txt, the lastest CMake version is considered the minimum version. . |
|
|
Directory for the source files. |
|
|
Directory for the binaries relative to the source directory. |
|
|
Path to C compiler. |
|
|
Path to C++ compiler. |
|
|
List of standards with which cmake will build and test the program. |
|
|
Force flags to be used with the C++ compiler. |
|
|
Path to toolchain. |
|
|
Generator name. |
|
|
Build type. |
|
|
Targets to build instead of the default target. |
|
|
Path where the library should be installed. |
|
|
Extra arguments to cmake configure command. |
|
|
Whether we should run tests. |
|
|
Whether we should install the library. The library is only installed once in the The latest std version described in |
|
|
Create github annotations on errors. |
|
|
A reference source directory for annotations. Any annotation filename will be relative to this directory. This is typically useful when the repository being tested is not the current directory, in which we need to make annotations relative to some other directory. In most cases, the default option should be enough. . |
|
|
Trace commands executed by the workflow. |
|
This action clones the Boost source directory, attempting to get it from the cache first. Only the specified modules are cloned and cached.
Besides the explicitly specified list of modules, the action can also scan directories for boost dependencies to implicitly determine what modules should be cloned.
The union of the implicitly and explicitly specified modules is cloned. Caching is based only on these dependencies.
For a project with about 5 boost dependencies, caching saves about 4 minutes in the workflow. When there’s no cache, the scanning scripting saves us about 3 minutes.
steps:
- name: Clone Boost.Variant2
uses: alandefreitas/cpp-actions/boost-clone@master
with:
boost-dir: boost-root
branch: master
modules: variant2
Parameter |
Description |
Default |
|
The boost directory. The default value assumes boost is in-source. |
|
|
Branch of the super-project. |
|
|
Libraries used to patch the boost installation. |
|
|
The boost submodules we need to clone. |
|
|
An independent directory we should scan for boost dependencies to clone. |
|
|
List of modules that should be ignored in scan-modules. |
|
|
Trace commands executed by the workflow. |
|
This action runs a complete B2 workflow from Boost source files.
It takes the Boost source directory and does whatever it needs to test the specified modules. This includes
compiling b2
if needed and generating a proper user-config.jam
file.
This action is particularly useful for Boost library proposals.
Example 1:
steps:
- name: Test Boost.Variant2
uses: alandefreitas/cpp-actions/b2-workflow@master
with:
source-dir: boost-root
modules: variant2
toolset: gcc-11
cxxstd: 17,20
Example 2 (cxx
):
steps:
- name: Test Boost.Variant2
uses: alandefreitas/cpp-actions/b2-workflow@master
with:
source-dir: boost-root
modules: variant2
toolset: clang
cxx: clang++-12
cxxstd: 17,20
Example 3 (address-model
):
steps:
- name: Test Boost.Variant2
uses: alandefreitas/cpp-actions/b2-workflow@master
with:
source-dir: boost-root
modules: variant2
toolset: msvc-14.3
cxxstd: 17,20
address-model: 32,64
Example 4 (ubsan
):
steps:
- name: Test Boost.Variant2
uses: alandefreitas/cpp-actions/b2-workflow@master
with:
source-dir: boost-root
modules: variant2
toolset: gcc-11
cxxstd: 17,20
ubsan: 'true'
Example 5 (cxxflags
, linkflags
):
steps:
- name: Test Boost.Variant2
uses: alandefreitas/cpp-actions/b2-workflow@master
with:
source-dir: boost-root
modules: variant2
toolset: clang
cxx: clang++-12
cxxstd: 17,20
cxxflags: -stdlib=libc++
linkflags: -stdlib=libc++
Example 6 (gcc-toolchain
):
steps:
- name: Test Boost.Variant2
uses: alandefreitas/cpp-actions/b2-workflow@master
with:
source-dir: boost-root
modules: variant2
toolset: clang
cxx: clang++-8
cxxstd: '17'
gcc-toolchain: '7'
Parameter |
Description |
Default |
|
The boost source directory. |
|
|
Custom build variants. |
|
|
The list of modules we should test. |
|
|
Create a special GCC toolchain for this version of GCC and update user-config.jam. |
|
|
Toolset name. |
|
|
Valid b2 list of address models. |
|
|
Path to C++ compiler. |
|
|
Extra compiler flags. |
|
|
Extra linker flags. |
|
|
List of standards with which cmake will build and test the program. |
|
|
List of standards with which cmake will build and test the program. |
|
|
b2 threading option. |
|
|
Trace commands executed by the workflow. |
|
This action creates an initial Changelog from the commit history.
The commits considered go from the latest commit up to a commit containing a version commit pattern specified by version-pattern.
The result can be used as the initial body for an automated release, a CHANGELOG.md file, or a job summary.
Each commit is parsed as a loose variant of a conventional commit in the following format:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
-
The body and footer are always ignored.
-
If no type is indicated, the description goes to an initial "other" category in the message.
-
If no scope is indicated, the description goes to an initial "general" scope in the type messages.
-
Breaking changes are indicated.
This action uses the local commit history to generate the notes. Ensure the fetch-depth
option
is set when cloning your repository in CI. If this option is unset, the checkout action will
perform a shallow clone and the Changelog will only include the latest commit.
- uses: actions/checkout@v3
with:
fetch-depth: 100
This parameter can also be used as a limit on the number of commits the action should consider.
steps:
- name: Create release notes
uses: alandefreitas/cpp-actions/create-changelog@master
with:
output-path: CHANGELOG.md
trace-commands: 'true'
Parameter |
Description |
Default |
|
The source directory from whose commits will be analyzed . |
|
|
A regex pattern used to identify if a commit is a version delimiter . |
|
|
The path where the changelog will be stored . |
|
|
The limit on the number of commits considered in the Changelog . |
|
|
Trace commands executed by the workflow. |
|
If there’s a platform where one of the actions does not work, feel free to submit a PR with adaptations and tests.
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following:
The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.