Skip to content

Commit f1e9b5a

Browse files
committed
CI test: add CMake using Yaml anchors and composite workflow
ci: avoid wasted runs. Add parallel builds to cross-builds
1 parent 645c4f6 commit f1e9b5a

4 files changed

Lines changed: 81 additions & 17 deletions

File tree

.github/workflows/ci.yml

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ on:
77
branches:
88
- master
99
tags: '*'
10+
11+
# avoid wasted runs
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
1016
jobs:
1117
test-unix:
1218
runs-on: ${{ matrix.os }}
@@ -17,11 +23,28 @@ jobs:
1723
- ubuntu-latest
1824
- macos-latest
1925
steps:
20-
- uses: actions/checkout@v6
21-
- run: make
22-
- run: make test
26+
- &git-checkout
27+
name: Checkout Openlibm
28+
uses: actions/checkout@v6
29+
- &count-cpu
30+
name: Count CPU cores
31+
uses: ./.github/workflows/composite-nproc
32+
- &make-build
33+
name: Build with GNU Make
34+
run: make -j${CMAKE_BUILD_PARALLEL_LEVEL}
35+
- &make-test
36+
name: Test with GNU Make
37+
run: make test -j${CTEST_PARALLEL_LEVEL}
38+
- &cmake-build
39+
name: Build with CMake
40+
run: cmake -Bbuild && cmake --build build
41+
- &ctest
42+
name: Test with CTest
43+
run: ctest --test-dir build --output-on-failure
2344
windows:
2445
runs-on: windows-latest
46+
env:
47+
CMAKE_GENERATOR: "MinGW Makefiles"
2548
strategy:
2649
fail-fast: false
2750
matrix:
@@ -34,18 +57,21 @@ jobs:
3457
run:
3558
shell: msys2 {0}
3659
steps:
37-
- uses: actions/checkout@v6
60+
- *git-checkout
61+
- *count-cpu
3862
- name: Set up the desired MSYS2 environment
3963
uses: msys2/setup-msys2@v2
4064
with:
4165
msystem: ${{matrix.sys}}
42-
install: base-devel mingw-w64-${{matrix.env}}-toolchain
43-
- run: make
44-
- run: make test
66+
install: base-devel mingw-w64-${{ matrix.env }}-cmake mingw-w64-${{ matrix.env }}-make mingw-w64-${{matrix.env}}-toolchain
67+
- *make-build
68+
- *make-test
69+
- *cmake-build
70+
- *ctest
4571
code-coverage-old:
4672
runs-on: ubuntu-latest
4773
steps:
48-
- uses: actions/checkout@v6
74+
- *git-checkout
4975
- name: Setup LCOV
5076
uses: hrishikesh-kadam/setup-lcov@v1
5177
- name: Build and Run tests
@@ -62,20 +88,20 @@ jobs:
6288
code-coverage:
6389
runs-on: ubuntu-latest
6490
steps:
65-
- name: Checkout Openlibm
66-
uses: actions/checkout@v6
91+
- *git-checkout
6792
- name: Checkout Openlibm-test
6893
uses: actions/checkout@v6
6994
with:
7095
repository: 'JuliaMath/openlibm-test'
7196
path: 'openlibm-test'
7297
- name: Setup LCOV
7398
uses: hrishikesh-kadam/setup-lcov@v1
99+
- *count-cpu
74100
- name: Build Openlibm
75-
run: make -j`nproc` CODE_COVERAGE=1
101+
run: make -j${CMAKE_BUILD_PARALLEL_LEVEL} CODE_COVERAGE=1
76102
- name: Run Test
77103
run: |
78-
make -j`nproc` -C openlibm-test \
104+
make -j${CTEST_PARALLEL_LEVEL} -C openlibm-test \
79105
USE_OPENLIBM=1 OPENLIBM_HOME="$(pwd)" \
80106
SKIP_FP_EXCEPT_TEST=1 \
81107
- 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-loongarch64.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# merge this file into cross.yml
22
# when we can `sudo apt install gcc-loongarch64-linux-gnu` on ubuntu
3-
name: Cross
3+
name: Cross-LoongArch64
44

55
on:
66
pull_request:
@@ -11,6 +11,11 @@ on:
1111
- master
1212
tags: '*'
1313

14+
# avoid wasted runs
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
1419
jobs:
1520
build-cross-qemu:
1621
# TODO: We need Ubuntu 24.04 to use newer version of qemu,
@@ -27,6 +32,8 @@ jobs:
2732
TRIPLE: ${{ matrix.config.triple }}
2833
steps:
2934
- uses: actions/checkout@v6
35+
- name: Count CPU cores
36+
uses: ./.github/workflows/composite-nproc
3037
- name: Install qemu
3138
run: |
3239
sudo apt update
@@ -37,12 +44,12 @@ jobs:
3744
run: sudo apt install -y gcc-14-loongarch64-linux-gnu
3845
- name: Build with ${{ matrix.config.triple }}-gcc
3946
run: |
40-
make ARCH=$ARCH TOOLPREFIX=$TRIPLE- \
47+
make -j${CMAKE_BUILD_PARALLEL_LEVEL} ARCH=$ARCH TOOLPREFIX=$TRIPLE- \
4148
CC='loongarch64-linux-gnu-gcc-14' \
4249
AR='loongarch64-linux-gnu-gcc-ar-14' \
4350
- name: Build tests
4451
run: |
45-
make -C test ARCH=$ARCH TOOLPREFIX=$TRIPLE- \
52+
make -C test -j${CTEST_PARALLEL_LEVEL} ARCH=$ARCH TOOLPREFIX=$TRIPLE- \
4653
CC='loongarch64-linux-gnu-gcc-14' \
4754
AR='loongarch64-linux-gnu-gcc-ar-14' \
4855
- name: Run Tests

.github/workflows/cross.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
- master
1010
tags: '*'
1111

12+
# avoid wasted runs
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
1217
jobs:
1318
build-cross-qemu:
1419
# TODO: We need Ubuntu 24.04 to use newer version of qemu,
@@ -36,14 +41,16 @@ jobs:
3641
TRIPLE: ${{ matrix.config.triple }}
3742
steps:
3843
- uses: actions/checkout@v6
44+
- name: Count CPU cores
45+
uses: ./.github/workflows/composite-nproc
3946
- name: Install qemu and toolchain gcc-${{ matrix.config.triple }}
4047
run: |
4148
sudo apt update
4249
sudo apt install qemu-user qemu-user-binfmt gcc-$TRIPLE -y
4350
- name: Build with ${{ matrix.config.triple }}-gcc
44-
run: make ARCH=$ARCH TOOLPREFIX=$TRIPLE-
51+
run: make -j${CMAKE_BUILD_PARALLEL_LEVEL} ARCH=$ARCH TOOLPREFIX=$TRIPLE-
4552
- name: Build tests
46-
run: make -C test ARCH=$ARCH TOOLPREFIX=$TRIPLE-
53+
run: make -C test -j${CTEST_PARALLEL_LEVEL} ARCH=$ARCH TOOLPREFIX=$TRIPLE-
4754
- name: Run Tests
4855
env:
4956
QEMU_EXEC: qemu-${{ matrix.config.arch }}

0 commit comments

Comments
 (0)