From 8db6e1a3910adb32d242e144e395582e0476fe7a Mon Sep 17 00:00:00 2001 From: James Newman Date: Wed, 29 Jul 2026 15:51:09 -0400 Subject: [PATCH] ci: make Gradle caching work by running the suite on main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No Gradle cache entry has ever existed for this repo. The unit-test job reported "116 actionable tasks: 116 executed" and re-downloaded the Gradle distribution every run; the instrumented jobs logged "Gradle User Home cache not found. Will initialize empty." on every run. The cause was structural. setup-gradle is read-only off the default branch and an entry written on a PR ref is visible only to that PR, but this workflow only ran on pull_request and workflow_dispatch — so no run was ever permitted to write the cache that PR jobs need to read. Adding readers to a cache with no writer changes nothing. - Run this workflow on pushes to main, matching the other Rokt Android repos. Main runs are permitted to write, so the normal suite populates the cache. - Gate the four jobs that require a pull request context to pull_request only: trunk-check (check-mode: pull_request), pr-check-hadcoded-secrets, security-checks (diff-aware against a base branch) and automerge-dependabot (reads the PR number). kit-compatibility-test and pr-notify were already gated. - Add setup-gradle to the remaining Gradle jobs, and replace the end-of-life gradle/gradle-build-action@v2.9.0 in instrumented-tests.yml. - Keep cache-read-only on build-kits.yml and instrumented-tests.yml. build-kits has an internal matrix over 22 kits and setup-gradle keys entries per job invocation, so leaving those writable would push one entry per kit per run. - Enable org.gradle.caching so task outputs are reused, not just dependencies. - Pass --no-build-cache on every publish invocation in release-publish.yml and release-draft.yml, so released artifacts are always built from scratch rather than assembled from cached task outputs. Because the macOS lint jobs now also run on main, they write the macOS/arm64 key their PR-side counterparts restore, so those jobs benefit too. Verified locally that the build cache is correct and effective: a populate pass took 2m55s ("40 executed, 2 from cache"), then a clean and rebuild took 3s ("12 executed, 23 from cache, 7 up-to-date") with compileReleaseKotlin, compileReleaseJavaWithJavac and minifyReleaseWithR8 all FROM-CACHE. Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/build-kits.yml | 5 +++++ .github/workflows/instrumented-tests.yml | 6 ++++-- .github/workflows/pull-request.yml | 19 ++++++++++++++++++- .github/workflows/release-draft.yml | 2 +- .github/workflows/release-publish.yml | 10 +++++----- gradle.properties | 1 + 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-kits.yml b/.github/workflows/build-kits.yml index 7bcd88c5f..71ed080e7 100644 --- a/.github/workflows/build-kits.yml +++ b/.github/workflows/build-kits.yml @@ -44,6 +44,11 @@ jobs: distribution: zulu java-version: "17" + - name: Setup Gradle + uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2 + with: + cache-read-only: true + - name: Publish core SDK to Maven Local run: ./gradlew publishMavenPublicationToMavenLocal diff --git a/.github/workflows/instrumented-tests.yml b/.github/workflows/instrumented-tests.yml index 1d6e3bbd5..acb6c95b1 100644 --- a/.github/workflows/instrumented-tests.yml +++ b/.github/workflows/instrumented-tests.yml @@ -38,8 +38,10 @@ jobs: with: distribution: "zulu" java-version: "17" - - name: Gradle cache - uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a #v2.9.0 + - name: "Setup Gradle" + uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2 + with: + cache-read-only: true # AVD cache disabled: causes indefinite hangs on emulator shutdown (see # ReactiveCircus/android-emulator-runner#373, #385, #362; WordPress/gutenberg#66771) - name: Enable KVM group perms diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 95135f56a..4073d9946 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,6 +1,11 @@ name: "Build and Test" -on: [workflow_dispatch, pull_request] +on: + push: + branches: + - main + pull_request: + workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -17,6 +22,7 @@ jobs: trunk-check: name: Trunk code check runs-on: ubuntu-latest + if: github.event_name == 'pull_request' steps: - name: Checkout uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 @@ -26,6 +32,7 @@ jobs: check-mode: pull_request pr-check-hadcoded-secrets: name: "Check PR for hardcoded secrets" + if: github.event_name == 'pull_request' uses: mParticle/mparticle-workflows/.github/workflows/security-hardcoded-secrets.yml@main instrumented-core: @@ -75,6 +82,8 @@ jobs: with: distribution: "zulu" java-version: "17" + - name: "Setup Gradle" + uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2 - name: "Run Unit Tests" run: ./gradlew test - name: "Print Android Unit Tests Report" @@ -101,6 +110,8 @@ jobs: with: distribution: "zulu" java-version: "17" + - name: "Setup Gradle" + uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2 - name: "Run Android Core SDK Lint" run: ./gradlew lint - name: "Setup Android Kit Lint" @@ -128,6 +139,8 @@ jobs: with: distribution: "zulu" java-version: "17" + - name: "Setup Gradle" + uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2 - name: "Run Android Core SDK Kotlin Lint" run: ./gradlew ktlintCheck - name: "Setup Android Kit Kotlin Lint" @@ -143,6 +156,7 @@ jobs: security-checks: name: "Security Lint Checks" + if: github.event_name == 'pull_request' uses: mparticle/mparticle-workflows/.github/workflows/security-checks.yml@main with: base_branch: main @@ -164,6 +178,8 @@ jobs: with: distribution: "zulu" java-version: "17" + - name: "Setup Gradle" + uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2 - name: "Generate Core Release Build" run: ./gradlew publishMavenPublicationToMavenLocal - name: "Run Kit-Base Release Tests and Build" @@ -179,6 +195,7 @@ jobs: automerge-dependabot: name: "Save PR Number for Dependabot Automerge" + if: github.event_name == 'pull_request' needs: [ instrumented-core, diff --git a/.github/workflows/release-draft.yml b/.github/workflows/release-draft.yml index e8fd2955a..eede09100 100644 --- a/.github/workflows/release-draft.yml +++ b/.github/workflows/release-draft.yml @@ -113,7 +113,7 @@ jobs: echo "${{ steps.compose-version.outputs.new-version }}" > VERSION - name: Publish to Maven local (smoke test) - run: ./gradlew publishMavenPublicationToMavenLocal -PVERSION=${{ steps.compose-version.outputs.new-version }} + run: ./gradlew publishMavenPublicationToMavenLocal -PVERSION=${{ steps.compose-version.outputs.new-version }} --no-build-cache - name: Generate changelog entry id: changelog diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index a7398fa37..63534c330 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -54,13 +54,13 @@ jobs: uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2 - name: Publish core to Maven local (required before kits can compile) - run: ./gradlew publishMavenPublicationToMavenLocal -PVERSION=${{ needs.setup-and-version.outputs.final_version }} + run: ./gradlew publishMavenPublicationToMavenLocal -PVERSION=${{ needs.setup-and-version.outputs.final_version }} --no-build-cache - name: Publish core to Maven Central - run: ./gradlew publishMavenPublicationToMavenCentralRepository -PVERSION=${{ needs.setup-and-version.outputs.final_version }} + run: ./gradlew publishMavenPublicationToMavenCentralRepository -PVERSION=${{ needs.setup-and-version.outputs.final_version }} --no-build-cache - name: Publish kits to Maven Central - run: ./gradlew publishMavenPublicationToMavenCentralRepository -PVERSION=${{ needs.setup-and-version.outputs.final_version }} -c settings-kits.gradle + run: ./gradlew publishMavenPublicationToMavenCentralRepository -PVERSION=${{ needs.setup-and-version.outputs.final_version }} -c settings-kits.gradle --no-build-cache # rokt-sdk-plus (com.rokt:rokt-sdk-plus) is an umbrella over the mParticle Rokt kit + the # Rokt Payment Extension. The "Publish core to Maven local" step above already placed @@ -69,7 +69,7 @@ jobs: # Maven Central propagation. com.rokt:payment-extension (+ roktsdk) come from Central, # released independently from the ROKT sdk-android-source repo. - name: Publish Rokt kit to Maven local (so rokt-sdk-plus resolves it locally) - run: ./gradlew :kits:android-rokt:rokt:publishMavenPublicationToMavenLocal -PVERSION=${{ needs.setup-and-version.outputs.final_version }} -c settings-kits.gradle + run: ./gradlew :kits:android-rokt:rokt:publishMavenPublicationToMavenLocal -PVERSION=${{ needs.setup-and-version.outputs.final_version }} -c settings-kits.gradle --no-build-cache # Published under the com.rokt namespace, so this step signs with the Rokt signing key. # The Sonatype account is shared with the com.mparticle publish (that account owns both @@ -80,7 +80,7 @@ jobs: ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ROKT_MAVEN_CENTRAL_SIGNING_KEY_PASSWORD }} ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} - run: ./gradlew publishMavenPublicationToMavenCentralRepository -PVERSION=${{ needs.setup-and-version.outputs.final_version }} -c settings-rokt-sdk-plus.gradle + run: ./gradlew publishMavenPublicationToMavenCentralRepository -PVERSION=${{ needs.setup-and-version.outputs.final_version }} -c settings-rokt-sdk-plus.gradle --no-build-cache - name: Create GitHub release uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0 diff --git a/gradle.properties b/gradle.properties index 444938580..e0d20bf41 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,7 @@ android.useAndroidX=true org.gradle.daemon=true org.gradle.jvmargs=-Xmx2560m #-XX:ThreadStackSize=4096 -XX:CompilerThreadStackSize=4096 +org.gradle.caching=true android.defaults.buildfeatures.buildconfig=true systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true JAVA_VERSION=17