name: publish

on:
  workflow_dispatch:
  release:
    types: [published]

jobs:
  publish:
    name: Publish
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: subosito/flutter-action@v2
        with:
          channel: 'stable'
      - name: Run pub.dev/inject-credentials@shell
        env:
          CREDENTIALS: ${{ secrets.CREDENTIALS_JSON }}
        run: |
          if [ -z $PUB_CACHE ];then
            PUB_CACHE=~/.pub-cache
          fi
          mkdir -p $PUB_CACHE
          echo $CREDENTIALS > $PUB_CACHE/credentials.json
      - run: flutter --version
      - run: flutter pub get
      - run: dart format --set-exit-if-changed .
      - run: echo "y" | flutter pub publish
