Skip to content

Commit 7722b73

Browse files
committed
ci: add remote HTTP build cache and Konan toolchain caching
- Add gradle/build-cache.settings.gradle (shared remote HTTP build cache), applied from settings.gradle.kts and configured from the GRADLE_CACHE_URL / GRADLE_CACHE_USERNAME / GRADLE_CACHE_PASSWORD secrets. Push is enabled only when credentials are present, so fork PRs are pull-only. - Cache ~/.konan (the Kotlin/Native toolchain) in CI, keyed on libs.versions.toml + the Gradle wrapper. The macOS build compiles nine native targets from a cold Konan on every run today; caching it avoids re-downloading the toolchain each time. Part of the Meshtastic KMP library standard alignment (CI caching). Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
1 parent 1bd9c84 commit 7722b73

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ concurrency:
1414
permissions:
1515
contents: read
1616

17+
env:
18+
GRADLE_CACHE_URL: ${{ secrets.GRADLE_CACHE_URL }}
19+
GRADLE_CACHE_USERNAME: ${{ secrets.GRADLE_CACHE_USERNAME }}
20+
GRADLE_CACHE_PASSWORD: ${{ secrets.GRADLE_CACHE_PASSWORD }}
21+
1722
jobs:
1823
build:
1924
name: Build, test & API check (all KMP targets)
@@ -34,6 +39,14 @@ jobs:
3439
- name: Setup Gradle
3540
uses: gradle/actions/setup-gradle@v6
3641

42+
- name: Cache Konan (Kotlin/Native toolchain)
43+
uses: actions/cache@v6
44+
with:
45+
path: ~/.konan
46+
key: konan-${{ runner.os }}-${{ hashFiles('gradle/libs.versions.toml', 'gradle/wrapper/gradle-wrapper.properties') }}
47+
restore-keys: |
48+
konan-${{ runner.os }}-
49+
3750
# `build` compiles all 13 targets, runs the common/jvm/js/wasm/macOS/iOS-sim
3851
# tests, and runs `apiCheck` (binary-compatibility-validator). Linux/Windows
3952
# native test binaries are cross-compiled but not executed on a macOS host.

gradle/build-cache.settings.gradle

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Shared remote HTTP Gradle build cache for Meshtastic KMP libraries.
3+
*
4+
* Credentials come from the GRADLE_CACHE_URL / GRADLE_CACHE_USERNAME /
5+
* GRADLE_CACHE_PASSWORD environment variables (CI secrets), or a
6+
* local.properties / config.properties entry for local use. Push is enabled
7+
* only when credentials are present, so fork PRs (which have no secrets) are
8+
* pull-only and cannot poison the cache.
9+
*/
10+
11+
def getMeshProperty(String key) {
12+
def env = System.getenv(key)
13+
if (env) return env
14+
def currentDir = settingsDir
15+
while (currentDir != null) {
16+
for (name in ["local.properties", "config.properties"]) {
17+
def f = new File(currentDir, name)
18+
if (f.exists()) {
19+
def props = new Properties()
20+
f.withInputStream { props.load(it) }
21+
if (props.containsKey(key)) return props.getProperty(key)
22+
}
23+
}
24+
currentDir = currentDir.parentFile
25+
}
26+
return null
27+
}
28+
29+
buildCache {
30+
local {
31+
enabled = true
32+
}
33+
remote(HttpBuildCache) {
34+
// Some cache servers return 403 on "Expect: 100-continue".
35+
useExpectContinue = false
36+
def cacheUrl = getMeshProperty("GRADLE_CACHE_URL")?.trim()
37+
def cacheUsername = getMeshProperty("GRADLE_CACHE_USERNAME")?.trim()
38+
def cachePassword = getMeshProperty("GRADLE_CACHE_PASSWORD")?.trim()
39+
if (cacheUrl) {
40+
url = cacheUrl.endsWith("/") ? cacheUrl : "${cacheUrl}/"
41+
if (cacheUsername && cachePassword) {
42+
credentials {
43+
username = cacheUsername
44+
password = cachePassword
45+
}
46+
}
47+
allowInsecureProtocol = true
48+
allowUntrustedServer = true
49+
// Push only when credentials exist -> fork PRs are pull-only.
50+
push = (cacheUsername && cachePassword)
51+
enabled = true
52+
} else {
53+
enabled = false
54+
}
55+
}
56+
}

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ pluginManagement {
66
}
77
}
88

9+
apply(from = "gradle/build-cache.settings.gradle")
10+
911
rootProject.name = "kzstd"

0 commit comments

Comments
 (0)