Search code examples
github-actionsfirebase-tools

How to cache firebase/emulators directory using GitHub Actions


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.


Solution

  • 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/cache@v2.1.2
        with:
          path: ~/.cache/firebase/emulators
          key: ${{ runner.os }}-firebase-${{ steps.cache-settings.outputs.firebase-tools }}