Merge pull request #9690

f18b966a9 build: auto-set GitHub runner make job count (iamamyth)
This commit is contained in:
tobtoht 2025-01-25 05:57:58 +00:00
commit c0f3a1c1db
No known key found for this signature in database
GPG Key ID: E45B10DD027D2472
3 changed files with 37 additions and 9 deletions

View File

@ -0,0 +1,22 @@
name: 'set-make-job-count'
description: 'Set the MAKE_JOB_COUNT environment variable to a value suitable for the host runner'
runs:
using: "composite"
steps:
# Each job runner requires 2.25 GiB (i.e. 1024 * 9/4 MiB) memory and
# a dedicated logical CPU core
- name: set-jobs-macOS
if: runner.os == 'macOS'
run: |
echo MAKE_JOB_COUNT=$(expr $(printf '%s\n%s' $(( $(sysctl -n hw.memsize) * 4 / (1073741824 * 9) )) $(sysctl -n hw.logicalcpu) | sort -n | head -n1) '|' 1) >> $GITHUB_ENV
shell: bash
- name: set-jobs-windows
if: runner.os == 'Windows'
run: |
echo MAKE_JOB_COUNT=$(expr $(printf '%s\n%s' $(( $(grep MemTotal: /proc/meminfo | cut -d: -f2 | cut -dk -f1) * 4 / (1048576 * 9) )) $(nproc) | sort -n | head -n1) '|' 1) >> $GITHUB_ENV
shell: msys2 {0}
- name: set-jobs-linux
if: runner.os == 'Linux'
run: |
echo MAKE_JOB_COUNT=$(expr $(printf '%s\n%s' $(( $(grep MemTotal: /proc/meminfo | cut -d: -f2 | cut -dk -f1) * 4 / (1048576 * 9) )) $(nproc) | sort -n | head -n1) '|' 1) >> $GITHUB_ENV
shell: bash

View File

