kevlened / fireway

A schema migration tool for firestore
MIT License
277 stars 41 forks source link

How to run migrations in Github Actions using firebase token? #52

Closed adinvadim closed 4 months ago

adinvadim commented 2 years ago

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

How to run migrations with this token?

adinvadim commented 2 years ago

@kevlened need your help

yliu7810 commented 2 years ago

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

eugeneford commented 2 years ago

@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

omarsourour commented 1 year ago

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

anettebgo commented 1 year ago

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

omarsourour commented 1 year ago

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

adinvadim commented 4 months ago

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 }}