1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

いままでfirebase-toolsを使ってReactのデプロイをしていたのですが、仕様が変わって困ったのでまとめます

問題

通常なら

$ firebase init
? Do you want to use a web framework? (experimental) (y/N) 

このように聞かれていたが、最新版のfirebaseをインストールしたら聞かれなくなってしまった

{
  "hosting": {
    "source": ".",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "frameworksBackend": {
      "region": "asia-east1"
    }
  }
}

このように普段なら設定していたのが使えなくなってしまったのでCDがうまくいかなくなった

解決方法

仕方ないので、

$ firebase init hositing
? What do you want to use as your public directory? dist
あとはEnter

そしてパイプラインではartifactでビルドしたディレクトリをデプロイのところにも共有するようにしたい

name: Scheduled deploy

on:
  push:
  workflow_dispatch:

env:
  VITE_SUPABASE_URL: ${{ secrets.VITE_SUPABASE_URL }}
  VITE_SUPABASE_ANON_KEY: ${{ secrets.VITE_SUPABASE_ANON_KEY }}

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
      - name: Archive production artifacts
        uses: actions/upload-artifact@v2
        with:
          name: dist
          path: dist

  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 Firebase project
        run: ./node_modules/.bin/firebase use ${{ secrets.FIREBASE_PROJECT_ID }}
      - name: Download artifact
        uses: actions/download-artifact@v2
        with:
          name: dist
          path: dist
      - name: Deploy to Firebase Hosting
        run: |
          ./node_modules/.bin/firebase deploy --only hosting
        env:
          FIREBASE_CLI_EXPERIMENTS: webframeworks
      - name: Delete service account key
        run: rm $GOOGLE_APPLICATION_CREDENTIALS
        if: ${{ always() }}

ちなみに何故前はdistの共有が不要だったかというと、firebase-toolsがbuildとdeployを同時にしてくれていたから

おわりに

仕様変更で困りましたが、パイプラインがより一般的な書き方になりました

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?