-
Notifications
You must be signed in to change notification settings - Fork 2
177 lines (152 loc) · 5.07 KB
/
build.yml
File metadata and controls
177 lines (152 loc) · 5.07 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
name: Build
on:
push:
branches: [master]
paths:
- 'app/**'
- 'module/**'
- 'gradle/**'
- 'build.gradle.kts'
- 'settings.gradle.kts'
- 'gradle.properties'
- 'scripts/**'
- '.github/workflows/build.yml'
pull_request:
branches: [master]
paths:
- 'app/**'
- 'gradle/**'
- 'build.gradle.kts'
- 'settings.gradle.kts'
- 'gradle.properties'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
profile: [debug, release]
steps:
- uses: actions/checkout@v4
- name: Bump patch version
if: github.event_name == 'push'
run: |
prop="module/module.prop"
ver=$(grep '^version=' "$prop" | cut -d= -f2)
code=$(grep '^versionCode=' "$prop" | cut -d= -f2)
new_code=$((code + 1))
# Bump patch: v3.1 -> v3.2, v3.1.2 -> v3.1.3
base="${ver%.*}"
patch="${ver##*.}"
if echo "$patch" | grep -qE '^[0-9]+$'; then
new_ver="${base}.$((patch + 1))"
else
new_ver="${ver}.1"
fi
sed -i "s/^version=.*/version=${new_ver}/" "$prop"
sed -i "s/^versionCode=.*/versionCode=${new_code}/" "$prop"
echo "Bumped: $ver ($code) -> $new_ver ($new_code)"
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- uses: gradle/actions/setup-gradle@v4
with:
validate-wrappers: false
- name: Decode keystore
if: matrix.profile == 'release'
run: echo "${{ secrets.RELEASE_KEYSTORE }}" | base64 -d > release.jks
- name: Build APK (${{ matrix.profile }})
run: |
if [ "$PROFILE" = "release" ]; then
./gradlew assembleRelease --no-daemon
else
./gradlew assembleDebug --no-daemon
fi
env:
PROFILE: ${{ matrix.profile }}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
- name: Verify R8 shrinking (release only)
if: matrix.profile == 'release'
run: |
APK="app/build/outputs/apk/release/app-release.apk"
SIZE=$(stat -c%s "$APK")
echo "Release APK size: $((SIZE / 1024)) KB"
if [ "$SIZE" -gt 10485760 ]; then
echo "::warning::Release APK exceeds 10MB — R8 shrinking may not be effective"
fi
- uses: actions/upload-artifact@v4
with:
name: apk-${{ matrix.profile }}
path: app/build/outputs/apk/${{ matrix.profile }}/app-${{ matrix.profile }}.apk
retention-days: 7
package:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Read version
id: ver
run: echo "version=$(grep '^version=' module/module.prop | cut -d= -f2)" >> "$GITHUB_OUTPUT"
- name: Package ZIPs
run: |
ver="${{ steps.ver.outputs.version }}"
mkdir -p out/release out/debug
bash scripts/package.sh --apk="artifacts/apk-release/app-release.apk"
mv "out/UsbMassStorage-${ver}.zip" "out/release/"
bash scripts/package.sh --apk="artifacts/apk-debug/app-debug.apk"
mv "out/UsbMassStorage-${ver}.zip" "out/debug/UsbMassStorage-${ver}-debug.zip"
- uses: actions/upload-artifact@v4
with:
name: usbmassstorage-release-zip
path: out/release/*.zip
retention-days: 30
- uses: actions/upload-artifact@v4
with:
name: usbmassstorage-debug-zip
path: out/debug/*.zip
retention-days: 30
release:
needs: [build, package]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Read version
id: ver
run: echo "version=$(grep '^version=' module/module.prop | cut -d= -f2)" >> "$GITHUB_OUTPUT"
- uses: actions/download-artifact@v4
with:
name: usbmassstorage-release-zip
path: zips/release
- uses: actions/download-artifact@v4
with:
name: usbmassstorage-debug-zip
path: zips/debug
- name: Extract changelog
run: |
ver="${VER}"
awk "/^## ${ver}/{flag=1; next} /^## v/{if(flag) exit} flag" CHANGELOG.md > /tmp/notes.md
cat /tmp/notes.md
env:
VER: ${{ steps.ver.outputs.version }}
- name: Create release
run: |
gh release delete "$VER" --yes 2>/dev/null || true
gh release create "$VER" \
--title "$VER" \
--latest \
--notes-file /tmp/notes.md \
zips/release/*.zip \
zips/debug/*.zip
env:
VER: ${{ steps.ver.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}