how to add/pass .env file using github action in firebase hosting

77 views
Skip to first unread message

Mohd Rashid

unread,
Oct 29, 2024, 10:34:27 AMOct 29
to Firebase Google Group
Hi,

want to add or run .env file in firebase using github action

here is what i did

.github/workflows/firebase-hosting-merge.yml

```
name: Deploy to Firebase Hosting on merge
on:
  push:
    branches:
      - main
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout
      - run: npm ci && npm run build

      - name: Load environment variables from .env file
        run: |
          if [ -f .env ]; then
            export $(grep -v '^#' .env | xargs)
          fi
          cat .env
         
      - uses: FirebaseExtended/action-hosting-deploy
        with:
          repoToken: ${{ secrets.GITHUB_TOKEN }}
          firebaseServiceAccount: ${{
            secrets.FIREBASE_SERVICE_ACCOUNT_TEST_GOOGLE_PAGE }}
          channelId: live
          projectId: test-google-page
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
```

This is repo of github code enter image description here

  1. I have added .env in the root directory of github repo
  2. Everything is working fine even .env file is reading from above action but when i dont know whether its reading .env file or not and deployed into firebase account

Here is output where i need to show .env values reflected or not enter image description here so its not reflecting the values which im looking

cat .env

VUE_APP_API_URL=http://test.devops.com:3002/api/v1/xxxxxxx/xxxx
  1. actually values it need to show :- http://test.devops.com:3002/api/v1/xxxxxxx/xxxx
  2. current values showing :- http://localhost:3002/api/v1/xxxxxxx/xxxx

even i read this docs 5. https://firebase.google.com/docs/functions/config-env?gen=2nd#env-variables

But dont understand how to do

but in code of repo under subfolder i see this line

const apiEndpoint = process.env.SECURITY_AI_URL || "http://localhost:3002";

and i cannot change any code under repo of github because its client repo

please tell me what should i do to solve .env

Joe Spiro

unread,
Oct 29, 2024, 10:42:36 AMOct 29
to Firebase Google Group
Hello,

I'm sorry to hear this is happening. To get help with code questions please post  to StackOverflow with the 'firebase' tag. Answering code questions is easier and more visible there. 

Alternatively, to contact the Firebase team directly, file a case with Firebase Support.

Regards,
Joe

Reply all
Reply to author
Forward
0 new messages