name: Build Web
on:
  push:
    branches:
      - master
jobs:
  build:
    name: Build Web
    env:
      commit_secret: ${{secrets.commit_secret}}
      commit_email: ${{secrets.commit_email}}
      commit_name: ${{secrets.commit_name}}
      app_sentry: ${{secrets.app_sentry}}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: subosito/flutter-action@v1
        with:
          channel: 'dev' # TODO change to beta/stable
          #flutter-version: '1.15.17'
      - run: flutter pub get
      - run: |
          cp lib/.env.dart.example lib/.env.dart
          cp android/app/build.gradle.prod android/app/build.gradle
          sed -i 's/secret/password/g' lib/.env.dart
          sed -i 's/dns/${{secrets.app_sentry}}/g' lib/.env.dart
          sed -i -e '/OTHER_LANGUAGES/{r lib/utils/i18n' -e 'd}' lib/utils/i18n.dart
      - run: flutter upgrade
      - run: flutter config --enable-web
      - run: flutter build web --release
      - run: |
          git config --global user.email ${{secrets.commit_email}}
          git config --global user.name ${{secrets.commit_name}}

          git clone https://${{secrets.commit_secret}}@github.com/invoiceninja/invoiceninja.git
          cd invoiceninja
          git checkout v2

          cp -r ../build/web/* ./public/
          git add .
          git commit -m 'New admin portal build'
          git push