-
Notifications
You must be signed in to change notification settings - Fork 0
242 lines (219 loc) · 8.74 KB
/
release.yml
File metadata and controls
242 lines (219 loc) · 8.74 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
236
237
238
239
240
241
242
name: Build and Release
on:
push:
branches:
- main
permissions:
contents: write
checks: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
test-gate:
name: Test Gate
runs-on: ubuntu-latest
if: "!startsWith(github.event.head_commit.message, 'chore: bump version')"
steps:
- uses: actions/checkout@v4
- name: Setup Java 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Run unit tests
run: ./gradlew test --continue
- name: Run lint
run: ./gradlew lintRelease
- name: Verify FreeRDP AAR exists
run: |
if [ ! -f core/rdp/libs/freerdp-android.aar ]; then
echo "::error::FreeRDP AAR missing - trigger Build FreeRDP AAR workflow and pull the auto-commit"
exit 1
fi
SIZE=$(stat -c %s core/rdp/libs/freerdp-android.aar)
if [ "$SIZE" -lt 1000000 ]; then
echo "::error::AAR too small ($SIZE bytes) - likely corrupt"
exit 1
fi
- name: Upload test results on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-results
path: "**/build/test-results/test/*.xml"
build:
name: Build and Publish
runs-on: ubuntu-latest
needs: test-gate
if: "!startsWith(github.event.head_commit.message, 'chore: bump version')"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Java 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Determine version bump
id: bump
shell: bash
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
run: |
CURRENT=$(grep 'versionName' app/build.gradle.kts | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
FIRST_LINE=$(echo "$COMMIT_MSG" | head -1)
if echo "$FIRST_LINE" | grep -qE "^feat(\(.+\))?:"; then
MINOR=$((MINOR + 1))
PATCH=0
BUMP="minor"
else
PATCH=$((PATCH + 1))
BUMP="patch"
fi
NEW="${MAJOR}.${MINOR}.${PATCH}"
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
echo "new=$NEW" >> "$GITHUB_OUTPUT"
echo "bump=$BUMP" >> "$GITHUB_OUTPUT"
echo "tag=v$NEW" >> "$GITHUB_OUTPUT"
echo "Version: $CURRENT -> $NEW ($BUMP)"
- name: Check if tag already exists
id: check_tag
shell: bash
env:
TAG: ${{ steps.bump.outputs.tag }}
run: |
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Update version in build.gradle.kts
if: steps.check_tag.outputs.exists == 'false'
shell: bash
env:
NEW_VERSION: ${{ steps.bump.outputs.new }}
run: |
IFS='.' read -r MAJOR MINOR PATCH <<< "$NEW_VERSION"
NEW_VERSION_CODE=$(( MAJOR * 10000 + MINOR * 100 + PATCH ))
sed -i "s/versionName = \"[0-9]*\.[0-9]*\.[0-9]*\"/versionName = \"$NEW_VERSION\"/" app/build.gradle.kts
sed -i "s/versionCode = [0-9]*/versionCode = $NEW_VERSION_CODE/" app/build.gradle.kts
echo "Updated versionName=$NEW_VERSION versionCode=$NEW_VERSION_CODE"
- name: Update CHANGELOG
if: steps.check_tag.outputs.exists == 'false'
shell: bash
env:
NEW_VERSION: ${{ steps.bump.outputs.new }}
COMMIT_MSG: ${{ github.event.head_commit.message }}
run: |
FIRST_LINE=$(echo "$COMMIT_MSG" | head -1)
DATE=$(date +%Y-%m-%d)
if echo "$FIRST_LINE" | grep -qE "^feat"; then
SECTION="Features"
ENTRY=$(echo "$FIRST_LINE" | sed 's/^feat[^:]*: //')
elif echo "$FIRST_LINE" | grep -qE "^fix"; then
SECTION="Fixes"
ENTRY=$(echo "$FIRST_LINE" | sed 's/^fix[^:]*: //')
else
SECTION="Changes"
ENTRY=$(echo "$FIRST_LINE" | sed 's/^[a-z]*[^:]*: //')
fi
if [ -f CHANGELOG.md ]; then
TEMP=$(mktemp)
awk -v block="## [$NEW_VERSION] - $DATE\n\n### $SECTION\n- $ENTRY\n\n---" '
/^# Changelog/ { print; print ""; print block; next }
{ print }
' CHANGELOG.md > "$TEMP"
mv "$TEMP" CHANGELOG.md
fi
- name: Setup signing
if: steps.check_tag.outputs.exists == 'false'
shell: bash
run: |
if [ -n "$KEYSTORE_BASE64" ]; then
echo "$KEYSTORE_BASE64" | base64 -d > keystore.jks
else
keytool -genkey -v -keystore keystore.jks -keyalg RSA -keysize 2048 -validity 10000 \
-alias gatecontrol -storepass android -keypass android \
-dname "CN=GateControl, OU=Dev, O=GateControl, C=DE"
fi
echo "KEYSTORE_PATH=$(pwd)/keystore.jks" >> "$GITHUB_ENV"
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
- name: Build APK and AAB
if: steps.check_tag.outputs.exists == 'false'
shell: bash
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
./gradlew assembleRelease bundleRelease assembleDebug
- name: Verify R8 obfuscation
if: steps.check_tag.outputs.exists == 'false'
run: |
if [ ! -f app/build/outputs/mapping/release/mapping.txt ]; then
echo "::error::R8 mapping.txt not found — minification may not be active"
exit 1
fi
SIZE=$(wc -c < app/build/outputs/mapping/release/mapping.txt)
if [ "$SIZE" -lt 1000 ]; then
echo "::error::R8 mapping.txt is suspiciously small (${SIZE} bytes) — minification may not be working"
exit 1
fi
echo "R8 mapping.txt verified (${SIZE} bytes)"
- name: Rename and package artifacts
if: steps.check_tag.outputs.exists == 'false'
shell: bash
env:
NEW_VERSION: ${{ steps.bump.outputs.new }}
run: |
mv app/build/outputs/apk/release/app-release.apk "app/build/outputs/apk/release/GateControl-Android-${NEW_VERSION}.apk"
mv app/build/outputs/bundle/release/app-release.aab "app/build/outputs/bundle/release/GateControl-Android-${NEW_VERSION}.aab"
# Package R8 mapping file for Play Console
cp app/build/outputs/mapping/release/mapping.txt "app/build/outputs/mapping/release/GateControl-Android-${NEW_VERSION}-mapping.txt"
# Package native debug symbols for Play Console
if [ -d app/build/outputs/native-debug-symbols/release ]; then
cd app/build/outputs/native-debug-symbols/release
zip -r "../../../../GateControl-Android-${NEW_VERSION}-native-debug-symbols.zip" .
cd -
fi
# Debug APK for crash diagnosis
if [ -f app/build/outputs/apk/debug/app-debug.apk ]; then
mv app/build/outputs/apk/debug/app-debug.apk "app/build/outputs/apk/debug/GateControl-Android-${NEW_VERSION}-debug.apk"
fi
- name: Commit version bump
if: steps.check_tag.outputs.exists == 'false'
shell: bash
env:
TAG: ${{ steps.bump.outputs.tag }}
NEW_VERSION: ${{ steps.bump.outputs.new }}
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add app/build.gradle.kts CHANGELOG.md
git commit -m "chore: bump version to $NEW_VERSION"
git tag "$TAG"
git push origin main --tags
- name: Create GitHub Release
if: steps.check_tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.bump.outputs.tag }}
name: "GateControl Android ${{ steps.bump.outputs.tag }}"
generate_release_notes: true
files: |
app/build/outputs/apk/release/GateControl-Android-*.apk
app/build/outputs/apk/debug/GateControl-Android-*-debug.apk
app/build/outputs/bundle/release/GateControl-Android-*.aab
app/build/outputs/mapping/release/GateControl-Android-*-mapping.txt
app/GateControl-Android-*-native-debug-symbols.zip