Skip to content

Commit 4cdbd58

Browse files
committed
dataconnect.yml: refactor, especially to have cache only saved on scheduled runs
1 parent 0170dc8 commit 4cdbd58

File tree

1 file changed

+52
-16
lines changed

1 file changed

+52
-16
lines changed

.github/workflows/dataconnect.yml

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ on:
1111
type: boolean
1212
pull_request:
1313
paths:
14-
- buildSrc/**
15-
- firebase-common/**
16-
- firebase-dataconnect/**
1714
- .github/workflows/dataconnect.yml
15+
- 'firebase-dataconnect/**'
16+
- '!firebase-dataconnect/demo/**'
17+
- '!firebase-dataconnect/scripts/**'
18+
- '!firebase-dataconnect/**/*.md'
19+
- '!firebase-dataconnect/**/*.txt'
1820
schedule:
1921
- cron: '0 11 * * *' # Run nightly at 11am UTC (3am Pacific, 6am Eastern)
2022

@@ -23,8 +25,8 @@ env:
2325
FDC_ANDROID_EMULATOR_API_LEVEL: ${{ inputs.androidEmulatorApiLevel || '34' }}
2426
FDC_NODEJS_VERSION: ${{ inputs.nodeJsVersion || '20' }}
2527
FDC_FIREBASE_TOOLS_VERSION: ${{ inputs.firebaseToolsVersion || '13.29.1' }}
26-
FDC_FIREBASE_TOOLS_DIR: ${{ github.workspace }}/firebase-tools
27-
FDC_FIREBASE_COMMAND: ${{ github.workspace }}/firebase-tools/node_modules/.bin/firebase
28+
FDC_FIREBASE_TOOLS_DIR: ${{ runner.temp }}/firebase-tools
29+
FDC_FIREBASE_COMMAND: ${{ runner.temp }}/firebase-tools/node_modules/.bin/firebase
2830

2931
concurrency:
3032
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -85,6 +87,15 @@ jobs:
8587
${{ env.FDC_FIREBASE_COMMAND }} --version
8688
./gradlew --version
8789
90+
- name: Restore Gradle cache
91+
uses: actions/cache/restore@v4
92+
if: github.event_name != 'schedule'
93+
with:
94+
path: |
95+
~/.gradle/caches
96+
~/.gradle/wrapper
97+
key: gradle-cache-jqnvfzw6w7
98+
8899
- name: Gradle assembleDebugAndroidTest
89100
run: |
90101
set -v
@@ -98,26 +109,34 @@ jobs:
98109
${{ (inputs.gradleInfoLog && '--info') || '' }} \
99110
:firebase-dataconnect:assembleDebugAndroidTest
100111
112+
- name: Save Gradle cache
113+
uses: actions/cache/save@v4
114+
if: github.event_name == 'schedule'
115+
with:
116+
path: |
117+
~/.gradle/caches
118+
~/.gradle/wrapper
119+
key: gradle-cache-jqnvfzw6w7
120+
101121
- name: Enable KVM group permissions for Android Emulator
102122
run: |
103123
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
104124
| sudo tee /etc/udev/rules.d/99-kvm4all.rules
105125
sudo udevadm control --reload-rules
106126
sudo udevadm trigger --name-match=kvm
107127
108-
- name: AVD cache
109-
uses: actions/cache@v4
128+
- name: Restore AVD cache
129+
uses: actions/cache/restore@v4
130+
if: github.event_name != 'schedule'
110131
id: avd-cache
111132
with:
112133
path: |
113134
~/.android/avd/*
114135
~/.android/adb*
115-
key: avd-cache-zhdsn586je-api${{ env.FDC_ANDROID_EMULATOR_API_LEVEL }}-ref${{ github.ref_name }}
116-
restore-keys: |
117-
avd-cache-zhdsn586je-api${{ env.FDC_ANDROID_EMULATOR_API_LEVEL }}-
136+
key: avd-cache-zhdsn586je-api${{ env.FDC_ANDROID_EMULATOR_API_LEVEL }}
118137

119-
- name: Create AVD and generate snapshot for caching
120-
if: steps.avd-cache.outputs.cache-hit != 'true'
138+
- name: Create AVD
139+
if: github.event_name == 'schedule' || steps.avd-cache.outputs.cache-hit != 'true'
121140
uses: reactivecircus/android-emulator-runner@v2
122141
with:
123142
api-level: ${{ env.FDC_ANDROID_EMULATOR_API_LEVEL }}
@@ -127,22 +146,32 @@ jobs:
127146
disable-animations: false
128147
script: echo "Generated AVD snapshot for caching."
129148

149+
- name: Save AVD cache
150+
uses: actions/cache/save@v4
151+
if: github.event_name == 'schedule'
152+
id: avd-cache
153+
with:
154+
path: |
155+
~/.android/avd/*
156+
~/.android/adb*
157+
key: avd-cache-zhdsn586je-api${{ env.FDC_ANDROID_EMULATOR_API_LEVEL }}
158+
130159
- name: Data Connect Emulator
131160
run: |
132161
set -x
133162
134-
echo "emulator.postgresConnectionUrl=postgresql://postgres:[email protected]:5432?sslmode=disable" > firebase-dataconnect/dataconnect.local.properties
163+
echo 'emulator.postgresConnectionUrl=postgresql://postgres:[email protected]:5432?sslmode=disable' > firebase-dataconnect/dataconnect.local.properties
135164
136165
./gradlew \
137166
${{ (inputs.gradleInfoLog && '--info') || '' }} \
138167
:firebase-dataconnect:connectors:runDebugDataConnectEmulator \
139-
2>&1 >dataconnect.emulator.log &
168+
2>&1 >firebase.emulator.dataconnect.log &
140169
141170
- name: Firebase Auth Emulator
142171
run: |
143172
set -x
144173
cd firebase-dataconnect/emulator
145-
${{ env.FDC_FIREBASE_COMMAND }} emulators:start --only=auth &
174+
${{ env.FDC_FIREBASE_COMMAND }} emulators:start --only=auth 2>&1 >firebase.emulator.auth.log &
146175
147176
- name: Gradle connectedCheck
148177
uses: reactivecircus/android-emulator-runner@v2
@@ -152,9 +181,16 @@ jobs:
152181
force-avd-creation: false
153182
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
154183
disable-animations: true
155-
script: set -x && ./gradlew --no-daemon ${{ (inputs.gradleInfoLog && '--info') || '' }} --profile :firebase-dataconnect:connectedCheck :firebase-dataconnect:connectors:connectedCheck
184+
script: |
185+
set -euox pipefail
186+
./gradlew \
187+
${{ (inputs.gradleInfoLog && '--info') || '' }} \
188+
--profile \
189+
:firebase-dataconnect:connectedCheck \
190+
:firebase-dataconnect:connectors:connectedCheck
156191
157192
- uses: actions/upload-artifact@v4
193+
if: true
158194
with:
159195
name: logs
160196
path: "**/*.log"

0 commit comments

Comments
 (0)