-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (174 loc) · 7.4 KB
/
android_deploy.yml
File metadata and controls
208 lines (174 loc) · 7.4 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: Push Android build to Play Store Beta
on:
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
default: 'patch'
jobs:
android_deployment:
runs-on: ubuntu-latest
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
PLAY_STORE_SERVICE_ACCOUNT_JSON: ${{ secrets.PLAY_STORE_SERVICE_ACCOUNT_JSON }}
ANDROID_GOOGLE_SERVICES_JSON: ${{ secrets.ANDROID_GOOGLE_SERVICES_JSON }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Set up Flutter SDK
uses: flutter-actions/setup-flutter@v3
with:
channel: stable
version: 3.24.0
- name: Install dependencies & Lint check
run: |
flutter clean
flutter pub get
flutter analyze --fatal-infos
- name: Install the CodeMagic CLI
run: |
pip install --upgrade pip
pip install --upgrade codemagic-cli-tools
google-play --version
sudo apt-get update && sudo apt-get install -y jq
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Android keystore
run: |
mkdir -p $GITHUB_WORKSPACE/keystore
echo $ANDROID_KEYSTORE_BASE64 | base64 -d > $GITHUB_WORKSPACE/keystore/upload-keystore.jks
# Verify keystore file was created
if [ ! -f "$GITHUB_WORKSPACE/keystore/upload-keystore.jks" ]; then
echo "Error: Keystore file was not created"
exit 1
fi
# List keystore contents to verify the alias
keytool -list -v -keystore $GITHUB_WORKSPACE/keystore/upload-keystore.jks -storepass $ANDROID_KEYSTORE_PASSWORD || echo "Failed to read keystore"
- name: Setup key.properties
run: |
echo "storePassword=$ANDROID_KEYSTORE_PASSWORD" > android/key.properties
echo "keyPassword=$ANDROID_KEY_PASSWORD" >> android/key.properties
echo "keyAlias=$ANDROID_KEY_ALIAS" >> android/key.properties
echo "storeFile=$GITHUB_WORKSPACE/keystore/upload-keystore.jks" >> android/key.properties
- name: Set up Google Services JSON
run: |
echo $ANDROID_GOOGLE_SERVICES_JSON | base64 -d > android/app/google-services.json
- name: Update Version
run: |
set -x # Enable debug mode to see each command
file='VERSION'
echo "Checking for VERSION file..."
if [ -f "$file" ]; then
echo "VERSION file exists"
echo "Current file contents:"
cat "$file"
echo "Reading version components..."
# Read the version and split it into parts
version=$(cat "$file" | tr -d '[:space:]') # Remove any whitespace
IFS='.' read -r -a version_parts <<< "$version"
# Set default values for missing components
major="${version_parts[0]:-0}"
minor="${version_parts[1]:-0}"
patch="${version_parts[2]:-0}"
# Validate that we got numbers
if ! [[ "$major" =~ ^[0-9]+$ ]] || ! [[ "$minor" =~ ^[0-9]+$ ]] || ! [[ "$patch" =~ ^[0-9]+$ ]]; then
echo "Error: Version components must be numbers. Got major=$major minor=$minor patch=$patch"
exit 1
fi
echo "Current version: major=$major minor=$minor patch=$patch"
echo "Getting version bump type from input..."
echo "Raw input value: ${{ github.event.inputs.version_bump }}"
bump_type="${{ github.event.inputs.version_bump }}"
echo "Assigned bump_type: $bump_type"
if [ -z "$bump_type" ]; then
echo "No bump type provided, defaulting to patch"
bump_type="patch"
fi
echo "Using bump type: $bump_type"
case "$bump_type" in
"major")
echo "Performing major version bump"
major=$((major + 1))
minor=0
patch=0
;;
"minor")
echo "Performing minor version bump"
minor=$((minor + 1))
patch=0
;;
"patch")
echo "Performing patch version bump"
patch=$((patch + 1))
;;
*)
echo "Invalid version bump type: '$bump_type'"
exit 1
;;
esac
new_version="$major.$minor.$patch"
echo "Writing new version: $new_version"
echo "$new_version" > "$file"
echo "Updated version to $new_version"
echo "New file contents:"
cat "$file"
else
echo "VERSION file does not exist, creating with initial version"
echo "1.0.0" > "$file"
echo "Created initial version 1.0.0"
echo "New file contents:"
cat "$file"
fi
- name: Build Android App Bundle
run: |
set -x # Enable debug mode
file='VERSION'
version=$(cat "$file" | tr -d '[:space:]') # Remove any whitespace
IFS='.' read -r -a version_parts <<< "$version"
major="${version_parts[0]}"
minor="${version_parts[1]}"
buildNumber=$(( major * 1000000 + minor * 10000 + ${{github.run_number}} ))
buildName="$major.$minor.${{github.run_number}}"
echo "Building version $buildName ($buildNumber)"
# Update the Android project to use v2 embedding
echo "Updating Android project configuration..."
cd android
if [ -f "./app/build.gradle" ]; then
echo "Checking build.gradle configuration..."
cat ./app/build.gradle
fi
cd ..
flutter build appbundle --release --build-number=$buildNumber --build-name=$buildName
- name: Upload and Release to Play Store
run: |
APP_FILE="build/app/outputs/bundle/release/app-release.aab"
if [ ! -f "$APP_FILE" ]; then
echo "Error: AAB file not found at expected path: $APP_FILE"
exit 1
fi
echo "Found AAB file at: $APP_FILE"
# Upload the bundle and capture the output
echo "Uploading bundle to Play Store..."
UPLOAD_OUTPUT=$(google-play bundles publish \
--bundle "$APP_FILE" \
--credentials "$PLAY_STORE_SERVICE_ACCOUNT_JSON" \
--track internal \
--release-name "$(cat VERSION)" \
--release-notes '[{"language": "en-US", "text": "Automated release from GitHub Actions"}]' \
--json \
--log-stream stderr)
echo "Upload response:"
echo "$UPLOAD_OUTPUT"
echo "Release process completed. Please check Play Console in a few minutes."