From daca5156e70eeef55aea66ca239e32ae580f8871 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 17 May 2024 10:12:52 +0800 Subject: [PATCH] github: extract test.yaml into a resusable workflow 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 --- .github/workflows/test.yaml | 89 ++++++++++++++++++++++++++++++++++++ .github/workflows/tests.yaml | 57 +++-------------------- 2 files changed, 96 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000000..f111721eee1 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,89 @@ +name: Test + +permissions: + contents: read + +on: + workflow_call: + inputs: + compiler: + required: true + # only the compilers supported by setup-cpp can be used + description: 'the C++ compiler to use' + type: string + standard: + required: true + description: 'the C++ standard to use' + type: number + mode: + required: true + type: choice + description: 'build mode' + options: + - debug + - dev + - release + enables: + required: false + type: string + description: 'the --enable-* option passed to configure.py' + default: '' + options: + required: false + type: string + description: 'additional options passed to configure.py' + default: '' + +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 }} diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 90748f660cc..c8e4ba4285a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -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: @@ -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 }}