This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit af5fe51ac135eb838d0ced7894d0f6eb36ea4d3f
Author: Szymon Janc <[email protected]>
AuthorDate: Tue Oct 13 01:41:42 2026 +0200

    ci: Add ccache support for build jobs
    
    Build jobs compile same sources on every run. Add composite actions
    that set up ccache in front of compilers used by newt and restore and
    save ccache directory, and use them in all build and test jobs on
    Linux.
    
    ccache directory is saved only from master branch, so pull requests
    use cache from latest master build. Before saving, entries not used
    by current job are removed so that cache does not grow over time.
    
    Assisted-by: Claude:claude-opus-5-5
---
 .github/actions/ccache-restore/action.yml   | 77 +++++++++++++++++++++++++++++
 .github/actions/ccache-save/action.yml      | 59 ++++++++++++++++++++++
 .github/workflows/build_all_apps.yml        | 11 ++++-
 .github/workflows/build_blinky.yml          | 11 ++++-
 .github/workflows/build_bootloader.yml      | 11 ++++-
 .github/workflows/build_bootloader_main.yml | 11 ++++-
 .github/workflows/build_cc_target.yml       |  9 ++++
 .github/workflows/build_mtest_apps.yml      | 11 ++++-
 .github/workflows/build_targets.yml         |  9 ++++
 .github/workflows/newt_test_all.yml         | 11 ++++-
 10 files changed, 214 insertions(+), 6 deletions(-)

diff --git a/.github/actions/ccache-restore/action.yml 
b/.github/actions/ccache-restore/action.yml
new file mode 100644
index 000000000..13ae7ab5c
--- /dev/null
+++ b/.github/actions/ccache-restore/action.yml
@@ -0,0 +1,77 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+name: Restore ccache
+description: >
+  Install ccache, put it in front of compilers used by newt and restore
+  ccache directory from cache. Must be used after toolchain is installed
+  so that ccache wrappers are found in PATH before real compilers.
+  Supported only on Linux, does nothing on other systems.
+
+inputs:
+  key:
+    description: Cache key, unique for job (and matrix entry)
+    required: true
+  max-size:
+    description: Maximum size of ccache directory
+    required: false
+    default: 500M
+
+runs:
+  using: composite
+  steps:
+    - name: Set up ccache
+      if: runner.os == 'Linux'
+      shell: bash
+      run: |
+        if ! command -v ccache > /dev/null; then
+          sudo apt-get update
+          sudo apt-get install -y ccache
+        fi
+        # Wrappers named as compilers used by newt, ccache finds real
+        # compiler by skipping its own directory in PATH.
+        dir="$RUNNER_TEMP/ccache-bin"
+        mkdir -p "$dir"
+        for c in arm-none-eabi-gcc arm-none-eabi-g++ gcc g++; do
+          ln -sf "$(command -v ccache)" "$dir/$c"
+        done
+        echo "$dir" >> "$GITHUB_PATH"
+        {
+          echo "CCACHE_DIR=$RUNNER_TEMP/ccache"
+          echo "CCACHE_BASEDIR=$GITHUB_WORKSPACE"
+          echo "CCACHE_NOHASHDIR=true"
+          echo "CCACHE_COMPILERCHECK=content"
+          echo "CCACHE_MAXSIZE=${{ inputs.max-size }}"
+          echo "CCACHE_JOB_START=$(date +%s)"
+        } >> "$GITHUB_ENV"
+
+    - name: Restore ccache directory
+      if: runner.os == 'Linux'
+      uses: actions/cache/restore@v6
+      with:
+        path: ${{ runner.temp }}/ccache
+        key: ccache-${{ inputs.key }}-${{ github.sha }}
+        restore-keys: ccache-${{ inputs.key }}-
+
+    - name: Reset ccache statistics
+      if: runner.os == 'Linux'
+      shell: bash
+      run: |
+        ccache --version | head -1
+        ccache --zero-stats
diff --git a/.github/actions/ccache-save/action.yml 
b/.github/actions/ccache-save/action.yml
new file mode 100644
index 000000000..a05da4273
--- /dev/null
+++ b/.github/actions/ccache-save/action.yml
@@ -0,0 +1,59 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+name: Save ccache
+description: >
+  Show ccache statistics, drop cache entries not used by current job and
+  save ccache directory to cache. Cache is saved only from master branch
+  since only caches from default branch are available to pull requests.
+  Supported only on Linux, does nothing on other systems.
+
+inputs:
+  key:
+    description: Cache key, same as used for ccache-restore
+    required: true
+
+runs:
+  using: composite
+  steps:
+    - name: Show ccache statistics
+      if: runner.os == 'Linux'
+      shell: bash
+      run: ccache --show-stats
+
+    - name: Remove unused ccache entries
+      if: >-
+        runner.os == 'Linux' && github.ref == 'refs/heads/master' &&
+        github.event_name != 'pull_request'
+      shell: bash
+      run: |
+        # Keep only entries used by this job so that cache size does not
+        # grow over time with stale entries.
+        age=$(( $(date +%s) - CCACHE_JOB_START + 60 ))
+        ccache --evict-older-than "${age}s"
+        ccache --show-stats | grep -i 'cache size' || true
+
+    - name: Save ccache directory
+      if: >-
+        runner.os == 'Linux' && github.ref == 'refs/heads/master' &&
+        github.event_name != 'pull_request'
+      uses: actions/cache/save@v6
+      with:
+        path: ${{ runner.temp }}/ccache
+        key: ccache-${{ inputs.key }}-${{ github.run_id }}-${{ 
github.run_attempt }}
diff --git a/.github/workflows/build_all_apps.yml 
b/.github/workflows/build_all_apps.yml
index 124d37f6f..1c510dc9a 100644
--- a/.github/workflows/build_all_apps.yml
+++ b/.github/workflows/build_all_apps.yml
@@ -45,7 +45,7 @@ jobs:
         shell: bash
         run: |
              sudo apt-get update
