GitHub ActionsでのFirestore Rulesテストがエラーになる

公開日時

GitHub Actionsを使ってFirestore Rulesのテストを実行するようにしている。

yarn run firebase emulators:exec --only firestore "yarn test"

Firebase Emulator SuiteのDocker対応を行ったあとから、このテストが失敗するようになってしまった。

Actionsのログには↓が記録されていた。

@firebase/firestore: Firestore (8.3.2): Could not reach Cloud Firestore backend.
Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment.
The client will operate in offline mode until it is able to successfully connect to the backend.

ローカルで実行すると問題なくテストが完了していたため、Actionsでのみ起こるエラーの模様。

firebase.json"host": "0.0.0.0" を設定したのが怪しいと思い、この設定をなくしたところActionsでもエラーなく実行できるようになった。

とはいえDocker利用時にはhost設定が必要になるので、 firebase.json をコピーして firebase.test.json を作成し、Actionsの実行時に firebase.json として上書きするようにした。

// firebase.test.json
{
  // ...
  "emulators": {
    "auth": {
      "port": 9099
    },
    "functions": {
      "port": 5001
    },
    "firestore": {
      "port": 8080
    },
    "hosting": {
      "port": 5000
    },
    "ui": {
      "enabled": true
    }
  }
}

.github/workflows/test.yml でのtest実行前にcpを追加。

name: test
'on':
  push:
    branches:
      - main
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: yarn
      - run: cp ./firebase.test.json ./firebase.json
      - run: yarn run firebase emulators:exec --only firestore "yarn test --forceExit"

これでDocker環境を維持しつつ、GitHub Actionsでのテストも実行できるようになった。

補足

本来であれば1分ほどでActionsの実行は完了するはずだが、エラー発生時のActionsの実行時間は 3h 11m 31s となっていた。

今回のエラーは早めに気づけたものの、今後別のエラーが起きた際にGitHub Actionsの実行時間枠を無駄に消費するのを避けるため yarn test 実行時に --forceExit を設定することにした。


Related #firebase

Firestoreの複合インデックスを削除する

CLI経由で削除する必要があった

Firebase Web SDK v9

_this.auth.addAuthTokenListener is not a function

8.6.5にダウングレードした

Firebase Summit 2021