Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 422
Rodrigo Avatar asked May 10 '26 06:05

Rodrigo


2 Answers

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.

First run

  1. Cache is missing

enter image description here

  1. Download emulator when running test

enter image description here

  1. Save cache as post action of actions/cache

enter image description here

Second run

  1. Cache is found and restored and download doesn't happen.

enter image description here

like image 121
banyan Avatar answered May 12 '26 10:05

banyan


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 }}
like image 31
malibeg Avatar answered May 12 '26 10:05

malibeg