Skip to content

Instantly share code, notes, and snippets.

@ebwood
Created March 16, 2025 17:09
Show Gist options
  • Save ebwood/d7301998667b8d7c75768b1d99fec79c to your computer and use it in GitHub Desktop.
Save ebwood/d7301998667b8d7c75768b1d99fec79c to your computer and use it in GitHub Desktop.
Flutter increment build number script
#!/bin/bash
# Read pubspec.yaml
file="pubspec.yaml"
# Use grep and sed to find and increment the build number
if grep -qE "version: [0-9]+\.[0-9]+\.[0-9]+\+[0-9]+" "$file"; then
# Get the current build number
current_build=$(grep -E "version: [0-9]+\.[0-9]+\.[0-9]+\+[0-9]+" "$file" | sed -E "s/version: [0-9]+\.[0-9]+\.[0-9]+\+([0-9]+)/\1/")
# Increment the build number
new_build=$((current_build + 1))
# Update the file with the new build number
sed -i '' -E "s/(version: [0-9]+\.[0-9]+\.[0-9]+\+)[0-9]+/\1$new_build/" "$file"
echo "Build number incremented successfully from $current_build to $new_build."
else
echo "No version found in pubspec.yaml"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment