Skip to content

Commit 06f6265

Browse files
jamesarichclaude
andcommitted
ci(kmp): add remote HTTP build cache and Konan toolchain caching
- Add packages/kmp/gradle/build-cache.settings.gradle (shared remote HTTP build cache), applied from packages/kmp/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 and cannot poison the cache. - Pass GRADLE_CACHE_* to the KMP CI, snapshot, and publish workflows. - Cache ~/.konan across those workflows — each compiles all 14 KMP targets (including native) on macOS from a cold Konan today. Part of the Meshtastic KMP library standard alignment (CI caching). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b73e5ad commit 06f6265

5 files changed

Lines changed: 105 additions & 0 deletions

File tree

.github/workflows/kmp-pull-request.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ on:
1010
permissions:
1111
contents: read
1212

13+
env:
14+
GRADLE_CACHE_URL: ${{ secrets.GRADLE_CACHE_URL }}
15+
GRADLE_CACHE_USERNAME: ${{ secrets.GRADLE_CACHE_USERNAME }}
16+
GRADLE_CACHE_PASSWORD: ${{ secrets.GRADLE_CACHE_PASSWORD }}
17+
1318
jobs:
1419
build-kmp:
1520
runs-on: macos-latest
@@ -29,5 +34,13 @@ jobs:
2934
- name: Setup Gradle
3035
uses: gradle/actions/setup-gradle@v6
3136

37+
- name: Cache Konan (Kotlin/Native toolchain)
38+
uses: actions/cache@v6
39+
with:
40+
path: ~/.konan
41+
key: konan-${{ runner.os }}-${{ hashFiles('packages/kmp/build.gradle.kts', 'packages/kmp/gradle/wrapper/gradle-wrapper.properties') }}
42+
restore-keys: |
43+
konan-${{ runner.os }}-
44+
3245
- name: Build KMP package
3346
run: packages/kmp/gradlew --no-daemon -p packages/kmp build -PVERSION_NAME=0.0.0-pr

.github/workflows/publish-kmp.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ on:
1919
permissions:
2020
contents: read
2121

22+
env:
23+
GRADLE_CACHE_URL: ${{ secrets.GRADLE_CACHE_URL }}
24+
GRADLE_CACHE_USERNAME: ${{ secrets.GRADLE_CACHE_USERNAME }}
25+
GRADLE_CACHE_PASSWORD: ${{ secrets.GRADLE_CACHE_PASSWORD }}
26+
2227
jobs:
2328
build-kmp:
2429
runs-on: macos-latest
@@ -59,6 +64,14 @@ jobs:
5964
- name: Setup Gradle
6065
uses: gradle/actions/setup-gradle@v6
6166

67+
- name: Cache Konan (Kotlin/Native toolchain)
68+
uses: actions/cache@v6
69+
with:
70+
path: ~/.konan
71+
key: konan-${{ runner.os }}-${{ hashFiles('packages/kmp/build.gradle.kts', 'packages/kmp/gradle/wrapper/gradle-wrapper.properties') }}
72+
restore-keys: |
73+
konan-${{ runner.os }}-
74+
6275
- name: Build KMP package
6376
run: packages/kmp/gradlew --no-daemon -p packages/kmp clean build -PVERSION_NAME=${{ steps.version.outputs.VERSION }}
6477

@@ -87,6 +100,14 @@ jobs:
87100
- name: Setup Gradle
88101
uses: gradle/actions/setup-gradle@v6
89102

103+
- name: Cache Konan (Kotlin/Native toolchain)
104+
uses: actions/cache@v6
105+
with:
106+
path: ~/.konan
107+
key: konan-${{ runner.os }}-${{ hashFiles('packages/kmp/build.gradle.kts', 'packages/kmp/gradle/wrapper/gradle-wrapper.properties') }}
108+
restore-keys: |
109+
konan-${{ runner.os }}-
110+
90111
- name: Publish to Maven Central
91112
env:
92113
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}

.github/workflows/snapshot-kmp.yml

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

18+
env:
19+
GRADLE_CACHE_URL: ${{ secrets.GRADLE_CACHE_URL }}
20+
GRADLE_CACHE_USERNAME: ${{ secrets.GRADLE_CACHE_USERNAME }}
21+
GRADLE_CACHE_PASSWORD: ${{ secrets.GRADLE_CACHE_PASSWORD }}
22+
1823
jobs:
1924
publish-snapshot:
2025
runs-on: macos-latest
@@ -36,6 +41,14 @@ jobs:
3641
- name: Setup Gradle
3742
uses: gradle/actions/setup-gradle@v6
3843

44+
- name: Cache Konan (Kotlin/Native toolchain)
45+
uses: actions/cache@v6
46+
with:
47+
path: ~/.konan
48+
key: konan-${{ runner.os }}-${{ hashFiles('packages/kmp/build.gradle.kts', 'packages/kmp/gradle/wrapper/gradle-wrapper.properties') }}
49+
restore-keys: |
50+
konan-${{ runner.os }}-
51+
3952
- name: Set version name
4053
run: |
4154
# Name the snapshot after the latest tag (v-stripped), the commit count
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+
}

packages/kmp/settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ dependencyResolutionManagement {
1313
}
1414
}
1515

16+
apply(from = "gradle/build-cache.settings.gradle")
17+
1618
rootProject.name = "protobufs"

0 commit comments

Comments
 (0)