# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge

on:
  push:
    branches:
      - master

jobs:
  build_web:
    name: Build Flutter (Web)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: subosito/flutter-action@v2
        with:
          channel: "stable"
      - run: flutter pub get

      # Add this step to decode and create firebase_options.dart
      # you need to encode your firebase_options.dart content using base64
      # if you using git command line, you can just run this in terminal : base64 -w 0 lib/firebase_options.dart | clip
      # and goto your github repo -> settings -> Secret and variables -> actions->
      # addnew Secret with name FIREBASE_OPTIONS, and just paste your encoded
      - name: Create Firebase Options File
        run: |
          echo "$FIREBASE_OPTIONS" | base64 -d > lib/firebase_options.dart
        env:
          FIREBASE_OPTIONS: ${{ secrets.FIREBASE_OPTIONS }}

      - run: flutter build web --release --web-renderer html
      - name: Archive Production Artifact
        uses: actions/upload-artifact@v2
        with:
          name: web-build
          path: build/web

  deploy_web:
    name: Deploy Web to Firebase Hosting
    needs: build_web
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3
      - name: Download Artifact
        uses: actions/download-artifact@v2
        with:
          name: web-build
          path: build/web
      - name: Deploy To Firebase
        uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_HALODOCTOR_A1660 }}"
          channelId: live
          projectId: halodoctor-a1660
