はじめに
GitHub ActionsでFirebaseにデプロイした時の遭遇した複数のエラーについて書いていきます。
前々回の記事はこちら
GitHub ActionsでCDした時に出たエラーその1 "Error: firebase use must be run from a Firebase project directory."
問題
このエラーメッセージは、Firebase CLI の webframeworks 実験機能が有効になっていないために発生しているようです。
Error: Cannot deploy a web framework from source because the experiment webframeworks is not enabled. To enable webframeworks run firebase experiments:enable webframeworks
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
- name: delete GOOGLE_APPLICATION_CREDENTIALS
run: rm $GOOGLE_APPLICATION_CREDENTIALS
if: ${{ always() }}
解決方法
Deploy to Firebase Hosting ステップの env セクションに FIREBASE_CLI_EXPERIMENTS: webframeworks
を追加しました。
これにより、webframeworks 実験機能が有効になります。
これで、GitHub Actions ワークフロー内で webframeworks 実験機能が有効になり、Firebase にデプロイできるようになります。
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
+ FIREBASE_CLI_EXPERIMENTS: webframeworks
run: |
./node_modules/.bin/firebase deploy
- name: delete GOOGLE_APPLICATION_CREDENTIALS
run: rm $GOOGLE_APPLICATION_CREDENTIALS
if: ${{ always() }}
おわりに
今回、FIREBASE_CLI_EXPERIMENTS: webframeworks
を追加して解決しましたが、このコード実は元々書いていたのですが、Firebaseの認証方法として設定していたFIREBASE_TOKEN
をGOOGLE_APPLICATION_CREDENTIALS
に修正した際に削除してしまっていたコードでした。
これは、コードを理解せずにやってしまっていた行為であり、次からはコードが分からなければをAIに聞くなどして、理解してから削除なりアクションをしようと思いました。
参考