| 1 |
name: Compiler cache |
| 2 |
description: Restore or save the weekly compiler cache |
| 3 |
|
| 4 |
inputs: |
| 5 |
mode: |
| 6 |
description: Whether to restore or save the cache |
| 7 |
required: true |
| 8 |
path: |
| 9 |
description: Local compiler-cache directory |
| 10 |
required: true |
| 11 |
key-prefix: |
| 12 |
description: Cache family prefix used for restore |
| 13 |
required: false |
| 14 |
default: colmap-compiler |
| 15 |
key-suffix: |
| 16 |
description: Configuration-specific cache key suffix used for restore |
| 17 |
required: false |
| 18 |
cache-version: |
| 19 |
description: Cache schema version |
| 20 |
required: false |
| 21 |
default: "2" |
| 22 |
key: |
| 23 |
description: Exact cache key returned by an earlier restore |
| 24 |
required: false |
| 25 |
cache-hit: |
| 26 |
description: Whether the exact cache key was restored before the build |
| 27 |
required: false |
| 28 |
default: "false" |
| 29 |
ccache-dir: |
| 30 |
description: Optional ccache directory to prune and recompress before saving |
| 31 |
required: false |
| 32 |
evict-older-than: |
| 33 |
description: Remove ccache entries unused for this long before saving |
| 34 |
required: false |
| 35 |
default: 1d |
| 36 |
recompression-level: |
| 37 |
description: Zstandard level used to recompress ccache entries before saving |
| 38 |
required: false |
| 39 |
default: "6" |
| 40 |
|
| 41 |
outputs: |
| 42 |
cache-hit: |
| 43 |
description: Whether the exact weekly cache was restored |
| 44 |
value: ${{ steps.restore.outputs.cache-hit }} |
| 45 |
key: |
| 46 |
description: Exact weekly key to use when saving the cache |
| 47 |
value: ${{ inputs.key-prefix }}-v${{ inputs.cache-version }}-${{ inputs.key-suffix }}-${{ steps.epoch.outputs.value }} |
| 48 |
|
| 49 |
runs: |
| 50 |
using: composite |
| 51 |
steps: |
| 52 |
- name: Validate mode |
| 53 |
if: ${{ inputs.mode != 'restore' && inputs.mode != 'save' }} |
| 54 |
shell: bash |
| 55 |
run: | |
| 56 |
echo "Unsupported compiler-cache mode: ${{ inputs.mode }}" >&2 |
| 57 |
exit 1 |
| 58 |
|
| 59 |
- name: Set cache epoch |
| 60 |
if: ${{ inputs.mode == 'restore' }} |
| 61 |
id: epoch |
| 62 |
shell: bash |
| 63 |
# GitHub cache entries are immutable. Rotate weekly so changed objects |
| 64 |
# are incorporated without creating a new archive for every run. |
| 65 |
run: echo "value=$(date -u +%G-%V)" >> "$GITHUB_OUTPUT" |
| 66 |
|
| 67 |
- name: Restore compiler cache |
| 68 |
if: ${{ inputs.mode == 'restore' }} |
| 69 |
id: restore |
| 70 |
uses: actions/cache/restore@v6 |
| 71 |
with: |
| 72 |
key: ${{ inputs.key-prefix }}-v${{ inputs.cache-version }}-${{ inputs.key-suffix }}-${{ steps.epoch.outputs.value }} |
| 73 |
restore-keys: ${{ inputs.key-prefix }}-v${{ inputs.cache-version }}-${{ inputs.key-suffix }}- |
| 74 |
path: ${{ inputs.path }} |
| 75 |
|
| 76 |
- name: Compact ccache (Linux/macOS) |
| 77 |
if: ${{ success() && inputs.mode == 'save' && runner.os != 'Windows' && (github.event_name == 'push' || github.event_name == 'release') && inputs.cache-hit != 'true' && inputs.ccache-dir != '' }} |
| 78 |
shell: bash |
| 79 |
run: | |
| 80 |
set -euo pipefail |
| 81 |
cache_root="${{ inputs.path }}" |
| 82 |
if [ -x "${cache_root}/bin/ccache" ]; then |
| 83 |
ccache="${cache_root}/bin/ccache" |
| 84 |
elif [ -x "${cache_root}/bin/ccache.exe" ]; then |
| 85 |
ccache="${cache_root}/bin/ccache.exe" |
| 86 |
elif command -v ccache >/dev/null 2>&1; then |
| 87 |
ccache="$(command -v ccache)" |
| 88 |
else |
| 89 |
echo "ccache executable not found" >&2 |
| 90 |
exit 1 |
| 91 |
fi |
| 92 |
|
| 93 |
# CCACHE_DIR is remapped to a container path by the PyCOLMAP Linux job, |
| 94 |
# so it must be overridden here. CCACHE_MAXSIZE needs no override: the |
| 95 |
# job-level value is inherited by composite action steps as-is. |
| 96 |
export CCACHE_DIR="${{ inputs.ccache-dir }}" |
| 97 |
"${ccache}" --evict-older-than "${{ inputs.evict-older-than }}" |
| 98 |
"${ccache}" --recompress "${{ inputs.recompression-level }}" |
| 99 |
"${ccache}" --cleanup |
| 100 |
"${ccache}" --show-compression |
| 101 |
"${ccache}" --show-stats --verbose |
| 102 |
|
| 103 |
- name: Compact ccache (Windows) |
| 104 |
if: ${{ success() && inputs.mode == 'save' && runner.os == 'Windows' && (github.event_name == 'push' || github.event_name == 'release') && inputs.cache-hit != 'true' && inputs.ccache-dir != '' }} |
| 105 |
shell: pwsh |
| 106 |
run: | |
| 107 |
$ErrorActionPreference = "Stop" |
| 108 |
$cacheRoot = "${{ inputs.path }}" |
| 109 |
$ccache = @( |
| 110 |
(Join-Path $cacheRoot "bin/ccache"), |
| 111 |
(Join-Path $cacheRoot "bin/ccache.exe") |
| 112 |
) | Where-Object { Test-Path -PathType Leaf $_ } | Select-Object -First 1 |
| 113 |
if (!$ccache) { |
| 114 |
$ccache = (Get-Command ccache -ErrorAction SilentlyContinue).Source |
| 115 |
} |
| 116 |
if (!$ccache) { |
| 117 |
throw "ccache executable not found" |
| 118 |
} |
| 119 |
|
| 120 |
# CCACHE_DIR is remapped to a container path by the PyCOLMAP Linux job, |
| 121 |
# so it must be overridden here. CCACHE_MAXSIZE needs no override: the |
| 122 |
# job-level value is inherited by composite action steps as-is. |
| 123 |
$env:CCACHE_DIR = "${{ inputs.ccache-dir }}" |
| 124 |
& $ccache --evict-older-than "${{ inputs.evict-older-than }}" |
| 125 |
if ($LASTEXITCODE -ne 0) { throw "ccache eviction failed" } |
| 126 |
& $ccache --recompress "${{ inputs.recompression-level }}" |
| 127 |
if ($LASTEXITCODE -ne 0) { throw "ccache recompression failed" } |
| 128 |
& $ccache --cleanup |
| 129 |
if ($LASTEXITCODE -ne 0) { throw "ccache cleanup failed" } |
| 130 |
& $ccache --show-compression |
| 131 |
if ($LASTEXITCODE -ne 0) { throw "ccache compression stats failed" } |
| 132 |
& $ccache --show-stats --verbose |
| 133 |
if ($LASTEXITCODE -ne 0) { throw "ccache stats failed" } |
| 134 |
|
| 135 |
- name: Save compiler cache |
| 136 |
if: ${{ success() && inputs.mode == 'save' && (github.event_name == 'push' || github.event_name == 'release') && inputs.cache-hit != 'true' }} |
| 137 |
uses: actions/cache/save@v6 |
| 138 |
with: |
| 139 |
key: ${{ inputs.key }} |
| 140 |
path: ${{ inputs.path }} |