-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_release
executable file
·91 lines (75 loc) · 3.04 KB
/
build_release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#######################################
# Flutter Version Increment and Build Script
#######################################
# Script Usage:
# - This script must be executed from the root of the Flutter project.
# - It increments the build number in the Flutter project's pubspec.yaml file.
# - It provides options to increment the MAJOR, MINOR, or PATCH version components in
# addition to the build number.
# - Release builds for iOS and Android can be disabled using the --no-build option.
# - The appBundle and ipa file are copied to the ./release directory.
# Usage:
# ./build_release [OPTIONS]
# Available Options:
# --major Increment the MAJOR version component.
# --minor Increment the MINOR version component.
# --patch Increment the PATCH version component.
# => only one of the options above can be used at a time.
#
# --no-build Disable release builds for iOS and Android.
ios_release_build() {
# Build ipa
flutter build ipa --release
# Copy IPA file to release directory
cp build/ios/ipa/*.ipa ./release
}
android_release_build() {
# Build appBundle
flutter build appbundle --release
# Copy App Bundle file to release directory
cp build/app/outputs/bundle/release/*.aab ./release
}
# Function to execute Flutter release builds for iOS and Android
execute_flutter_release_builds() {
# Ensure release directory exists; create if not present
mkdir -p ./release
ios_release_build
android_release_build
}
# Function to increment version components in pubspec.yaml
increment_flutter_version() {
PUBSPEC_FILE="pubspec.yaml"
CURRENT_VERSION=$(awk '/version:/ {print $2}' "$PUBSPEC_FILE" | tr -d "'")
MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
PATCH=$(echo "$CURRENT_VERSION" | cut -d. -f3 | cut -d+ -f1)
BUILD=$(echo "$CURRENT_VERSION" | cut -d+ -f2)
if [ "$1" == "--major" ]; then
NEW_VERSION="$((MAJOR + 1)).0.0+$((BUILD + 1))"
elif [ "$1" == "--minor" ]; then
NEW_VERSION="$MAJOR.$((MINOR + 1)).0+$((BUILD + 1))"
elif [ "$1" == "--patch" ]; then
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))+$((BUILD + 1))"
else
NEW_VERSION="$MAJOR.$MINOR.$PATCH+$((BUILD + 1))"
fi
awk -v current_version="$CURRENT_VERSION" -v new_version="$NEW_VERSION" \
'$1 == "version:" && $2 == current_version { $2 = new_version } { print }' \
"$PUBSPEC_FILE" > temp && mv temp "$PUBSPEC_FILE"
echo "Flutter version incremented to $NEW_VERSION"
}
# Increment version based on provided options
if [ "$1" == "--major" ] || [ "$1" == "--minor" ] || [ "$1" == "--patch" ]; then
increment_flutter_version "$1"
elif [ "$2" == "--major" ] || [ "$2" == "--minor" ] || [ "$2" == "--patch" ]; then
increment_flutter_version "$2"
else
increment_flutter_version
fi
# Check for --no-build option to disable release builds
if [[ "$1" == "--no-build" || "$2" == "--no-build" ]]; then
echo "Release builds disabled."
else
execute_flutter_release_builds
fi