1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Firebase】FIREBASE_TOKENを作成して、GitHubActionsで使用する

Posted at

はじめに

GitHubActionsでFirebaseのデプロイフローを作成中、FIREBASE_TOKENの設定方法を忘れていました。
今後もスムーズにできるよう備忘録として残します。

作成したワークフロー

最後の行に記載のsecrets.FIREBASE_TOKENの取得と、設定を行います

main.yml
name: CiCd

on: push

jobs:
  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: "20"
      - name: Install dependencies
        run: npm install
      - name: Run build
        run: npm run build
      - name: Archive Production Artifact
        uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist

  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: "20"
      - name: Install dependencies
        run: npm install
      - name: Run test
        run: npm run test

  deploy:
    runs-on: ubuntu-latest
    needs: build # buildジョブが完了してから実行
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: "20"
      - name: Install dependencies
        run: npm install
      - name: Download Artifact
        uses: actions/download-artifact@v4
        with:
          name: dist
          path: dist
      - name: Deploy to Firebase
        uses: joinflux/firebase-tools@v9.16.0
        with:
          args: deploy --project=new-study-record --only hosting
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}


FIREBASE_TOKENの作成

  • FIREBASE_TOKENを作成する
# Firebase CLIにログインする
$ firebase login

# CIサービス用のトークンを生成する
$ firebase login:ci
  • firebase login:ci を実行すると、「コマンドラインは非インタラクティブモードで実行されています」という警告が表示されます。
    表示されたURLをクリックして、ブラウザでの認証に進みます。この画面では、赤枠で囲まれたURLが認証ページへのリンクです

image.png

  • Googleアカウントにログイン、リクエストの許可を行う

image.png

  • トークンが生成されるので、コピーする
    この時、トークンはターミナルに直接表示されます。秘密情報として取り扱ってください。

image.png

GitHubへFIREBASE_TOKENを登録

  • GitHubのリポジトリページから
    SettingsSecrets and variablesActionsを選択
    New repository secret押下

image.png

  • FIREBASE_TOKENを登録する
    Name:FIREBASE_TOKEN
    Secret: コピーしたシークレットキー

image.png

Add secretで追加

image.png

おわりに

以前も同じ個所で調べて解決しましたが、まとめなかったため、また調べるという作業が発生してしまいました。
こまめに記事にして同じことを繰り返さないようにしたいです。

参考

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?