Automating Version Bumps with GitHub Actions + Flutter
FlutterGitHub ActionsAutomationDevOps

Automating Version Bumps with GitHub Actions + Flutter

5 min read

Automating Version Bumps with GitHub Actions + Flutter: A Step-by-Step Guide

This guide shows how I automated versioning in my Flutter app whenever a PR is merged into dev, ensuring our TestFlight and Play builds are always up to date without manual editing.

The Problem

We often forgot to manually update pubspec.yaml, causing confusion and duplicate builds in TestFlight or Play Console.

Goals

  • Automatically bump version + build number
  • Commit that change back to the repo
  • Keep versioning predictable and unique

Step-by-Step Setup

1. Detect Merge to dev

Copy
on: push: branches: - dev

2. Use a Script to Bump Version

Copy
#!/bin/bash VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}') IFS='+' read -ra PARTS <<< "$VERSION" NEW_BUILD=$((PARTS[1]+1)) echo "version: ${PARTS[0]}+$NEW_BUILD" > pubspec.yaml

3. Commit and Push

Copy
- name: Commit version bump run: | git config user.name "github-actions" git config user.email "github-actions@github.com" git add pubspec.yaml git commit -m "ci: bump version" git push

4. Add to Workflow

Add these steps in your main CI pipeline after tests pass.

Gotchas

  • Make sure the workflow has write permission for the repo
  • Use a personal access token if GITHUB_TOKEN isn't enough

Results

  • Consistent versioning
  • Fewer manual steps before release
  • Seamless CI experience