Skip to content

Instantly share code, notes, and snippets.

@markhaehnel
Last active May 4, 2020 06:21
Show Gist options
  • Save markhaehnel/d6c59bf707ed954f43c93ed622aa0fba to your computer and use it in GitHub Desktop.
Save markhaehnel/d6c59bf707ed954f43c93ed622aa0fba to your computer and use it in GitHub Desktop.
Flutter build scripts (with version from Git)
#!/usr/bin/env pwsh
# Get version information from git
$VERSION_NAME=(git describe)
$VERSION_CODE=(git rev-list --all --count)
# Check git version validity
if (([string]::IsNullOrEmpty($VERSION_NAME)) -or ([string]::IsNullOrEmpty($VERSION_CODE))) {
Write-Output "VERSION_NAME or VERSION_CODE is empty. There must be at least one git commit and one git tag."
exit 1
}
Write-Output "VersionName: $VERSION_NAME"
Write-Output "VersionCode: $VERSION_CODE"
# Determine which platform should be built
switch ($args[0]) {
"apk" {
Write-Output "Building Android APK.."
flutter build apk --build-name=$VERSION_NAME --build-number=$VERSION_CODE
Break
}
"aab" {
Write-Output "Building Android App Bundle.."
flutter build appbundle --build-name=$VERSION_NAME --build-number=$VERSION_CODE
Break
}
"ios" {
Write-Output "Building iOS Build Archive.."
flutter build ios --build-name=$VERSION_NAME --build-number=$VERSION_CODE
Break
}
Default {
Write-Output "No valid platform specified. Available options are apk, aab, ios."
exit 1
}
}
#!/bin/bash
# Get version information from git
VERSION_NAME=$(git describe)
VERSION_CODE=$(git rev-list --all --count)
# Check git version validity
if [ -z "$VERSION_NAME" ] || [ -z "$VERSION_NAME" ]; then
echo "VERSION_NAME or VERSION_CODE is empty. There must be at least one git commit and one git tag."
exit 1
fi
echo "VersionName: $VERSION_NAME"
echo "VersionCode: $VERSION_CODE"
# Determine which platform should be built
case $1 in
apk)
echo "Building Android APK.."
flutter build apk --build-name=$VERSION_NAME --build-number=$VERSION_CODE
break
;;
aab)
echo "Building Android App Bundle.."
flutter build appbundle --build-name=$VERSION_NAME --build-number=$VERSION_CODE
break
;;
ios)
echo "Building iOS Build Archive.."
flutter build ios --build-name=$VERSION_NAME --build-number=$VERSION_CODE
break
;;
*)
echo "No valid platform specified. Available options are apk, aab, ios."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment