Skip to content

Conversation

@MaitreyaBuddha
Copy link
Contributor

@MaitreyaBuddha MaitreyaBuddha commented Apr 20, 2025

PR Type

Enhancement


Description

  • Simplify deploy steps using shared action

  • Remove manual Node.js, Firebase CLI setup

  • Consolidate authentication and deployment logic

  • Pass environment and credentials inputs


Changes walkthrough 📝

Relevant files
Enhancement
deploy-functions.yml
Simplify deployment workflow via shared action                     

.github/workflows/deploy-functions.yml

  • Removed manual Node.js, Firebase CLI, uv, Python steps
  • Deleted auth, debug, deploy and cleanup steps
  • Added single deploy step with local action
  • Configured environment and credentials inputs
  • +5/-84   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Conditional Logic

    Verify that the ${{ github.event.inputs.environment == 'prod' && secrets.FIREBASE_PROD_SERVICE_ACCOUNT || secrets.FIREBASE_STAGING_SERVICE_ACCOUNT }} and similar expressions work correctly for all possible input values. Consider explicitly validating or constraining environment to avoid unexpected fallbacks or secret leakage.

    environment: ${{ github.event.inputs.environment }}
    service_account_json: ${{ github.event.inputs.environment == 'prod' && secrets.FIREBASE_PROD_SERVICE_ACCOUNT || secrets.FIREBASE_STAGING_SERVICE_ACCOUNT }}
    project_id: ${{ github.event.inputs.environment == 'prod' && 'hello-wisdom-prod' || 'hello-wisdom-staging' }}
    Indentation Check

    Ensure the with: block and its keys (environment, service_account_json, project_id) are indented properly under the uses: ./ step so that GitHub Actions recognizes them correctly.

    - name: Deploy Firebase Functions
      uses: ./
      with:
        environment: ${{ github.event.inputs.environment }}
        service_account_json: ${{ github.event.inputs.environment == 'prod' && secrets.FIREBASE_PROD_SERVICE_ACCOUNT || secrets.FIREBASE_STAGING_SERVICE_ACCOUNT }}
        project_id: ${{ github.event.inputs.environment == 'prod' && 'hello-wisdom-prod' || 'hello-wisdom-staging' }}

    @github-actions
    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Use explicit ternary operators

    Replace combined logical expressions with explicit ternary operators to avoid
    unintended fallbacks when a value is empty.

    .github/workflows/deploy-functions.yml [47-48]

    -service_account_json: ${{ github.event.inputs.environment == 'prod' && secrets.FIREBASE_PROD_SERVICE_ACCOUNT || secrets.FIREBASE_STAGING_SERVICE_ACCOUNT }}
    -project_id: ${{ github.event.inputs.environment == 'prod' && 'hello-wisdom-prod' || 'hello-wisdom-staging' }}
    +service_account_json: ${{ github.event.inputs.environment == 'prod' ? secrets.FIREBASE_PROD_SERVICE_ACCOUNT : secrets.FIREBASE_STAGING_SERVICE_ACCOUNT }}
    +project_id: ${{ github.event.inputs.environment == 'prod' ? 'hello-wisdom-prod' : 'hello-wisdom-staging' }}
    Suggestion importance[1-10]: 6

    __

    Why: Replacing the &&/|| pattern with ?/: makes the intent clearer and prevents unexpected fallbacks when a value is empty.

    Low

    firebase use prod --non-interactive
    else
    firebase use staging --non-interactive
    if ! echo "$service_account_b64" | base64 --decode > /dev/null 2>&1; then
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    I'm trying to add validation for base64 encoding here. Let me know what you think of this approach.

    action.yml Outdated
    echo '${{ inputs.service_account_json_b64 }}' | base64 -d | jq '.' > service-account.json
    echo "GOOGLE_APPLICATION_CREDENTIALS=service-account.json" >> $GITHUB_ENV
    gcloud auth activate-service-account --key-file=service-account.json
    rm -f service-account.json
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    We still need this here. The JSON key will be cleaned up at the end of the workflow.

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

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

    What uses the json after this?

    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Good question. I thought the environment variable stores a reference to the JSON, which Firebase uses in later steps. I must have misunderstood.

    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    I added this line back in, but got:
    Error: Failed to authenticate, have you run firebase login?

    @aquitzia
    Copy link
    Collaborator

    I added two more keys, which are base 64 encoded:
    FIREBASE_STAGING_SERVICE_ACCOUNT_B64
    FIREBASE_PROD_SERVICE_ACCOUNT_B64
    We should delete the old keys.

    @aquitzia aquitzia closed this Aug 11, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants