DEV Community

Will Ceolin
Will Ceolin

Posted on • Edited on

Caching the Firebase Emulator on GitHub Actions

When testing your Firebase application, you need to download the Firebase Emulator. Fortunately, firebase-tools does that automatically for you.

However, when running your tests on a continuous integration environment such as GitHub Actions, you'll see the following warning:

It appears you are running in a CI environment. You can avoid downloading the Pub/Sub Emulator repeatedly by caching the /home/runner/.cache/firebase/emulators directory.
Enter fullscreen mode Exit fullscreen mode

This means, firebase-tools is downloading the Emulator binary every time you run your CI pipeline. You can avoid this by caching the emulator instead:

jobs:
  test:
    runs-on: ubuntu-latest
    env: FIREBASE_EMULATORS_PATH: ${{ github.workspace }}/emulator-cache

    steps:
      - name: Cache firebase emulators
        uses: actions/cache@v2
        with:
          path: ${{ env.FIREBASE_EMULATORS_PATH }}
          key:
            ${{ runner.os }}-firebase-emulators-${{
            hashFiles('emulator-cache/**') }}
        continue-on-error: true
Enter fullscreen mode Exit fullscreen mode

The step above will cache the emulator on GitHub Actions. The next time you run your tests, Firebase won't download the emulator again (unless the binary changed).


Follow me on Twitter

Top comments (0)