Skip to content

Conversation

mafreud
Copy link
Contributor

@mafreud mafreud commented Oct 3, 2025

Summary by CodeRabbit

  • 新機能: なし
  • バグ修正: なし
  • リファクタリング
    • デプロイワークフローを整理し、プレビュー(PR)と本番(push)で参照する認証情報とプロジェクト指定を明確化。
    • 設定参照の扱いを統一し、保守性と一貫性を向上。
  • チョア
    • PR時はプレビュー環境へ、push時は本番環境へ自動デプロイされるよう運用を整備。
    • 開発用の認証ファイルを無視対象に追加し、機密情報の管理を強化。

Copy link

linear bot commented Oct 3, 2025

Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

GitHub Actions の Firebase Functions デプロイワークフローを PR(preview)と push(production)で分岐させ、各パスで使用するシークレットと環境変数、デプロイ手順(checkout, node setup, auth via secret env, npm install, firebase deploy)を分離・明示的に切り替える変更を加えた。加えて functions 配下の .gitignore に service_account_dev.json を追加した。

Changes

Cohort / File(s) Summary of changes
GitHub Actions: デプロイワークフロー(dev / production に分離)
.github/workflows/github-apps-cd.yml
- 既存 deploy-firebase-functions を PR 用 deploy-firebase-functions-devif: github.event_name == 'pull_request')と push 用 deploy-firebase-functions-productionif: github.event_name == 'push')に分割
- PR パスは FIREBASE_SA_KEY_FOR_PREVIEW_FUNCTIONS / FIREBASE_PROJECT_ID_FOR_PREVIEW_FUNCTIONS を読み取り、checkout → setup-node → 認証(env)→ 依存インストール → firebase deploy --project $FIREBASE_PROJECT_ID_FOR_PREVIEW_FUNCTIONS を実行するフローを追加
- 本番パスは FIREBASE_SA_KEY / FIREBASE_PROJECT を使用し、最後のデプロイ参照を FIREBASE_PROJECT に変更(ステップ名は "Deploy Functions (Production)" 等に更新)
Ignore: functions サービスアカウント(開発用追加)
openci-runner/firebase/functions/.gitignore
- service_account_dev.json.gitignore に追加(既存の service_account.json は維持)

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor 開発者 as Dev
  participant GH as GitHub Actions
  participant Job as Deploy Job
  participant Secrets as GitHub Secrets
  participant FB as firebase-tools

  Dev->>GH: push / pull_request
  GH->>Job: スタート

  alt event == pull_request
    Note over Job: job = deploy-firebase-functions-dev
    Job->>Secrets: read FIREBASE_SA_KEY_FOR_PREVIEW_FUNCTIONS\nFIREBASE_PROJECT_ID_FOR_PREVIEW_FUNCTIONS
    Job->>Job: export preview env
    Job->>FB: auth using preview SA (env)
    Job->>FB: npm install -> firebase deploy --project $FIREBASE_PROJECT_ID_FOR_PREVIEW_FUNCTIONS
  else event == push
    Note over Job: job = deploy-firebase-functions-production
    Job->>Secrets: read FIREBASE_SA_KEY\nFIREBASE_PROJECT
    Job->>Job: export production env
    Job->>FB: auth using prod SA (env)
    Job->>FB: npm install -> firebase deploy --project $FIREBASE_PROJECT
  end

  FB-->>Job: deployment result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

ぽかぽかブランチで耳をぴょこん、
プルのときはプレビューへぴょこん、プッシュなら本番へぴょこん。
鍵をそっと env にしまって、
にんじんひとつでビルドを引いて、
今日もデプロイで跳ねるよ、ぴょん 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed タイトルは「Firebaseデプロイにおける環境変数の扱いをシンプル化するリファクタリング」という主旨を簡潔に表しており、実際の変更内容と整合しているため適切です。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch op-285-2

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cfc769c and 3b07a81.

📒 Files selected for processing (1)
  • .github/workflows/github-apps-cd.yml (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/github-apps-cd.yml

20-20: got unexpected character '$' while lexing expression, expecting 'a'..'z', 'A'..'Z', '_', '0'..'9', ''', '}', '(', ')', '[', ']', '.', '!', '<', '>', '=', '&', '|', '*', ',', ' '

(expression)


21-21: got unexpected character '$' while lexing expression, expecting 'a'..'z', 'A'..'Z', '_', '0'..'9', ''', '}', '(', ')', '[', ']', '.', '!', '<', '>', '=', '&', '|', '*', ',', ' '

(expression)

- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.FIREBASE_SA_KEY }}
credentials_json: $FIREBASE_SERVICE_ACCOUNT_JSON
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

