Skip to content

Commit

Permalink
github: extract test.yaml into a resusable workflow
Browse files Browse the repository at this point in the history
github's matrix machinery does not allow us to attach extra elements to
an existing matrix, for instance, we cannot add the combination of
`{compiler: clang-18, standard: 23, mode: release, enables: dpdk}` to a
matrix of `{compiler: [clang-18, gcc-13], mode: [debug, release], standard: [20, 23]}`,
without overwriting the combination of
`{compiler: clang-18, standard: 23, mode: release}` generated by the
matrix above. as the combination with "enables: dpdk" matches with
it.

to address this issue, we use the approach that we were using
when defining the circleci workflow: to define a parameterized workflow,
so that we can customize the behavior of the caller workflow
using either a matrix or a hardwired combination.

this change just extract the reuseable workflow out, and call it
in the parent workflow. we will replace the unrolled `inputs`
list with 3 different jobs, with which we will have

- 12 combinations generated with the matrix
- 1 combination for dpdk build
- 1 combination for C++20 build

instead of:

- 10 combinations
- 1 combination for dpdk build
- 1 combination for C++20 build

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed May 17, 2024
1 parent a7fb8ff commit 3dd4336
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 50 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Test

permissions:
contents: read

on:
workflow_call:
inputs:
compiler:
# only the compilers supported by setup-cpp can be used
description: 'the C++ compiler to use'
type: string
required: true
standard:
description: 'the C++ standard to use'
type: number
required: true
mode:
description: 'build mode (debug, dev or release)'
type: string
required: true
enables:
description: 'the --enable-* option passed to configure.py'
type: string
default: ''
required: false
options:
description: 'additional options passed to configure.py'
type: string
default: ''
required: false

jobs:
test:
name: "Tests (${{ matrix.compiler }}, C++${{ matrix.standard}}, ${{ matrix.mode }}, ${{ matrix.enables }})"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: "${{ contains(matrix.enables, 'dpdk') }}"

- name: Install build dependencies
run: |
sudo ./install-dependencies.sh
- name: Install ${{ matrix.compiler }}
uses: aminya/setup-cpp@master
with:
compiler: ${{ matrix.compiler }}
ccache: true
# ubuntu:latest comes with CMake 3.29, so we just need to install
# ninja. see
# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#tools
ninja: "${{ contains(matrix.enables, 'cxx-modules') }}"

- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: ${{ matrix.compiler }}-${{ matrix.standard }}-${{ matrix.mode }}-${{ matrix.enables }}

- name: Configure
run: >
./configure.py
--ccache
--c++-standard ${{ matrix.standard }}
--compiler $CXX
--c-compiler $CC
--mode ${{ matrix.mode }}
${{ matrix.options }}
${{ matrix.enables }} ;
- name: Build
run: cmake --build build/${{matrix.mode}}

- name: Check Header
if: ${{ matrix.mode == 'dev' && matrix.compiler == 'clang++-18' }}
run: cmake --build build/${{ matrix.mode }} --target checkheaders

- name: Build with C++20 modules
if: ${{ contains(matrix.enables, 'cxx-modules') }}
run: cmake --build build/${{ matrix.mode }} --target hello_cxx_module

- name: Test
if: ${{ ! contains(matrix.enables, 'cxx-modules') }}
run: ./test.py --mode=${{ matrix.mode }}
57 changes: 7 additions & 50 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
jobs:
test:
name: "Tests (${{ matrix.compiler }}, C++${{ matrix.standard}}, ${{ matrix.mode }}, ${{ matrix.enables }})"
runs-on: ubuntu-latest
uses: ./.github/workflows/test.yaml
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -66,52 +66,9 @@ jobs:
standard: 23
mode: debug
enables: --enable-cxx-modules
steps:
- uses: actions/checkout@v4
with:
submodules: "${{ contains(matrix.enables, 'dpdk') }}"

- name: Install build dependencies
run: |
sudo ./install-dependencies.sh
- name: Install ${{ matrix.compiler }}
uses: aminya/setup-cpp@master
with:
compiler: ${{ matrix.compiler }}
ccache: true
# ubuntu:latest comes with CMake 3.29, so we just need to install
# ninja. see
# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#tools
ninja: "${{ contains(matrix.enables, 'cxx-modules') }}"

- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: ${{ matrix.compiler }}-${{ matrix.standard }}-${{ matrix.mode }}-${{ matrix.enables }}

- name: Configure
run: >
./configure.py
--ccache
--c++-standard ${{ matrix.standard }}
--compiler $CXX
--c-compiler $CC
--mode ${{ matrix.mode }}
${{ matrix.options }}
${{ matrix.enables }} ;
- name: Build
run: cmake --build build/${{matrix.mode}}

- name: Check Header
if: ${{ matrix.mode == 'dev' && matrix.compiler == 'clang++-18' }}
run: cmake --build build/${{ matrix.mode }} --target checkheaders

- name: Build with C++20 modules
if: ${{ contains(matrix.enables, 'cxx-modules') }}
run: cmake --build build/${{ matrix.mode }} --target hello_cxx_module

- name: Test
if: ${{ ! contains(matrix.enables, 'cxx-modules') }}
run: ./test.py --mode=${{ matrix.mode }}
with:
compiler: ${{ matrix.compiler }}
standard: ${{ matrix.standard }}
mode: ${{ matrix.mode }}
enables: ${{ matrix.enables }}
options: ${{ matrix.options }}

0 comments on commit 3dd4336

Please sign in to comment.