1
0

Github Actionsからfirebase-toolsを利用してhosting:disableする

Last updated at Posted at 2024-04-27

はじめに

タイトル通りです。
作った背景は、firebase hostingで遊んでてdisableにするのを忘れた時でも、外出中にGithubのモバイルアプリからActionを起動してdisableにできたらいいなと思ってたからです。

また、firebase-toolsをGithub Actionsから利用できれば便利なので共有です。

※DeprecatedなfirebaseのToken利用です。

実装

コード

.github/workflows/hosting-disable.yml
name: hosting disable
on: workflow_dispatch
jobs:
  disable_hosting:
    permissions: write-all
    runs-on: ubuntu-latest
    env:
      FIREBASE_TOOLS_VERSION: 13.3.0
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v3
        with:
          version: 9.0.6
      # cacheするほどでもないけど
      - name: cache global node_modules
        id: cache-global-node-modules
        uses: actions/cache@v4
        with:
          # NOTE: pathの参考
          # ```bash
          # which firebase
          # /home/runner/setup-pnpm/node_modules/.bin/firebase
          # ```
          path: |
            /home/runner/setup-pnpm/node_modules
          key: ${{ runner.os }}-disable_hosting-cache-global-node-modules_firebase-tools@${{env.FIREBASE_TOOLS_VERSION}}
      - if: steps.cache-global-node-modules.outputs.cache-hit != 'true'
        run: pnpm add -g firebase-tools@${{ env.FIREBASE_TOOLS_VERSION }}
      - run: firebase hosting:disable --force --project ${PROJECT_NAME} --token "${FIREBASE_TOKEN}"
        env:
          PROJECT_NAME: ${{ vars.FIREBASE_PROJECT_NAME }}
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

準備

1.firebaseのTokenを取得して、Github Actionsのsecretsに設定します

firebase login:ci

2.firebaseのプロジェクト名をGithub Actionsのvarsに設定します

おわりに

以上です。

firebaseのToken利用はDeprecatedなので、将来は利用できなくなるかもしれません…。こちらの記事で紹介されている通りにfirebaseのToken利用から移行したいです。

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