Complete CI/CD for Flutter Apps

kaos

Kai Oswald

Posted on November 24, 2021

Complete CI/CD for Flutter Apps

My Workflow

This GitHub Action workflow can be used to fully automate your build, test and deployment processes for Flutter.
All Flutter build targets are supported with this workflow: android, iOS and web.
When pushing without a tag this workflow will analyze and test your Flutter app.
When pushing with a tag (starting with 'v' in this case) this workflow additionally creates a release including all artifacts needed for deployment.
These artifacts can then be used to deploy your apps.
I have added the firebase hosting deploy as an example for web deployment.

This can be further extended to deploy the iOS and Android app to a test platform like testflight or directly to the platform specific stores (don't forget to sign your apps 😄).

This workflow is a great starting point for any Flutter app and can be tweaked to your personal preference.

Submission Category:

DIY Deployments, Phone Friendly

Yaml File or Link to Code

name: Build Flutter apps

on:
  push:
    branches:
      - main
    tags:
      - v*


jobs:
  build:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v2
      - uses: subosito/flutter-action@v1.5.3
        with:
          channel: 'stable'

      - name: Install Dependencies
        run: flutter packages get

      - name: Analyze
        run: flutter analyze lib test

      - name: Run tests
        run: flutter test --no-pub --coverage --test-randomize-ordering-seed random packages test

      - name: Build Android App
        if: startsWith(github.ref, 'refs/tags/v')
        run: flutter build apk

      - name: Build iOS App
        if: startsWith(github.ref, 'refs/tags/v')
        run: |
            flutter build ios --no-codesign
            cd build/ios/iphoneos
            mkdir Payload
            cd Payload
            ln -s ../Runner.app
            cd ..
            zip -r app.ipa Payload

      - name: Build web
        if: startsWith(github.ref, 'refs/tags/v')
        run: |
          flutter build web
          cd build/web
          zip -r web-app.zip .

      - name: Archive Production Artifact
        if: startsWith(github.ref, 'refs/tags/v')
        uses: actions/upload-artifact@master
        with:
          name: web
          path: build/web

      - name: Release Apps
        if: startsWith(github.ref, 'refs/tags/v')
        uses: ncipollo/release-action@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          artifacts: 'build/app/outputs/**/*.apk,build/ios/iphoneos/app.ipa,build/web/web-app.zip'

  deploy:
    if: startsWith(github.ref, 'refs/tags/v')
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Download Artifact
        uses: actions/download-artifact@master
        with:
          name: web
          path: build/web

      - name: Deploy to Firebase hosting
        uses: w9jds/firebase-action@master
        with:
          args: deploy --message \"${{ github.event.head_commit.message }}\" --only hosting
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}  
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

We currently use this workflow for our own Flutter app that is not yet published and not yet open-source, but are planning on doing so in the near future!

💖 💪 🙅 🚩
kaos
Kai Oswald

Posted on November 24, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Complete CI/CD for Flutter Apps
actionshackathon21 Complete CI/CD for Flutter Apps

November 24, 2021