Github actions replacing firebase json in flutter project
Not sure that's the most optimised solution but it's what I found being the easiest to update and maintain.
Step 1 : Store the google-services.json files in the secrets of your Github repository (that way you won't have to commit this file in your repo, that's a bonus) with names like FIREBASE_CONFIG_DEV and FIREBASE_CONFIG_PROD.
Step 2 : Create two workflows : one for the dev, triggered every pull-request for example, and the other one for the release, triggered by a commit on a specific branch like your did
Step 3 : Provide the google-service.json to your project
steps:
- uses: actions/checkout@v1
- name: Provide Firebase Android
env:
FIREBASE_CONFIG_DEV: ${{ secrets.FIREBASE_CONFIG_DEV }}
run: echo $FIREBASE_CONFIG_DEV > ./android/app/google-services.json
Your Dev workflow should look like this
Just edit this snippet to add the creation of the google-services.json to your iOS project and you should be good to go
cas
Working as a full stack developer @ Rvised, actively looking for work!
Updated on December 21, 2022Comments
-
cas over 1 year
I'm running a Github action that automatically builds and releases a flutter project. But we use a dev and a production Firebase environment. so before the build I'd like to switch out the google-services.json from the dev to the production version. But I can't seem to find an easy way to do this. Or is there a better way to work with dev and production versions of Firebase inside flutter?
probably not very useful but here's the action in it's current state
on: push: branches: [ stable ] name: Build and Release jobs: build: name: Build runs-on: ubuntu-latest steps: - uses: actions/checkout@master with: fetch-depth: '0' - name: Bump version and push tag id: tag uses: anothrNick/[email protected] env: GITHUB_TOKEN: ${{ secrets.TOKEN }} WITH_V: true RELEASE_BRANCHES: stable - uses: actions/checkout@v1 - uses: actions/setup-java@v1 with: java-version: '12.x' - uses: subosito/flutter-action@v1 with: flutter-version: '1.17.3' - run: flutter pub get - run: flutter build appbundle - name: Create a Release APK uses: ncipollo/release-action@v1 with: artifacts: "build/app/outputs/bundle/release/*.aab" tag: ${{ steps.tag.outputs.tag }} token: ${{ secrets.TOKEN }}
I'm very, very new to github actions and CI in general. any constructive feedback is always welcome!
-
Yashovardhan99 about 3 yearsThanks a ton! I was looking for this while setting up automated releases via github.