Skip to content

Commit 1564596

Browse files
committed
chore: use the shared setup-flutter action in the android build
The android workflow was setting up flutter its own way with subosito/flutter-action plus hand-rolled cache restore/save steps, duplicating what .github/actions/setup-flutter already does. Beyond the duplication, the hand-rolled cache never actually hit. Its keys were only ever written by this workflow, which runs on tags, and a tag push gets its own cache scope - so every release missed on restore and saved to a scope no later run could read. setup-flutter's keys are already warmed into master's scope by pr-check, so a release now picks them up. Also drops the second way of installing flutter from the repo. If fvm is going away it should go away everywhere at once, not one workflow at a time. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ks57GnHLcu8SQsUpGWKm8y
1 parent 08c69ce commit 1564596

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

.github/workflows/android-builds.yml

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ permissions:
2323
env:
2424
# Matches the pin in windows/build.ps1, linux/build.sh and the other workflows.
2525
FLUTTER_VERSION: "3.44.6"
26+
FVM_VERSION: "4.1.2"
2627
# Pinned by android/app/build.gradle; the runner image does not always carry it.
2728
ANDROID_NDK_VERSION: "28.2.13676358"
2829
# android/app/build.gradle compileSdk.
@@ -87,22 +88,24 @@ jobs:
8788
"platforms;android-${ANDROID_COMPILE_SDK}" \
8889
"ndk;${ANDROID_NDK_VERSION}"
8990
90-
# Skipping fvm here since there's no need to switch SDKs mid-job, but the version
91-
# is the same one the desktop builds pin.
92-
#
93-
# Nothing is cached in this workflow, including the action's own `cache` input.
94-
# This job signs and publishes a release binary, and cache entries are mutable
95-
# state that never shows up in git history, so a poisoned one would end up inside
96-
# a signed APK with nothing to review. Tag builds are rare enough that refetching
97-
# is cheap. (The `cache` input also delegates to a floating actions/cache@v3.)
91+
# Also resolves dependencies, so there's no separate pub get below.
9892
- name: Setup Flutter
99-
uses: subosito/flutter-action@1508160852fb97248640997f7cfb38da241df0ba
93+
uses: ./.github/actions/setup-flutter
10094
with:
10195
flutter-version: ${{ env.FLUTTER_VERSION }}
102-
channel: stable
96+
fvm-version: ${{ env.FVM_VERSION }}
10397

104-
- name: Pub get
105-
run: flutter pub get --enforce-lockfile
98+
- name: Restore Gradle cache
99+
id: cache-gradle
100+
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
101+
with:
102+
path: |
103+
~/.gradle/caches
104+
~/.gradle/wrapper
105+
key: gradle-${{ runner.os }}-${{ matrix.flavor }}-${{ hashFiles('android/**/*.gradle', 'android/gradle.properties', 'android/gradle/wrapper/gradle-wrapper.properties', 'pubspec.lock') }}
106+
restore-keys: |
107+
gradle-${{ runner.os }}-${{ matrix.flavor }}-
108+
gradle-${{ runner.os }}-
106109
107110
# pubspec.yaml declares .env as an asset, so the build fails without it. The key
108111
# itself is desktop-only - dotenv.load() is behind `if (kIsDesktop)` in main.dart
@@ -137,7 +140,7 @@ jobs:
137140
echo "keyPassword=$(esc "$KEY_PASSWORD")"
138141
} > android/key.properties
139142
140-
# --no-pub: reuse the lockfile-enforced resolution from the Pub get step.
143+
# --no-pub: reuse the lockfile-enforced resolution from the Setup Flutter step.
141144
# Has to go through the flutter tool rather than gradlew directly - flutter build
142145
# is what refreshes android/local.properties with flutter.versionCode from
143146
# pubspec.yaml, and build.gradle folds that into the final versionCode.
@@ -147,17 +150,23 @@ jobs:
147150
# fallback into a hard error.
148151
env:
149152
BB_REQUIRE_RELEASE_SIGNING: "true"
150-
run: flutter build ${{ matrix.target }} --release --flavor ${{ matrix.flavor }} --no-pub
153+
run: fvm flutter build ${{ matrix.target }} --release --flavor ${{ matrix.flavor }} --no-pub
151154

152-
# The keystore is only needed by the gradle build above. Drop it before any
153-
# third-party action runs, so a compromised upload/release action cannot read it
154-
# off the workspace.
155-
# Drop the keystore before any third-party action runs.
155+
# Only the gradle build needs the keystore, so drop it before anything else runs.
156156
- name: Remove signing material
157157
if: always()
158158
run: |
159159
rm -f android/key.properties "$RUNNER_TEMP/release-keystore.jks"
160160
161+
- name: Save Gradle cache
162+
if: steps.cache-gradle.outputs.cache-hit != 'true'
163+
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
164+
with:
165+
path: |
166+
~/.gradle/caches
167+
~/.gradle/wrapper
168+
key: ${{ steps.cache-gradle.outputs.cache-primary-key }}
169+
161170
# Flutter lower-cases the flavor for APK filenames but not for bundle paths, and
162171
# that has moved around between versions, so find the file rather than hardcoding
163172
# the name. One variant per job means exactly one match.

0 commit comments

Comments
 (0)