with の入力に環境変数が展開されません
with ブロック内ではシェル展開が行われないため、$FIREBASE_SERVICE_ACCOUNT_JSON がそのまま文字列として渡され、認証が失敗します。env コンテキストを用いて明示的に式展開してください。

-          credentials_json: $FIREBASE_SERVICE_ACCOUNT_JSON
+          credentials_json: ${{ env.FIREBASE_SERVICE_ACCOUNT_JSON }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
credentials_json: $FIREBASE_SERVICE_ACCOUNT_JSON
credentials_json: ${{ env.FIREBASE_SERVICE_ACCOUNT_JSON }}
🤖 Prompt for AI Agents
.github/workflows/github-apps-cd.yml around line 34: the workflow uses a literal
shell-style variable ($FIREBASE_SERVICE_ACCOUNT_JSON) inside a with block which
is not expanded; change the input to use the GitHub Actions expression that
reads the env context (e.g. replace the literal with the expression that
references env.FIREBASE_SERVICE_ACCOUNT_JSON) and ensure the
FIREBASE_SERVICE_ACCOUNT_JSON value is exported into env earlier in the workflow
or provided as a secret mapped into env.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/github-apps-cd.yml (1)

63-64: プロダクション環境のデプロイ手順名を修正してください。

本番ジョブ内のステップ名が「Deploy Functions (dev)」のままなので、運用時に紛らわしくなります。prod など適切な表記へ変更することを検討してください。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3b07a81 and 2b7fe66.

📒 Files selected for processing (1)
  • .github/workflows/github-apps-cd.yml (2 hunks)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
openci-runner/firebase/functions/.gitignore (1)

11-12: サービスアカウント鍵はワイルドカードで包括的に無視した方が安全です

将来のファイル追加に強く、メンテ負担も減ります。

適用例:

-service_account.json
-service_account_dev.json
+service_account*.json
.github/workflows/github-apps-cd.yml (3)

16-40: フォークからの PR でシークレット未提供によりジョブが失敗する懸念

フォーク PR では GitHub Secrets が渡されません。プレビュー配備を自リポ内 PR に限定する条件を追加すると安定します。

例:

-    if: github.event_name == 'pull_request'
+    if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false

組織のコントリビューション方針(fork PR の有無)に合致するか確認してください。


38-40: Firebase CLI のバージョンを固定し、非対話モードを明示

最新版追随は破壊的変更の影響を受けやすいです。CI 向けに --non-interactive を付与してください。

例:

-        run: npx firebase-tools deploy --only functions --project ${{ secrets.FIREBASE_PROJECT_ID_FOR_PREVIEW_FUNCTIONS }}
+        run: npx firebase-tools@13 deploy --only functions --project ${{ secrets.FIREBASE_PROJECT_ID_FOR_PREVIEW_FUNCTIONS }} --non-interactive

63-64: 本番配備でも CLI バージョン固定と非対話化、プロジェクト値の整合確認

同様にバージョン固定と非対話化を推奨します。あわせて FIREBASE_PROJECT が Firebase/GCP の「プロジェクト ID」か「エイリアス」かを統一してください(プレビュー側は *_PROJECT_ID_*)。

修正例:

-        run: npx firebase-tools deploy --only functions --project ${{ secrets.FIREBASE_PROJECT }}
+        run: npx firebase-tools@13 deploy --only functions --project ${{ secrets.FIREBASE_PROJECT }} --non-interactive

FIREBASE_PROJECT の値がプロジェクト ID であることを確認し、可能なら命名を FIREBASE_PROJECT_ID に統一してください。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2b7fe66 and 099ca2b.

📒 Files selected for processing (2)
  • .github/workflows/github-apps-cd.yml (2 hunks)
  • openci-runner/firebase/functions/.gitignore (1 hunks)
🔇 Additional comments (2)
.github/workflows/github-apps-cd.yml (2)

30-33: credentials_json のシークレット形式を確認してください

google-github-actions/auth@v2credentials_json は「生の JSON 文字列」を想定しています。Base64 文字列では認証に失敗します。

シークレット FIREBASE_SA_KEY_FOR_PREVIEW_FUNCTIONSFIREBASE_SA_KEY が JSON 文字列であることを確認してください(先頭が { で始まる)。


26-29: node-version-file: .nvmrc の指定は正しいため、変更不要です。

Likely an incorrect or invalid review comment.

@mafreud mafreud merged commit 47b99de into develop Oct 3, 2025
28 of 34 checks passed
@mafreud mafreud deleted the op-285-2 branch October 3, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant