如何使用 GitHub Actions 缓存 firebase/emulators 目录

Skh*_*haz 8 firebase-tools github-actions

我正在使用 firebase 模拟器来运行测试,并且收到了有关使用缓存系统进行优化的警告。

我怎样才能做到这一点?

看起来您正在 CI 环境中运行。您可以通过缓存 /home/runner/.cache/firebase/emulators 目录来避免重复下载 Firestore 模拟器。

ban*_*yan 16

在 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-
Run Code Online (Sandbox Code Playgroud)

然后,例如,当我们运行此命令时firebase emulators:exec --project example 'npm test',如果模拟器不在缓存路径中,它将自动开始安装。

第一次运行

  1. 缓存丢失

在此输入图像描述

  1. 运行测试时下载模拟器

在此输入图像描述

  1. 将缓存保存为 actions/cache 的后操作

在此输入图像描述

第二次运行

  1. 找到并恢复缓存,但不会发生下载。

在此输入图像描述

  • 我建议使用 ```key: ${{ runner.os }}-firebase-emulators-${{ github.sha }} Restore-keys: | ${{ runner.os }}-firebase-emulators- ```。由于 github 缓存是不可变的,并且 `${{ hashFiles('~/.cache/firebase/emulators/**') }}` 在第一次尝试时不会返回任何内容,因此稍后只会缓存模拟器的第一个版本并且不考虑所使用的模拟器的变化或版本更新。 (6认同)

mal*_*beg 4

如果您需要在 npm 包更新时更新工具,请使用如下内容:

- 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 }}
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

2011 次

最近记录:

1 年,9 月 前