-
Notifications
You must be signed in to change notification settings - Fork 4.1k
chore(ci): implement best practices for CI caching #17873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ade40a1
6b2bcb4
951208b
0dd19a5
ef66fc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ jobs: | |
| matrix: | ||
| working_directory: | ||
| ['tests', 'packages/cloud_firestore/cloud_firestore/example'] | ||
| env: | ||
| AVD_ARCH: x86_64 | ||
| AVD_API_LEVEL: 34 | ||
| AVD_TARGET: google_apis | ||
| steps: | ||
| - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 | ||
| - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a | ||
|
|
@@ -43,11 +47,20 @@ jobs: | |
| with: | ||
| distribution: 'temurin' | ||
| java-version: '17' | ||
| - name: 'Install Tools' | ||
| run: | | ||
| sudo npm i -g firebase-tools | ||
| echo "FIREBASE_TOOLS_VERSION=$(npm firebase --version)" >> $GITHUB_ENV | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. discussion on how to share information between workflow steps, including syntax for command interpolation while setting an environment variable: https://stackoverflow.com/a/57989070/9910298 example output of command executed so you may verify it is valid for an environment variable (no spaces or similar): |
||
| - name: Firebase Emulator Cache | ||
| uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
| id: firebase-emulator-cache | ||
| uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. splitting to the separate restore/save actions vs the combo 'cache' action so we may restore every time but only save conditionally |
||
| continue-on-error: true | ||
| with: | ||
| # The firebase emulators are pure javascript and java, OS-independent | ||
| enableCrossOsArchive: true | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. documentation if interested https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache complete listing of files in |
||
| # Must match the save path exactly | ||
| path: ~/.cache/firebase/emulators | ||
| key: firebase-emulators-v3-${{ runner.os }} | ||
| key: firebase-emulators-v3-${{ env.FIREBASE_TOOLS_VERSION }} | ||
| restore-keys: firebase-emulators-v3 | ||
| - uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff | ||
| with: | ||
|
|
@@ -61,9 +74,6 @@ jobs: | |
| melos-version: '5.3.0' | ||
| - name: 'Bootstrap package' | ||
| run: melos bootstrap --scope tests && melos bootstrap --scope "cloud_firestore*" | ||
| - name: 'Install Tools' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to move tools install above tools cache restore so it could get the version for cache key |
||
| run: | | ||
| sudo npm i -g firebase-tools | ||
| - name: Start Firebase Emulator | ||
| run: cd ./.github/workflows/scripts && ./start-firebase-emulator.sh | ||
| - name: Enable KVM | ||
|
|
@@ -82,19 +92,21 @@ jobs: | |
| remove-docker-images: true | ||
| remove-large-packages: true | ||
| - name: AVD cache | ||
| uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
| uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
| continue-on-error: true | ||
| id: avd-cache | ||
| with: | ||
| # Must match the save path exactly | ||
| path: | | ||
| ~/.android/avd/* | ||
| ~/.android/adb* | ||
| key: avd-${{ runner.os }} | ||
| key: avd-${{ runner.os }}-${{ env.AVD_API_LEVEL }}-${{ env.AVD_TARGET }}-${{ env.AVD_ARCH }} | ||
| - name: Start AVD then run E2E tests | ||
| uses: reactivecircus/android-emulator-runner@v2 | ||
| uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. verify visually by noticing the |
||
| with: | ||
| api-level: 34 | ||
| target: google_apis | ||
| arch: x86_64 | ||
| api-level: ${{ env.AVD_API_LEVEL }} | ||
| target: ${{ env.AVD_TARGET }} | ||
| arch: ${{ env.AVD_ARCH }} | ||
| working-directory: ${{ matrix.working_directory }} | ||
| script: | | ||
| flutter test integration_test/e2e_test.dart --ignore-timeouts --dart-define=CI=true -d emulator-5554 | ||
|
|
@@ -103,3 +115,21 @@ jobs: | |
| # https://github.com/ReactiveCircus/android-emulator-runner/issues/385 | ||
| run: | | ||
| pgrep -f appium && pkill -f appium || echo "No Appium process found" | ||
| - name: Save Firestore Emulator Cache | ||
| # Branches can read main cache but main cannot read branch cache. Avoid LRU eviction with main-only cache. | ||
| if: github.ref == 'refs/heads/main' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. example of conditional step based on branch ref https://stackoverflow.com/a/58142412/9910298 |
||
| uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
| with: | ||
| key: ${{ steps.firebase-emulator-cache.outputs.cache-primary-key }} | ||
| # Must match the restore path exactly | ||
| path: ~/.cache/firebase/emulators | ||
| - name: Save Android Emulator Cache | ||
| # Branches can read main cache but main cannot read branch cache. Avoid LRU eviction with main-only cache. | ||
| if: github.ref == 'refs/heads/main' | ||
| uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 | ||
| with: | ||
| key: ${{ steps.avd-cache.outputs.cache-primary-key }} | ||
| # Must match the restore path exactly | ||
| path: | | ||
| ~/.android/avd/* | ||
| ~/.android/adb* | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env var used to follow "Don't Repeat Yourself" programming law since these values will be used both for cache key and emulator action now