I am using the firebase emulator to run my tests and, I received a warning about a chance of optimization using the cache system.
How I can do this?
It appears you are running in a CI environment. You can avoid downloading the Firestore Emulator repeatedly by caching the /home/runner/.cache/firebase/emulators directory.
Define this in GitHub Actions:
steps:
- uses: actions/checkout@v2
- name: Cache firebase emulators
uses: actions/cache@v4
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-emulators-${{ github.sha }}
restore-keys: |
${{ runner.os }}-firebase-emulators-
Then, for example, when we run this command firebase emulators:exec --project example 'npm test', if the emulator is not in the cache path, it will automatically start installing.




If you need to update tool when npm package updates use something like this:
- name: Get Library Versions For Binary Caching
id: cache-settings
run: |
echo "::set-output name=firebase-tools::$(yarn list -s --depth=0 --pattern firebase-tools | tail -n 1 | sed 's/.*@//g')"
echo "::set-output name=firebase-tools::$(npm list -s --depth=0 | grep firebase-tools | tail -n 1 | sed 's/.*@//g')"
- name: Cache Firebase Emulator Binaries
uses: actions/[email protected]
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-${{ steps.cache-settings.outputs.firebase-tools }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With