はじめに
GitHub ActionsでFirebaseにデプロイした時の遭遇した複数のエラーについて書いていきます。
前回の記事はこちら
GitHub ActionsでCDした時に出たエラーその1 "Error: firebase use must be run from a Firebase project directory."
問題
エラーメッセージ その2
Authenticating with `FIREBASE_TOKEN` is deprecated and will be removed in a future major version of `firebase-tools`. Instead, use a service account key with `GOOGLE_APPLICATION_CREDENTIALS`: https://cloud.google.com/docs/authentication/getting-started
Error: Assertion failed: resolving hosting target of a site with no site name or target name. This should have caused an error earlier
main.yml
name: Scheduled deploy
on:
push:
workflow_dispatch:
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "18"
- name: Install dependencies
run: npm install
- name: Run build
run: npm run build
deploy:
name: deploy
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js and cache
uses: actions/setup-node@v2
with:
node-version: "18"
cache: "npm"
- name: Install firebase-tools
run: npm install --save-dev firebase-tools
- name: Decode Firebase service account key
run: |
echo "${{ secrets.FIREBASE_KEY }}" | base64 -d > ./firebase-key.json
echo "GOOGLE_APPLICATION_CREDENTIALS=${{ github.workspace }}/firebase-key.json" >> $GITHUB_ENV
- name: change space
run: ./node_modules/.bin/firebase use ${{ secrets.FIREBASE_PROJECT_ID }}
- name: Deploy to Firebase Hosting
run: |
./node_modules/.bin/firebase deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} #問題箇所
FIREBASE_CLI_EXPERIMENTS: webframeworks
- name: delete GOOGLE_APPLICATION_CREDENTIALS
run: rm $GOOGLE_APPLICATION_CREDENTIALS
if: ${{ always() }}
解決方法
エラーメッセージ1:認証方法について
Authenticating with `FIREBASE_TOKEN` is deprecated and will be removed in a future major version of `firebase-tools`. Instead, use a service account key with `GOOGLE_APPLICATION_CREDENTIALS`: https://cloud.google.com/docs/authentication/getting-started
日本語訳
`FIREBASE_TOKEN`での認証は非推奨で、将来的なメジャーバージョンで削除されます。
代わりに、`GOOGLE_APPLICATION_CREDENTIALS`を使用してください: https://cloud.google.com/docs/authentication/getting-started
main.yml
name: Scheduled deploy
on:
push:
workflow_dispatch:
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "18"
- name: Install dependencies
run: npm install
- name: Run build
run: npm run build
deploy:
name: deploy
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js and cache
uses: actions/setup-node@v2
with:
node-version: "18"
cache: "npm"
- name: Install firebase-tools
run: npm install --save-dev firebase-tools
- name: Decode Firebase service account key
run: |
echo "${{ secrets.FIREBASE_KEY }}" | base64 -d > ./firebase-key.json
echo "GOOGLE_APPLICATION_CREDENTIALS=${{ github.workspace }}/firebase-key.json" >> $GITHUB_ENV
- name: change space
run: ./node_modules/.bin/firebase use ${{ secrets.FIREBASE_PROJECT_ID }}
- name: Deploy to Firebase Hosting
+ env:
+ GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/firebase-key.json
run: |
./node_modules/.bin/firebase deploy
- env:
- FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
- FIREBASE_CLI_EXPERIMENTS: webframeworks
- name: delete GOOGLE_APPLICATION_CREDENTIALS
run: rm $GOOGLE_APPLICATION_CREDENTIALS
if: ${{ always() }}
認証の詳細については以下にある参考記事を見ると分かりやすいです。
エラーメッセージ2:Firebaseのホスティングについて
Error: Assertion failed: resolving hosting target of a site with no site name or target name. This should have caused an error earlier
ここでややこしいのですが、修正したエラーをまとめてpushするべきだったのですが、認証方法の修正のみをしてpushしてしまい上記のエラーメッセージが、以下のエラーメッセージに変わりました。
エラーメッセージ2-1:Firebaseのホスティングについてのエラーが認証方法のみを修正してpushすると以下のエラーに変わった
Error: Directory 'dist' for Hosting does not exist.
このエラーについては以下のように修正しました。
firebase.json
{
"hosting": {
- "public": "dist",
+ "source": ".",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
おわりに
今回もChatGPTやCopilotを使用してエラーの修正をしていました。
AIからもらう回答について抽象的なところがあり、Qiitaの記事とAIを行き来しながら修正していましたが解決できてよかったです。
参考