forked from doudar/grupetto
-
Notifications
You must be signed in to change notification settings - Fork 0
235 lines (194 loc) · 8.56 KB
/
Copy pathandroid.yml
File metadata and controls
235 lines (194 loc) · 8.56 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Android CI/CD
on:
push:
branches: [ "develop", "main" ]
pull_request:
branches: [ "develop", "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Configure release signing
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
mkdir -p app
echo "$SIGNING_KEY" | base64 -d > app/release.keystore
cat <<EOF > keystore.properties
storeFile=release.keystore
storePassword=$KEY_STORE_PASSWORD
keyAlias=$KEY_ALIAS
keyPassword=$KEY_PASSWORD
EOF
- name: Extract version info
id: version_info
run: |
VERSION_NAME=$(grep "versionName" app/build.gradle | cut -d'"' -f2)
VERSION_CODE=$(grep "versionCode" app/build.gradle | awk '{print $2}')
# Get the latest tag and increment it
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag found: $LATEST_TAG"
# Extract version numbers (remove 'v' prefix and split by dots)
VERSION_NUMBERS=$(echo $LATEST_TAG | sed 's/^v//' | tr '.' ' ')
read -r MAJOR MINOR PATCH <<< "$VERSION_NUMBERS"
# Default to 0.0.0 if parsing fails
MAJOR=${MAJOR:-0}
MINOR=${MINOR:-0}
PATCH=${PATCH:-0}
# Increment patch version
NEW_PATCH=$((PATCH + 1))
NEW_TAG="v${MAJOR}.${MINOR}.${NEW_PATCH}"
# Calculate new version code (increment current version code)
NEW_VERSION_CODE=$((VERSION_CODE + 1))
echo "New tag will be: $NEW_TAG"
echo "New version code will be: $NEW_VERSION_CODE"
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_OUTPUT
echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_OUTPUT
echo "NEW_VERSION_CODE=$NEW_VERSION_CODE" >> $GITHUB_OUTPUT
echo "TAG_NAME=$NEW_TAG" >> $GITHUB_OUTPUT
echo "PREVIOUS_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: Update build.gradle versions
run: |
# Update versionName to match the new tag
sed -i "s/versionName \".*\"/versionName \"${{ steps.version_info.outputs.TAG_NAME }}\"/" app/build.gradle
# Update versionCode to incremented value
sed -i "s/versionCode [0-9]*/versionCode ${{ steps.version_info.outputs.NEW_VERSION_CODE }}/" app/build.gradle
# Verify changes
echo "Updated build.gradle versions:"
grep -E "(versionCode|versionName)" app/build.gradle
- name: Build release APK
run: ./gradlew assembleRelease
- name: List APK outputs
run: |
echo "Listing all APK files generated:"
find app/build/outputs/apk -name "*.apk" -type f || echo "No APK files found"
echo "Directory structure:"
ls -la app/build/outputs/apk/ || echo "APK output directory not found"
- name: Upload release APK as artifact
uses: actions/upload-artifact@v4
with:
name: release-apk
path: app/build/outputs/apk/release/app-release.apk
release:
if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main')
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version info
id: version_info
run: |
VERSION_NAME=$(grep "versionName" app/build.gradle | cut -d'"' -f2)
VERSION_CODE=$(grep "versionCode" app/build.gradle | awk '{print $2}')
# Get the latest tag and increment it
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag found: $LATEST_TAG"
# Extract version numbers (remove 'v' prefix and split by dots)
VERSION_NUMBERS=$(echo $LATEST_TAG | sed 's/^v//' | tr '.' ' ')
read -r MAJOR MINOR PATCH <<< "$VERSION_NUMBERS"
# Default to 0.0.0 if parsing fails
MAJOR=${MAJOR:-0}
MINOR=${MINOR:-0}
PATCH=${PATCH:-0}
# Increment patch version
NEW_PATCH=$((PATCH + 1))
NEW_TAG="v${MAJOR}.${MINOR}.${NEW_PATCH}"
# Calculate new version code (increment current version code)
NEW_VERSION_CODE=$((VERSION_CODE + 1))
echo "New tag will be: $NEW_TAG"
echo "New version code will be: $NEW_VERSION_CODE"
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_OUTPUT
echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_OUTPUT
echo "NEW_VERSION_CODE=$NEW_VERSION_CODE" >> $GITHUB_OUTPUT
echo "TAG_NAME=$NEW_TAG" >> $GITHUB_OUTPUT
echo "PREVIOUS_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: Update build.gradle versions
run: |
# Update versionName to match the new tag
sed -i "s/versionName \".*\"/versionName \"${{ steps.version_info.outputs.TAG_NAME }}\"/" app/build.gradle
# Update versionCode to incremented value
sed -i "s/versionCode [0-9]*/versionCode ${{ steps.version_info.outputs.NEW_VERSION_CODE }}/" app/build.gradle
# Verify changes
echo "Updated build.gradle versions:"
grep -E "(versionCode|versionName)" app/build.gradle
- name: Commit version updates
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add app/build.gradle
git commit -m "Auto-update version to ${{ steps.version_info.outputs.TAG_NAME }} (build ${{ steps.version_info.outputs.NEW_VERSION_CODE }})" || echo "No changes to commit"
git push origin HEAD:${{ github.ref_name }} || echo "Failed to push version update"
- name: Download release APK
uses: actions/download-artifact@v4
with:
name: release-apk
path: ./
- name: Find and prepare APK
id: find_apk
run: |
# Find the APK file (could be signed or unsigned)
APK_FILE=$(find . -name "*.apk" -type f | head -1)
if [ -z "$APK_FILE" ]; then
echo "No APK file found!"
exit 1
fi
echo "Found APK: $APK_FILE"
echo "APK_PATH=$APK_FILE" >> $GITHUB_OUTPUT
- name: Create/Update tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.version_info.outputs.TAG_NAME }}" -m "Release ${{ steps.version_info.outputs.TAG_NAME }}"
git push origin "${{ steps.version_info.outputs.TAG_NAME }}"
- name: Create GitHub Release
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version_info.outputs.TAG_NAME }}
release_name: "Grupetto ${{ steps.version_info.outputs.TAG_NAME }}"
body: |
## Grupetto Release ${{ steps.version_info.outputs.TAG_NAME }}
**Version:** ${{ steps.version_info.outputs.TAG_NAME }}
**Previous Version:** ${{ steps.version_info.outputs.PREVIOUS_TAG }}
**Build Code:** ${{ steps.version_info.outputs.NEW_VERSION_CODE }} (was ${{ steps.version_info.outputs.VERSION_CODE }})
**Commit:** ${{ github.sha }}
### Changes
- Automated release from ${{ github.ref_name }} branch
- Auto-incremented from ${{ steps.version_info.outputs.PREVIOUS_TAG }}
- Updated app/build.gradle with new version numbers
### Installation
Download the APK file below and install on your Android device.
**Note:** You may need to enable "Install from unknown sources" in your device settings.
draft: false
prerelease: false
- name: Upload APK to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app-release.apk
asset_name: grupetto-${{ steps.version_info.outputs.TAG_NAME }}.apk
asset_content_type: application/vnd.android.package-archive