Skip to content

Commit fa8e623

Browse files
scivisionViralBShah
authored andcommitted
CI test: add CMake using Yaml anchors and composite workflow
ci: avoid wasted runs. Add parallel builds to cross-builds
1 parent 9988ad0 commit fa8e623

3 files changed

Lines changed: 59 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,29 @@ jobs:
2525
- macos-latest
2626
- macos-15-intel
2727
steps:
28-
- uses: actions/checkout@v7
29-
- run: make -j$(getconf _NPROCESSORS_ONLN)
30-
- run: make test
28+
- &git-checkout
29+
name: Checkout Openlibm
30+
uses: actions/checkout@v7
31+
- &count-cpu
32+
name: Count CPU cores
33+
uses: ./.github/workflows/composite-nproc
34+
- &make-build
35+
name: Build with GNU Make
36+
run: make -j${CMAKE_BUILD_PARALLEL_LEVEL}
37+
- &make-test
38+
name: Test with GNU Make
39+
run: make test -j${CTEST_PARALLEL_LEVEL}
40+
- &cmake-build
41+
name: Build with CMake
42+
run: cmake -Bbuild && cmake --build build
43+
- &ctest
44+
name: Test with CTest
45+
run: ctest --test-dir build --output-on-failure
3146
windows:
3247
runs-on: ${{ matrix.os }}
3348
timeout-minutes: 10
49+
env:
50+
CMAKE_GENERATOR: "MinGW Makefiles"
3451
strategy:
3552
fail-fast: false
3653
matrix:
@@ -44,32 +61,35 @@ jobs:
4461
run:
4562
shell: msys2 {0}
4663
steps:
47-
- uses: actions/checkout@v7
64+
- *git-checkout
65+
- *count-cpu
4866
- name: Set up the desired MSYS2 environment
4967
uses: msys2/setup-msys2@v2
5068
with:
5169
msystem: ${{matrix.sys}}
52-
install: base-devel mingw-w64-${{matrix.env}}-toolchain
53-
- run: make -j$(nproc)
54-
- run: make test
70+
install: base-devel mingw-w64-${{ matrix.env }}-cmake mingw-w64-${{ matrix.env }}-make mingw-w64-${{matrix.env}}-toolchain
71+
- *make-build
72+
- *make-test
73+
- *cmake-build
74+
- *ctest
5575
code-coverage:
5676
runs-on: ubuntu-latest
5777
timeout-minutes: 10
5878
steps:
59-
- name: Checkout Openlibm
60-
uses: actions/checkout@v7
79+
- *git-checkout
6180
- name: Checkout Openlibm-test
6281
uses: actions/checkout@v7
6382
with:
6483
repository: 'JuliaMath/openlibm-test'
6584
path: 'openlibm-test'
6685
- name: Setup LCOV
6786
uses: hrishikesh-kadam/setup-lcov@v1
87+
- *count-cpu
6888
- name: Build Openlibm
69-
run: make -j$(nproc) CODE_COVERAGE=1
89+
run: make -j${CMAKE_BUILD_PARALLEL_LEVEL} CODE_COVERAGE=1
7090
- name: Run Test
7191
run: |
72-
make -j$(nproc) -C openlibm-test \
92+
make -j${CTEST_PARALLEL_LEVEL} -C openlibm-test \
7393
USE_OPENLIBM=1 OPENLIBM_HOME="$(pwd)" \
7494
SKIP_FP_EXCEPT_TEST=1
7595
- name: Show Test Result
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Detect CPU core count
2+
description: Set CPU core count as environment variables for parallel builds and tests
3+
4+
runs:
5+
6+
using: composite
7+
8+
steps:
9+
- name: Detect CPU cores
10+
shell: bash
11+
id: cores
12+
run: |
13+
if [[ "$RUNNER_OS" == "Linux" ]]; then
14+
CORES=$(nproc)
15+
elif [[ "$RUNNER_OS" == "macOS" ]]; then
16+
CORES=$(sysctl -n hw.ncpu)
17+
elif [[ "$RUNNER_OS" == "Windows" ]]; then
18+
CORES=$NUMBER_OF_PROCESSORS
19+
else
20+
CORES=2
21+
fi
22+
echo "CMAKE_BUILD_PARALLEL_LEVEL=$CORES" >> $GITHUB_ENV
23+
echo "CTEST_PARALLEL_LEVEL=$CORES" >> $GITHUB_ENV
24+
echo "Detected $CORES cores"

.github/workflows/cross.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ jobs:
4949
AR: ${{ matrix.config.ar }}
5050
steps:
5151
- uses: actions/checkout@v7
52+
- name: Count CPU cores
53+
uses: ./.github/workflows/composite-nproc
5254
- name: Install qemu and toolchain
5355
run: |
5456
sudo apt update
5557
sudo apt install -y qemu-user qemu-user-binfmt \
5658
${{ matrix.config.gcc_pkg || format('gcc-{0}', matrix.config.triple) }}
5759
- name: Build with ${{ matrix.config.triple }}-gcc
58-
run: make -j$(nproc) ARCH=$ARCH TOOLPREFIX=$TRIPLE- ${CC:+CC=$CC} ${AR:+AR=$AR}
60+
run: make -j${CMAKE_BUILD_PARALLEL_LEVEL} ARCH=$ARCH TOOLPREFIX=$TRIPLE- ${CC:+CC=$CC} ${AR:+AR=$AR}
5961
- name: Build tests
60-
run: make -j$(nproc) -C test ARCH=$ARCH TOOLPREFIX=$TRIPLE- ${CC:+CC=$CC} ${AR:+AR=$AR}
62+
run: make -j${CTEST_PARALLEL_LEVEL} -C test ARCH=$ARCH TOOLPREFIX=$TRIPLE- ${CC:+CC=$CC} ${AR:+AR=$AR}
6163
- name: Run tests under qemu
6264
env:
6365
QEMU_LD_PREFIX: /usr/${{ matrix.config.triple }}

0 commit comments

Comments
 (0)