-             sudo apt-get install -y gcc-multilib
+             sudo apt-get install -y gcc-multilib ccache
       - name: Install newt
         uses: ./.github/actions/newt-install
       - name: Set up project
@@ -55,9 +55,18 @@ jobs:
       - name: Remove project targets
         shell: bash
         run: rm -rf build/targets
+      - name: Restore ccache
+        uses: ./.github/actions/ccache-restore
+        with:
+          key: apps
       - name: Build applications
         shell: bash
         run: |
              cd build
              bash ../.github/test_build_apps.sh
              cd ..
+      - name: Save ccache
+        if: always()
+        uses: ./.github/actions/ccache-save
+        with:
+          key: apps
diff --git a/.github/workflows/build_blinky.yml 
b/.github/workflows/build_blinky.yml
index 69d4fca8a..673db3ff2 100644
--- a/.github/workflows/build_blinky.yml
+++ b/.github/workflows/build_blinky.yml
@@ -49,7 +49,7 @@ jobs:
         if: matrix.os == 'ubuntu-latest'
         run: |
              sudo apt-get update
-             sudo apt-get install -y gcc-multilib
+             sudo apt-get install -y gcc-multilib ccache
       - name: Install GNU sed
         if: matrix.os == 'macos-latest'
         run: |
@@ -61,8 +61,17 @@ jobs:
         uses: ./.github/actions/newt-project
         with:
           project: .github/project.yml
+      - name: Restore ccache
+        uses: ./.github/actions/ccache-restore
+        with:
+          key: blinky
       - name: Build Blinky
         shell: bash
         run: |
              cd build
              bash ../.github/test_build_blinky.sh
+      - name: Save ccache
+        if: always()
+        uses: ./.github/actions/ccache-save
+        with:
+          key: blinky
diff --git a/.github/workflows/build_bootloader.yml 
b/.github/workflows/build_bootloader.yml
index 369152f54..546ddcd28 100644
--- a/.github/workflows/build_bootloader.yml
+++ b/.github/workflows/build_bootloader.yml
@@ -44,7 +44,7 @@ jobs:
       - name: Install Dependencies
         run: |
              sudo apt-get update
-             sudo apt-get install -y gcc-multilib
+             sudo apt-get install -y gcc-multilib ccache
       - name: Install newt
         uses: ./.github/actions/newt-install
       - name: Set up project
@@ -52,8 +52,17 @@ jobs:
         with:
           project: .github/project.yml
           save-cache: true
+      - name: Restore ccache
+        uses: ./.github/actions/ccache-restore
+        with:
+          key: bootloader
       - name: Build bootloader
         shell: bash
         run: |
              cd build
              bash ../.github/test_build_bootloader.sh
+      - name: Save ccache
+        if: always()
+        uses: ./.github/actions/ccache-save
+        with:
+          key: bootloader
diff --git a/.github/workflows/build_bootloader_main.yml 
b/.github/workflows/build_bootloader_main.yml
index a2c377f57..fbb6f0c60 100644
--- a/.github/workflows/build_bootloader_main.yml
+++ b/.github/workflows/build_bootloader_main.yml
@@ -41,13 +41,17 @@ jobs:
       - name: Install Dependencies
         run: |
              sudo apt-get update
-             sudo apt-get install -y gcc-multilib
+             sudo apt-get install -y gcc-multilib ccache
       - name: Install newt
         uses: ./.github/actions/newt-install
       - name: Set up project
         uses: ./.github/actions/newt-project
         with:
           project: .github/project.yml
