如何使用 GitHub 操作缓存 firebase/emulators 目录
How to cache firebase/emulators directory using GitHub Actions
我正在使用 firebase 模拟器 运行 我的测试,我收到了关于使用缓存系统进行优化机会的警告。
我该怎么做?
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.
在 GitHub 操作中定义:
steps:
- uses: actions/checkout@v2
- name: Cache firebase emulators
uses: actions/cache@v2
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('~/.cache/firebase/emulators/**') }}
...
然后比如我们运行这个命令firebase emulators:exec --project example 'npm test'
时,如果模拟器不在缓存路径中,就会自动开始安装
第一个运行
- 缺少缓存
- 运行测试时下载模拟器
- 将缓存保存为 actions/cache
的 post 操作
第二个运行
- 找到并恢复了缓存,但没有下载。
如果你需要在 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 }}
我正在使用 firebase 模拟器 运行 我的测试,我收到了关于使用缓存系统进行优化机会的警告。
我该怎么做?
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.
在 GitHub 操作中定义:
steps:
- uses: actions/checkout@v2
- name: Cache firebase emulators
uses: actions/cache@v2
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('~/.cache/firebase/emulators/**') }}
...
然后比如我们运行这个命令firebase emulators:exec --project example 'npm test'
时,如果模拟器不在缓存路径中,就会自动开始安装
第一个运行
- 缺少缓存
- 运行测试时下载模拟器
- 将缓存保存为 actions/cache 的 post 操作
第二个运行
- 找到并恢复了缓存,但没有下载。
如果你需要在 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 }}