fireway icon indicating copy to clipboard operation
fireway copied to clipboard

How to run migrations in Github Actions using firebase token?

Open adinvadim opened this issue 2 years ago • 6 comments

I got firebase token by using command firebase login:ci, and after deploy with flag --token

How to run migrations with this token?

adinvadim avatar Jan 11 '22 13:01 adinvadim

@kevlened need your help

adinvadim avatar Feb 04 '22 18:02 adinvadim

+1 I would like to know how to use this on firebase too. Thanks in advance!

yliu7810 avatar Feb 12 '22 01:02 yliu7810

@yliu7810 @adinvadim, I've managed to do this by creating the following workflow:

name: Migrate Firestore

on:
  push:
    branches:
      - your_branch

jobs:
  backup:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master
      - name: Install Dependencies
        run: npm install
      - id: auth
        uses: google-github-actions/auth@v0
        with:
          credentials_json: ${{ secrets.YOUR_GCLOUD_SERVICE_ACCOUNT_JSON_ENCODED_TO_BASE64 }}
      - name: Migrate data
        run: npm run migrations # this basically runs fireway migrate

I have not found the specifics roles that have to enabled for a service account for this to work, so that I've simply used basic role Editor

eugeneford avatar Mar 11 '22 15:03 eugeneford

I am having trouble with the library when using google-github-actions/auth. Whenever I use the new workload identity federation for Google auth, I get an error with "Invalid content in credentials file" .. If I use the deprecated service account method, it works fine.

Did anyone face this issue? @eugeneford

omarsourour avatar Sep 24 '22 03:09 omarsourour

@omarsourour I have encountered the same issue. Did you come upon a solution?

anettebgo avatar Jan 26 '23 11:01 anettebgo

@anettebgo I didn't unfortunately.. Honestly I didn't try too much.

omarsourour avatar Jan 26 '23 19:01 omarsourour

I solved my problem like this

      - name: Prepare Service Account for Migrations
        run: |
          touch service-account.json
          printf "%s\n" '${{ secrets.FIREBASE_SERVICE_ACCOUNT }}' >> service-account.json

...

      - name: Migrations
        run: |
          export GOOGLE_APPLICATION_CREDENTIALS="$(pwd)/service-account.json"
          cd functions && \
          npx fireway migrate \
            --require='ts-node/register' \
            --path='./src/migrations' \
            --projectId=${{ secrets.PROJECT_ID }}

adinvadim avatar Apr 01 '24 10:04 adinvadim