@ -13,8 +13,7 @@ on:
# The below variables reduce repetitions across similar targets # The below variables reduce repetitions across similar targets
env: env:
REMOVE_BUNDLED_PACKAGES : sudo rm -rf /usr/local REMOVE_BUNDLED_PACKAGES : sudo rm -rf /usr/local
BUILD_DEFAULT_LINUX: | BUILD_DEFAULT_LINUX: 'cmake -S . -B build -D ARCH="default" -D BUILD_TESTS=ON -D CMAKE_BUILD_TYPE=Release && cmake --build build'
cmake -S . -B build -D ARCH="default" -D BUILD_TESTS=ON -D CMAKE_BUILD_TYPE=Release && cmake --build build --parallel 4
APT_INSTALL_LINUX: 'apt -y install build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind8-dev pkg-config libssl-dev libzmq3-dev libsodium-dev libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler ccache git' APT_INSTALL_LINUX: 'apt -y install build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind8-dev pkg-config libssl-dev libzmq3-dev libsodium-dev libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler ccache git'
APT_SET_CONF: | APT_SET_CONF: |
tee -a /etc/apt/apt.conf.d/80-custom << EOF tee -a /etc/apt/apt.conf.d/80-custom << EOF
@ -42,6 +41,7 @@ jobs:
path: /Users/runner/Library/Caches/ccache path: /Users/runner/Library/Caches/ccache
key: ccache-${{ runner.os }}-build-${{ github.sha }} key: ccache-${{ runner.os }}-build-${{ github.sha }}
restore-keys: ccache-${{ runner.os }}-build- restore-keys: ccache-${{ runner.os }}-build-
- uses: ./.github/actions/set-make-job-count
- name: install dependencies - name: install dependencies
run: | run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install boost hidapi openssl zmq miniupnpc expat libunwind-headers protobuf@21 ccache HOMEBREW_NO_AUTO_UPDATE=1 brew install boost hidapi openssl zmq miniupnpc expat libunwind-headers protobuf@21 ccache
@ -49,7 +49,7 @@ jobs:
- name: build - name: build
run: | run: |
${{env.CCACHE_SETTINGS}} ${{env.CCACHE_SETTINGS}}
make -j3 make -j${{env.MAKE_JOB_COUNT}}
build-windows: build-windows:
name: 'Windows (MSYS2)' name: 'Windows (MSYS2)'
@ -73,10 +73,11 @@ jobs:
with: with:
update: true update: true
install: mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-ccache mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-protobuf mingw-w64-x86_64-libusb mingw-w64-x86_64-unbound git pkg-config install: mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-ccache mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-protobuf mingw-w64-x86_64-libusb mingw-w64-x86_64-unbound git pkg-config
- uses: ./.github/actions/set-make-job-count
- name: build - name: build
run: | run: |
${{env.CCACHE_SETTINGS}} ${{env.CCACHE_SETTINGS}}
make release-static-win64 -j4 make release-static-win64 -j${{env.MAKE_JOB_COUNT}}
build-arch: build-arch:
name: 'Arch Linux' name: 'Arch Linux'
@ -113,8 +114,9 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
submodules: recursive submodules: recursive
- uses: ./.github/actions/set-make-job-count
- name: build - name: build
run: ${{env.BUILD_DEFAULT_LINUX}} run: ${{env.BUILD_DEFAULT_LINUX}} --parallel ${{env.MAKE_JOB_COUNT}}
# See the OS labels and monitor deprecations here: # See the OS labels and monitor deprecations here:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
@ -141,6 +143,7 @@ jobs:
path: ~/.ccache path: ~/.ccache
key: ccache-${{ runner.os }}-build-${{ matrix.os }}-${{ github.sha }} key: ccache-${{ runner.os }}-build-${{ matrix.os }}-${{ github.sha }}
restore-keys: ccache-${{ runner.os }}-build-${{ matrix.os }} restore-keys: ccache-${{ runner.os }}-build-${{ matrix.os }}
- uses: ./.github/actions/set-make-job-count
- name: remove bundled packages - name: remove bundled packages
run: ${{env.REMOVE_BUNDLED_PACKAGES}} run: ${{env.REMOVE_BUNDLED_PACKAGES}}
- name: set apt conf - name: set apt conf
@ -152,7 +155,7 @@ jobs:
- name: build - name: build
run: | run: |
${{env.CCACHE_SETTINGS}} ${{env.CCACHE_SETTINGS}}
${{env.BUILD_DEFAULT_LINUX}} ${{env.BUILD_DEFAULT_LINUX}} --parallel ${{env.MAKE_JOB_COUNT}}
libwallet-ubuntu: libwallet-ubuntu:
name: "Ubuntu 20.04 (libwallet)" name: "Ubuntu 20.04 (libwallet)"
@ -168,6 +171,7 @@ jobs:
path: ~/.ccache path: ~/.ccache
key: ccache-${{ runner.os }}-libwallet-${{ github.sha }} key: ccache-${{ runner.os }}-libwallet-${{ github.sha }}
restore-keys: ccache-${{ runner.os }}-libwallet- restore-keys: ccache-${{ runner.os }}-libwallet-
- uses: ./.github/actions/set-make-job-count
- name: remove bundled packages - name: remove bundled packages
run: ${{env.REMOVE_BUNDLED_PACKAGES}} run: ${{env.REMOVE_BUNDLED_PACKAGES}}
- name: set apt conf - name: set apt conf
@ -180,7 +184,7 @@ jobs:
run: | run: |
${{env.CCACHE_SETTINGS}} ${{env.CCACHE_SETTINGS}}
cmake . cmake .
make wallet_api -j4 make wallet_api -j${{env.MAKE_JOB_COUNT}}
test-ubuntu: test-ubuntu:
name: "Ubuntu 20.04 (tests)" name: "Ubuntu 20.04 (tests)"
@ -198,6 +202,7 @@ jobs:
path: ~/.ccache path: ~/.ccache
key: ccache-${{ runner.os }}-build-ubuntu-latest-${{ github.sha }} key: ccache-${{ runner.os }}-build-ubuntu-latest-${{ github.sha }}
restore-keys: ccache-${{ runner.os }}-build-ubuntu-latest restore-keys: ccache-${{ runner.os }}-build-ubuntu-latest
- uses: ./.github/actions/set-make-job-count
- name: remove bundled packages - name: remove bundled packages
run: ${{env.REMOVE_BUNDLED_PACKAGES}} run: ${{env.REMOVE_BUNDLED_PACKAGES}}
- name: set apt conf - name: set apt conf
@ -214,7 +219,7 @@ jobs:
DNS_PUBLIC: tcp://9.9.9.9 DNS_PUBLIC: tcp://9.9.9.9
run: | run: |
${{env.CCACHE_SETTINGS}} ${{env.CCACHE_SETTINGS}}
${{env.BUILD_DEFAULT_LINUX}} ${{env.BUILD_DEFAULT_LINUX}} --parallel ${{env.MAKE_JOB_COUNT}}
cmake --build build --target test cmake --build build --target test
# ARCH="default" (not "native") ensures, that a different execution host can execute binaries compiled elsewhere. # ARCH="default" (not "native") ensures, that a different execution host can execute binaries compiled elsewhere.

View File

@ -79,6 +79,7 @@ jobs:
restore-keys: | restore-keys: |
depends-${{ matrix.toolchain.host }}-${{ hashFiles('contrib/depends/packages/*') }} depends-${{ matrix.toolchain.host }}-${{ hashFiles('contrib/depends/packages/*') }}
depends-${{ matrix.toolchain.host }}- depends-${{ matrix.toolchain.host }}-
- uses: ./.github/actions/set-make-job-count
- name: set apt conf - name: set apt conf
run: ${{env.APT_SET_CONF}} run: ${{env.APT_SET_CONF}}
- name: install dependencies - name: install dependencies
@ -91,7 +92,7 @@ jobs:
- name: build - name: build
run: | run: |
${{env.CCACHE_SETTINGS}} ${{env.CCACHE_SETTINGS}}
make depends target=${{ matrix.toolchain.host }} -j4 make depends target=${{ matrix.toolchain.host }} -j${{env.MAKE_JOB_COUNT}}
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
if: ${{ matrix.toolchain.host == 'x86_64-w64-mingw32' || matrix.toolchain.host == 'x86_64-apple-darwin' || matrix.toolchain.host == 'aarch64-apple-darwin' || matrix.toolchain.host == 'x86_64-unknown-linux-gnu' }} if: ${{ matrix.toolchain.host == 'x86_64-w64-mingw32' || matrix.toolchain.host == 'x86_64-apple-darwin' || matrix.toolchain.host == 'aarch64-apple-darwin' || matrix.toolchain.host == 'x86_64-unknown-linux-gnu' }}
with: with: