feat(build): Add support for remote Gradle build cache (#4357)

This commit is contained in:
James Rich 2026-01-29 13:43:21 -06:00 committed by GitHub
parent 6665737c9b
commit fd3ad804fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 43 additions and 11 deletions

View file

@ -54,9 +54,7 @@ jobs:
with:
api_levels: '[35]' # Run only on API 35 for PRs
test_flavors: 'google' # Run only Google flavor for PRs (faster)
secrets:
GRADLE_ENCRYPTION_KEY: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
secrets: inherit
# This job handles the case when no code changes are detected (docs-only PRs)
skip-notice:

View file

@ -34,6 +34,8 @@ on:
required: true
GRADLE_ENCRYPTION_KEY:
required: true
GRADLE_CACHE_URL:
required: false
concurrency:
group: ${{ github.workflow }}-${{ inputs.tag_name }}
@ -144,6 +146,7 @@ jobs:
env:
VERSION_NAME: ${{ needs.prepare-build-info.outputs.APP_VERSION_NAME }}
VERSION_CODE: ${{ needs.prepare-build-info.outputs.APP_VERSION_CODE }}
GRADLE_CACHE_URL: ${{ secrets.GRADLE_CACHE_URL }}
run: bundle exec fastlane internal
- name: Upload Google AAB artifact
@ -213,6 +216,7 @@ jobs:
env:
VERSION_NAME: ${{ needs.prepare-build-info.outputs.APP_VERSION_NAME }}
VERSION_CODE: ${{ needs.prepare-build-info.outputs.APP_VERSION_CODE }}
GRADLE_CACHE_URL: ${{ secrets.GRADLE_CACHE_URL }}
run: bundle exec fastlane fdroid_build
- name: Upload F-Droid APK artifact

View file

@ -11,6 +11,8 @@ on:
required: false
CODECOV_TOKEN:
required: false
GRADLE_CACHE_URL:
required: false
inputs:
upload_artifacts:
description: 'Whether to upload build and Detekt artifacts'
@ -30,6 +32,7 @@ jobs:
DATADOG_APPLICATION_ID: ${{ secrets.DATADOG_APPLICATION_ID }}
DATADOG_CLIENT_TOKEN: ${{ secrets.DATADOG_CLIENT_TOKEN }}
MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
GRADLE_CACHE_URL: ${{ secrets.GRADLE_CACHE_URL }}
steps:

View file

@ -23,11 +23,15 @@ on:
required: false
CODECOV_TOKEN:
required: true
GRADLE_CACHE_URL:
required: false
jobs:
androidTest:
runs-on: ubuntu-latest
timeout-minutes: 45
env:
GRADLE_CACHE_URL: ${{ secrets.GRADLE_CACHE_URL }}
strategy:
matrix:
api-level: ${{ fromJson(inputs.api_levels) }} # Use the input to define the matrix

View file

@ -70,6 +70,26 @@ plugins {
id("com.gradle.common-custom-user-data-gradle-plugin") version "2.4.0"
}
fun Settings.getMeshProperty(key: String): String? {
val env = System.getenv(key)
if (!env.isNullOrBlank()) return env
val localFile = file("local.properties")
if (localFile.exists()) {
val props = java.util.Properties()
localFile.inputStream().use { props.load(it) }
if (props.containsKey(key)) return props.getProperty(key)
}
val configFile = file("config.properties")
if (configFile.exists()) {
val props = java.util.Properties()
configFile.inputStream().use { props.load(it) }
if (props.containsKey(key)) return props.getProperty(key)
}
return null
}
develocity {
buildScan {
capture {
@ -82,14 +102,17 @@ develocity {
isEnabled = true
}
remote(HttpBuildCache::class.java) {
isAllowInsecureProtocol = true
// Replace with your selfhosted instance address
// see: https://docs.gradle.org/current/userguide/build_cache.html#sec:build_cache_setup_http_backend
url = uri("http://192.168.1.3:5071/cache/")
// Allow this machine to upload results to the cache
isPush = true
val cacheUrl = getMeshProperty("GRADLE_CACHE_URL")?.trim()
if (!cacheUrl.isNullOrBlank()) {
println("Meshtastic Build: Remote cache URL found. Using remote build cache.")
url = uri(cacheUrl)
isAllowInsecureProtocol = true
isPush = true
isEnabled = true
} else {
println("Meshtastic Build: Remote cache URL not found. Disabling remote cache write.")
isEnabled = false
}
}
}
}