-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (128 loc) · 6.16 KB
/
Copy pathbuild_bundle.yml
File metadata and controls
149 lines (128 loc) · 6.16 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
name: Build and Deploy AAB
on:
workflow_dispatch:
inputs:
deploymentType:
description: 'Deployment Type'
required: true
type: choice
options:
- 'internal'
- 'beta'
- 'production'
default: 'internal'
branch:
description: 'Branch to build (e.g., main)'
required: true
default: 'main'
jobs:
build-and-deploy:
runs-on: ubuntu-24.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: Set up JDK
uses: actions/setup-java@v4.2.2
with:
distribution: 'temurin'
java-version: '21'
- name: Grant execute permission to gradlew
run: chmod +x ./gradlew
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts', '**/gradle/libs.versions.toml', '**/gradle.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Read current version from build.gradle.kts
id: get_version
run: |
CURRENT_VERSION_NAME=$(grep 'versionName = ' app/build.gradle.kts | sed 's/.*versionName = "\(.*\)".*/\1/')
CURRENT_VERSION_CODE=$(grep 'versionCode = ' app/build.gradle.kts | sed 's/.*versionCode = \(.*\)/\1/')
NEW_VERSION_CODE=$((CURRENT_VERSION_CODE + 1))
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION_NAME"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
NEW_MINOR=$((MINOR + 1))
NEW_VERSION_NAME="$MAJOR.$(printf "%02d" $NEW_MINOR)"
echo "current_version_name=$CURRENT_VERSION_NAME" >> $GITHUB_OUTPUT
echo "current_version_code=$CURRENT_VERSION_CODE" >> $GITHUB_OUTPUT
echo "new_version_name=$NEW_VERSION_NAME" >> $GITHUB_OUTPUT
echo "new_version_code=$NEW_VERSION_CODE" >> $GITHUB_OUTPUT
echo "Current Version: $CURRENT_VERSION_NAME ($CURRENT_VERSION_CODE)"
echo "New Version: $NEW_VERSION_NAME ($NEW_VERSION_CODE)"
- name: Update version in build.gradle.kts
run: |
sed -i "s/versionName = \".*\"/versionName = \"${{ steps.get_version.outputs.new_version_name }}\"/" app/build.gradle.kts
sed -i "s/versionCode = .*/versionCode = ${{ steps.get_version.outputs.new_version_code }}/" app/build.gradle.kts
- name: Decode and setup keystore
run: |
mkdir -p keystore_details
echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | tr -d ' \n\r' | base64 -d > keystore_details/sensor.jks
- name: Read keystore properties
id: keystore_properties
run: |
echo "store_password=$(grep 'storePassword' keystore_details/keystore.properties | cut -d'=' -f2)" >> $GITHUB_OUTPUT
echo "key_password=$(grep 'keyPassword' keystore_details/keystore.properties | cut -d'=' -f2)" >> $GITHUB_OUTPUT
echo "key_alias=$(grep 'keyAlias' keystore_details/keystore.properties | cut -d'=' -f2)" >> $GITHUB_OUTPUT
- name: Build AAB (bundleRelease)
env:
ANDROID_KEYSTORE_PATH: ${{ github.workspace }}/keystore_details/sensor.jks
ANDROID_KEYSTORE_PASSWORD: ${{ steps.keystore_properties.outputs.store_password }}
ANDROID_KEY_ALIAS: ${{ steps.keystore_properties.outputs.key_alias }}
ANDROID_KEY_PASSWORD: ${{ steps.keystore_properties.outputs.key_password }}
run: ./gradlew bundleRelease
- name: Rename AAB file
run: |
mv app/build/outputs/bundle/release/app-release.aab \
app/build/outputs/bundle/release/SensorApp-v${{ steps.get_version.outputs.new_version_name }}-release.aab
- name: Generate release notes
id: notes
run: |
prev_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$prev_tag" ]; then
notes=$(git log "$prev_tag"..HEAD --oneline --no-merges --format="- %s" 2>/dev/null || true)
else
notes=$(git log --oneline --no-merges --format="- %s" -20 2>/dev/null || true)
fi
if [ -z "$notes" ]; then
notes="- Bug fixes and improvements"
fi
mkdir -p whatsnew
echo "$notes" > whatsnew/default
echo "notes_file=whatsnew/default" >> "$GITHUB_OUTPUT"
- name: Upload to Google Play Store
uses: r0adkll/upload-google-play@v1.1.3
with:
serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}
packageName: com.shreyash.sensorapp
releaseFiles: app/build/outputs/bundle/release/SensorApp-v${{ steps.get_version.outputs.new_version_name }}-release.aab
track: ${{ github.event.inputs.deploymentType }}
status: 'completed'
inAppUpdatePriority: 2
releaseName: SensorApp v${{ steps.get_version.outputs.new_version_name }}
whatsNewDirectory: whatsnew/
- name: Upload AAB Artifact
uses: actions/upload-artifact@v4.6.2
with:
name: SensorApp-AAB-v${{ steps.get_version.outputs.new_version_name }}
path: app/build/outputs/bundle/release/SensorApp-v${{ steps.get_version.outputs.new_version_name }}-release.aab
- name: Create Release Tag
if: github.event.inputs.deploymentType == 'production'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -a "v${{ steps.get_version.outputs.new_version_name }}" -m "Release v${{ steps.get_version.outputs.new_version_name }}"
git push origin "v${{ steps.get_version.outputs.new_version_name }}"
- name: Update version in repository
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add app/build.gradle.kts
git commit -m "Bump version to ${{ steps.get_version.outputs.new_version_name }} (${{ steps.get_version.outputs.new_version_code }})" || exit 0
git push origin ${{ github.event.inputs.branch }}