+      - name: Restore ccache
+        uses: ./.github/actions/ccache-restore
+        with:
+          key: bootloader-main
       - name: Build bootloader (main branch)
         shell: bash
         run: |
@@ -58,3 +62,8 @@ jobs:
              cd ../..
              bash ../.github/test_build_bootloader_main.sh
              newt test @mcuboot/boot/boot_serial
+      - name: Save ccache
+        if: always()
+        uses: ./.github/actions/ccache-save
+        with:
+          key: bootloader-main
diff --git a/.github/workflows/build_cc_target.yml 
b/.github/workflows/build_cc_target.yml
index 9cbd8dafc..66f6fc46f 100644
--- a/.github/workflows/build_cc_target.yml
+++ b/.github/workflows/build_cc_target.yml
@@ -51,9 +51,18 @@ jobs:
         uses: ./.github/actions/newt-project
         with:
           project: .github/project_build_cc_target.yml
+      - name: Restore ccache
+        uses: ./.github/actions/ccache-restore
+        with:
+          key: gcc-target-${{ matrix.gcc }}
       - name: Build targets
         shell: bash
         run: |
              cd build
              newt build 
@apache-mynewt-core/targets/coverity/btshell_nrf52840_coverity
              newt build 
@apache-mynewt-core/targets/coverity/btshell_nrf52840_coverity2
+      - name: Save ccache
+        if: always()
+        uses: ./.github/actions/ccache-save
+        with:
+          key: gcc-target-${{ matrix.gcc }}
diff --git a/.github/workflows/build_mtest_apps.yml 
b/.github/workflows/build_mtest_apps.yml
index 014ab231d..9764a0239 100644
--- a/.github/workflows/build_mtest_apps.yml
+++ b/.github/workflows/build_mtest_apps.yml
@@ -45,7 +45,7 @@ jobs:
         shell: bash
         run: |
           sudo apt-get update
-          sudo apt-get install -y gcc-multilib
+          sudo apt-get install -y gcc-multilib ccache
       - name: Install newt
         uses: ./.github/actions/newt-install
       - name: Set up project
@@ -56,9 +56,18 @@ jobs:
       - name: Remove project targets
         shell: bash
         run: rm -rf build_mtest/targets
+      - name: Restore ccache
+        uses: ./.github/actions/ccache-restore
+        with:
+          key: mtest-apps
       - name: Build mtest apps
         shell: bash
         run: |
           cd build_mtest
           bash ../.github/test_build_mtest_apps.sh
           cd ..
+      - name: Save ccache
+        if: always()
+        uses: ./.github/actions/ccache-save
+        with:
+          key: mtest-apps
diff --git a/.github/workflows/build_targets.yml 
b/.github/workflows/build_targets.yml
index f84f25f65..114cef7f5 100644
--- a/.github/workflows/build_targets.yml
+++ b/.github/workflows/build_targets.yml
@@ -59,6 +59,10 @@ jobs:
       - name: Remove project targets
         shell: bash
         run: rm -rf build/targets
+      - name: Restore ccache
+        uses: ./.github/actions/ccache-restore
+        with:
+          key: targets
       - name: Build targets
         shell: bash
         run: |
@@ -76,3 +80,8 @@ jobs:
              ls targets | xargs -n1 sh -c 'echo "Testing $0"; newt build -q  
$0'
              rm -rf targets
              cd ..
+      - name: Save ccache
+        if: always()
+        uses: ./.github/actions/ccache-save
+        with:
+          key: targets
diff --git a/.github/workflows/newt_test_all.yml 
b/.github/workflows/newt_test_all.yml
index 5cec7bc85..f2ef2f13f 100644
--- a/.github/workflows/newt_test_all.yml
+++ b/.github/workflows/newt_test_all.yml
@@ -41,13 +41,17 @@ jobs:
       - name: Install Dependencies
         run: |
              sudo apt-get update
-             sudo apt-get install -y gcc-multilib
+             sudo apt-get install -y gcc-multilib ccache
       - name: Install newt
         uses: ./.github/actions/newt-install
       - name: Set up project
         uses: ./.github/actions/newt-project
         with:
           project: .github/project_newt_test_all.yml
+      - name: Restore ccache
+        uses: ./.github/actions/ccache-restore
+        with:
+          key: unit-tests
       - name: Switch to main mcuboot
         # This is temporary until next mcuboot release is available
         shell: bash
@@ -59,3 +63,8 @@ jobs:
         run: |
              cd build
              newt test all
+      - name: Save ccache
+        if: always()
+        uses: ./.github/actions/ccache-save
+        with:
+          key: unit-tests

Reply via email to