From b5af7a339091600240044eadcd5d75e034022e22 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 1 Apr 2026 09:41:19 +0100 Subject: [PATCH] Enable ccache within CI (#26121) --- .../ci_build_major_branch_keymap.yml | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci_build_major_branch_keymap.yml b/.github/workflows/ci_build_major_branch_keymap.yml index d2dcd853135..d3cef2a6fac 100644 --- a/.github/workflows/ci_build_major_branch_keymap.yml +++ b/.github/workflows/ci_build_major_branch_keymap.yml @@ -38,17 +38,18 @@ jobs: run: pip3 install -r requirements-dev.txt - name: Generate build targets + shell: 'bash {0}' id: generate_targets run: | { # Intentionally use `shuf` here so that we share manufacturers across all build groups -- some have a lot of ARM-based boards which inherently take longer counter=0 echo -n '{' - qmk find -km ${{ inputs.keymap }} 2>/dev/null | sort | uniq | shuf | xargs -L${{ inputs.slice_length }} | while IFS=$'\n' read target ; do + qmk find -km ${{ inputs.keymap }} 2>/dev/null | sort | uniq | shuf --random-source=<(openssl enc -aes-256-ctr -pass pass:qmk -nosalt /dev/null) | xargs -L${{ inputs.slice_length }} | while IFS=$'\n' read target ; do if [ $counter -gt 0 ]; then echo -n ',' fi counter=$((counter+1)) - printf "\"group %02d\":{" $counter + printf "\"group-%02d\":{" $counter echo -n '"targets":"' echo $target | tr ' ' '\n' | sort | uniq | xargs echo -n echo -n '"}' @@ -72,6 +73,9 @@ jobs: container: ghcr.io/qmk/qmk_cli continue-on-error: true + env: + CCACHE_CONFIGPATH: ~/.cache + strategy: matrix: target: ${{ fromJson(needs.generate_targets.outputs.targets) }} @@ -83,6 +87,8 @@ jobs: - name: Checkout QMK Firmware uses: actions/checkout@v6 + with: + submodules: recursive - name: Install dependencies run: pip3 install -r requirements-dev.txt @@ -93,24 +99,43 @@ jobs: name: targets-${{ inputs.keymap }} path: . - - name: Deploy submodules - run: | - qmk git-submodule -f - - name: Dump targets run: | jq -r '.["${{ matrix.target }}"].targets' targets.json | tr ' ' '\n' | sort + - name: Restore Cache + id: cache + uses: actions/cache/restore@v5 + with: + path: ${{ env.CCACHE_CONFIGPATH }} + key: compile-${{ inputs.keymap }}-${{ matrix.target }} + - name: Build targets continue-on-error: true run: | - export NCPUS=$(( $(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null) -1 )) targets=$(jq -r '.["${{ matrix.target }}"].targets' targets.json | tr ' ' '\n' | sort) if [ -z "${targets}" ]; then echo "Zero build targets detected" exit 0 fi - qmk mass-compile -t -j $NCPUS -e DUMP_CI_METADATA=yes $targets || touch .failed + qmk mass-compile -t -j $(nproc) -e DUMP_CI_METADATA=yes -e USE_CCACHE=yes $targets || touch .failed + + - name: Dump ccache stats + run: | + ccache -s + + # Delete the old cache on hit to emulate a cache update. See https://github.com/actions/cache/issues/342. + - name: Delete old cache + env: + GH_TOKEN: ${{ github.token }} + if: steps.cache.outputs.cache-hit + run: gh cache delete --ref ${{ github.ref }} ${{ steps.cache.outputs.cache-primary-key }} + + - name: Save Cache + uses: actions/cache/save@v5 + with: + path: ${{ env.CCACHE_CONFIGPATH }} + key: compile-${{ inputs.keymap }}-${{ matrix.target }} - name: Upload binaries uses: actions/upload-artifact@v7