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
129name: Build and Release
on:
push:
branches: [ main ]
jobs:
build-and-release:
name: Build APK and Create Pre-Release
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write # Required to create releases
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all history for version info
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v21
- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v13
- name: Get version from build.gradle.kts
id: version
run: |
VERSION_NAME=$(grep 'versionName = ' app/build.gradle.kts | sed 's/.*versionName = "\(.*\)".*/\1/')
VERSION_CODE=$(grep 'versionCode = ' app/build.gradle.kts | sed 's/.*versionCode = \(.*\)/\1/')
SHORT_SHA=$(git rev-parse --short HEAD)
echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT
echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
echo "tag=v${VERSION_NAME}-${SHORT_SHA}" >> $GITHUB_OUTPUT
- name: Build debug APK with Nix
run: |
nix develop --command bash -c '
echo "Building MoodTracker v${{ steps.version.outputs.version_name }}"
echo "Environment setup:"
echo " ANDROID_HOME: $ANDROID_HOME"
echo " JAVA_HOME: $JAVA_HOME"
chmod +x ./gradlew
./gradlew assembleDebug \
--parallel \
--build-cache \
--configuration-cache \
--no-daemon \
--stacktrace
'
- name: Rename APKs with version
run: |
VERSION="${{ steps.version.outputs.version_name }}"
SHORT_SHA="${{ steps.version.outputs.short_sha }}"
cd app/build/outputs/apk/debug
for apk in *.apk; do
if [[ $apk == "app-debug.apk" ]]; then
# Universal APK (no ABI splits)
NEW_NAME="MoodTracker-${VERSION}-${SHORT_SHA}.apk"
mv "$apk" "$NEW_NAME"
echo "Renamed: $apk -> $NEW_NAME"
elif [[ $apk =~ app-(.+)-debug\.apk ]]; then
# ABI-specific APK (e.g., app-arm64-v8a-debug.apk -> arm64-v8a)
ABI="${BASH_REMATCH[1]}"
NEW_NAME="MoodTracker-${VERSION}-${SHORT_SHA}-${ABI}.apk"
mv "$apk" "$NEW_NAME"
echo "Renamed: $apk -> $NEW_NAME"
fi
done
ls -lh
- name: Generate release notes
id: release_notes
run: |
cat > release_notes.md << EOF
## MoodTracker v${{ steps.version.outputs.version_name }}
**Build:** \`${{ steps.version.outputs.short_sha }}\`
**Version Code:** ${{ steps.version.outputs.version_code }}
### Installation
Download the appropriate APK for your device architecture:
- **arm64-v8a**: Modern 64-bit ARM devices (most recent Android phones)
- **armeabi-v7a**: Older 32-bit ARM devices
- **x86_64**: 64-bit x86 devices (emulators, some tablets)
- **x86**: 32-bit x86 devices (older emulators)
- **universal**: Works on all architectures (larger file size)
### Changes
Built from commit [\`${{ github.sha }}\`](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
---
*This is an automated pre-release build. For production use, please wait for a stable release.*
EOF
cat release_notes.md
- name: Create pre-release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: "MoodTracker v${{ steps.version.outputs.version_name }} (${{ steps.version.outputs.short_sha }})"
body_path: release_notes.md
draft: false
prerelease: true
files: app/build/outputs/apk/debug/MoodTracker-*.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload build artifacts
uses: actions/upload-artifact@v5
with:
name: debug-apks-${{ steps.version.outputs.tag }}
path: app/build/outputs/apk/debug/MoodTracker-*.apk
compression-level: 0
retention-days: 30