Skip to content

Auto Publish Flutter Packages to Pub.dev with Github Workflows

Published: at 03:22 PMSuggest Changes

Have you ever experienced time-consuming difficulty manually publishing your Flutter packages? Do you wish there were a method to speed things up and eliminate human error? You’re in luck if so! You may automate your package publishing procedure and spare yourself time, hassle, and frustration by using the strength of GitHub Actions.

This Blog will guide you through the process of setting up a GitHub Workflow to automatically publish your Flutter package to pub.dev. This tutorial will give you the information and resources you need to advance your package publishing process, whether you’re an experienced developer or just learning Flutter.

Let’s Get Started✌️:

via GIPHY

Prerequisites:

A Little Back-Story:

A few weeks back I started working on my own Flutter Package neubrutalism_ui, which is a UI kit packed with amazing Neubrutalist styled widgets, and I was having difficulty deploying the package again and again with changes, I was trapped in an infinite loop where I was doing the same thing manually every time I had to update the package with changes.

I started looking for solutions to automate the process, after hours of trying different solutions from StackOverflow and this Blog but none of them were working, then I found https://github.com/k-paxian/dart-package-publisher this repo, which worked perfectly.

via GIPHY

Step 1:

Step 2:

Copy your pub-credentials.json:

Step 3:

Create a new Github Secret and store your pub-credential data there.

Step 4:

Step 5:

Writing the workflow to automate the deployment🔥🔥🔥.

name: Publish Flutter Package

on:
  push:
    branches:
      - master

jobs:
  publish-package:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Flutter
        uses: subosito/flutter-action@v2

      - name: Get dependencies
        run: flutter pub get

      - name: Analyze code
        run: flutter analyze

      - name: Format code
        run: dart format --fix .

      - name: Check publish warnings
        run: dart pub publish --dry-run

      - name: Publish package
        uses: k-paxian/[email protected]
        with:
          credentialJson: ${{ secrets.CREDENTIAL_SECRET }}
          flutter: true
          skipTests: true

Explanation:

  1. The above action will be triggered when we push changes to the master branch. (I recommend creating 2 branches one for development and testing and the other for deployment, think of them as prod and dev environment)
  2. Creates a job for a new build that will run on ubuntu-latest
  3. Set up configuration, install dependencies, analyze etc
  4. The k-paxian/[email protected] is the plugin that will take care of our package deployment in pub.dev.
  5. Provide all the parameters like credentialJsonwhich we created in GitHub Secret and so on.

[Note]: To trigger a new build, commit all your changes and head over to your root repository and there you will see create a new release build.

And It’s Done ✅

via GIPHY


Previous Post
Build and Push your First Docker Image to Docker Hub 🐳