Merge pull request #5 from Hack4Impact-UMD/funcs #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Firebase Functions | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| paths: | |
| - 'functions/**' | |
| - 'firebase.json' | |
| pull_request: | |
| branches: [ main ] | |
| paths: | |
| - 'functions/**' | |
| - 'firebase.json' | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Environment to deploy to' | |
| required: true | |
| default: 'production' | |
| type: choice | |
| options: | |
| - production | |
| - staging | |
| env: | |
| NODE_VERSION: '22' | |
| jobs: | |
| test-functions: | |
| name: Test Firebase Functions | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install main dependencies | |
| run: npm ci | |
| - name: Install Firebase Functions dependencies | |
| run: npm run functions:install | |
| - name: Build Firebase Functions | |
| run: npm run functions:build | |
| - name: Run Firebase Functions tests | |
| run: npm run functions:test | |
| - name: Upload Functions Test Coverage | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: functions-coverage | |
| path: functions/coverage/ | |
| retention-days: 30 | |
| deploy-functions-staging: | |
| name: Deploy Functions to Staging | |
| runs-on: ubuntu-latest | |
| needs: [test-functions] | |
| if: github.ref == 'refs/heads/develop' && github.event_name == 'push' | |
| environment: staging | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Install Firebase Functions dependencies | |
| run: npm run functions:install | |
| - name: Build Firebase Functions | |
| run: npm run functions:build | |
| - name: Install Firebase CLI | |
| run: npm install -g firebase-tools | |
| - name: Deploy Firebase Functions to Staging | |
| run: firebase deploy --only functions --project staging --token "${{ secrets.FIREBASE_TOKEN_STAGING }}" | |
| env: | |
| FIREBASE_TOKEN_STAGING: ${{ secrets.FIREBASE_TOKEN_STAGING }} | |
| deploy-functions-production: | |
| name: Deploy Functions to Production | |
| runs-on: ubuntu-latest | |
| needs: [test-functions] | |
| if: | | |
| (github.ref == 'refs/heads/main' && github.event_name == 'push') || | |
| (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production') | |
| environment: production | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Install Firebase Functions dependencies | |
| run: npm run functions:install | |
| - name: Build Firebase Functions | |
| run: npm run functions:build | |
| - name: Install Firebase CLI | |
| run: npm install -g firebase-tools | |
| - name: Deploy Firebase Functions to Production | |
| run: firebase deploy --only functions --token "${{ secrets.FIREBASE_TOKEN }}" | |
| env: | |
| FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} | |
| - name: Notify Deployment Success | |
| if: success() | |
| run: | | |
| echo "✅ Firebase Functions deployed successfully to production!" | |
| echo "🚀 Functions are now live and ready to use." | |
| deploy-functions-manual: | |
| name: Deploy Functions (Manual) | |
| runs-on: ubuntu-latest | |
| needs: [test-functions] | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging' | |
| environment: staging | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Install Firebase Functions dependencies | |
| run: npm run functions:install | |
| - name: Build Firebase Functions | |
| run: npm run functions:build | |
| - name: Install Firebase CLI | |
| run: npm install -g firebase-tools | |
| - name: Deploy Firebase Functions to Staging (Manual) | |
| run: firebase deploy --only functions --project staging --token "${{ secrets.FIREBASE_TOKEN_STAGING }}" | |
| env: | |
| FIREBASE_TOKEN_STAGING: ${{ secrets.FIREBASE_TOKEN_STAGING }} |