Skip to content

Instantly share code, notes, and snippets.

@evelyne24
Last active December 18, 2022 05:56
Show Gist options
  • Save evelyne24/ba2930fb03299a9214850b7b5d301d85 to your computer and use it in GitHub Desktop.
Save evelyne24/ba2930fb03299a9214850b7b5d301d85 to your computer and use it in GitHub Desktop.
Bash script to extract the build name and number from `pubspec.yaml` before building your Flutter app
#!/bin/bash
set -e
file=$(cat pubspec.yaml)
BUILD_NAME=$(echo $file | sed -ne 's/[^0-9]*\(\([0-9]\.\)\{0,4\}[0-9][^.]\).*/\1/p')
BUILD_NUMBER=$(git rev-list HEAD --count)
echo "Building version ${BUILD_NAME} ${BUILD_NUMBER}"
export BUILD_NAME="$BUILD_NAME"
export BUILD_NUMBER="$BUILD_NUMBER"
@evelyne24
Copy link
Author

One liner, set the build command to include --build-name=$(echo $(cat pubspec.yaml) | sed -ne 's/[^0-9]*\(\([0-9]\.\)\{0,4\}[0-9][^.]\).*/\1/p') --build-number=$(git rev-list HEAD --count)

@zsjenei
Copy link

zsjenei commented Jul 1, 2021

This will take the first proper formatted number, but not necessarily the version number. If there is a comment with similar number before the version, it will give back that one.

@shakir915
Copy link

shakir915 commented Dec 18, 2022

build flutter : ios adhoc IPA + android APK + Upload

#!/bin/
echo "build adhoc IPA + APK + Upload "
set -e
file=$(cat pubspec.yaml)
fullVersion=$(echo | grep -i -e "version: " pubspec.yaml)
buildName=$(echo $fullVersion | cut -d " " -f 2 | cut -d "+" -f 1)
buildNumber=$(echo $fullVersion | cut -d "+" -f 2 )
echo "$fullVersion BUILD_NAME ${buildName} BUILD_NUMBER ${buildNumber}"

flutterSDK=/Users/emstell/flutter_latest/bin/flutter
exportPlist="/Users/emstell/Desktop/EW/Adhoc_IPA_ExportOptions.plist"
ipaFile="/Users/emstell/Desktop/EW/build/ios/ipa/everything_women.ipa"
apkFile="/Users/emstell/Desktop/EW/build/app/outputs/flutter-apk/app-release.apk"
$flutterSDK clean
($flutterSDK  --no-color build ipa --build-number=$buildNumber --build-name=$buildName  --release   --no-sound-null-safety   --export-options-plist=$exportPlist)&&(curl -X PUT $(curl -s "https://appho.st/api/get_upload_url?user_id=mk93BH22AwXQC8Jl9gokup0FIwN&app_id=Oblh5aocIfvh9Nc1U2Bx&key=X4EkmZ53xaQZOUCwdYxMJUgGkrxhgIsH&platform=ios&version=$buildName&ios_bundle_identifier=com.emstell.Everything.Woman") -H 'content-type: application/octet-stream' --data-binary "@$ipaFile" > /dev/null)
($flutterSDK --no-color build apk  --build-number=$buildNumber --build-name=$buildName --release   --no-sound-null-safety )&&(curl -X PUT $(curl -s "https://appho.st/api/get_upload_url?user_id=mk93BH22AwXQC8Jl9gokup0FIwN&app_id=Oblh5aocIfvh9Nc1U2Bx&key=X4EkmZ53xaQZOUCwdYxMJUgGkrxhgIsH&platform=android&version=$buildName") -H 'content-type: application/octet-stream' --data-binary "@$apkFile" > /dev/null)
say completed
echo "EW build https://appho.st/d/ODtgkWP1"


plist : replace teamID

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>compileBitcode</key>
	<true/>
	<key>destination</key>
	<string>export</string>
	<key>method</key>
	<string>ad-hoc</string>
	<key>signingStyle</key>
	<string>automatic</string>
	<key>stripSwiftSymbols</key>
	<true/>
	<key>teamID</key>
	<string>ZDE7PEH8M3</string>
	<key>thinning</key>
	<string>&lt;none&gt;</string>
</dict>
</plist>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment