Skip to content

Commit 5e36d8e

Browse files
m-tsuruscrwnl
andauthored
Meta: Generate APK Files on GitHub Actions (#12)
--------- Co-authored-by: Mahiro Saeki a.k.a. Nejikugi <63852665+scrwnl@users.noreply.github.com>
1 parent 4021782 commit 5e36d8e

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

.github/workflows/android.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: build release apk
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- name: Get version from tag
17+
id: get_version
18+
run: |
19+
if [[ $GITHUB_REF == refs/tags/* ]]; then
20+
VERSION=${GITHUB_REF#refs/tags/}
21+
else
22+
VERSION=$(git describe --tags --always --dirty)
23+
fi
24+
echo "version=$VERSION" >> $GITHUB_OUTPUT
25+
echo "Version: $VERSION"
26+
- name: set up JDK 17
27+
uses: actions/setup-java@v4
28+
with:
29+
java-version: '17'
30+
distribution: 'temurin'
31+
cache: gradle
32+
- name: Grant execute permission for gradlew
33+
run: chmod +x gradlew
34+
- name: build Release
35+
run: ./gradlew assembleRelease
36+
- name: Create Release
37+
uses: svenstaro/upload-release-action@v2
38+
with:
39+
repo_token: ${{ secrets.GITHUB_TOKEN }}
40+
file: app/build/outputs/apk/release/app-release.apk
41+
asset_name: yuredroid-${{ steps.get_version.outputs.version }}.apk
42+
tag: ${{ github.ref }}
43+
overwrite: true
44+
body: "Yure Android Client ${{ steps.get_version.outputs.version }}"

app/build.gradle.kts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ plugins {
44
alias(libs.plugins.kotlin.compose)
55
}
66

7+
fun getGitVersion(): String {
8+
return try {
9+
val process = Runtime.getRuntime().exec("git describe --tags --always --dirty")
10+
val version = process.inputStream.bufferedReader().readText().trim()
11+
if (version.startsWith("v")) version.substring(1) else version
12+
} catch (e: Exception) {
13+
"1.0.0-beta" // Fallback version
14+
}
15+
}
16+
17+
fun getVersionCode(): Int {
18+
return try {
19+
val process = Runtime.getRuntime().exec("git rev-list --count HEAD")
20+
process.inputStream.bufferedReader().readText().trim().toInt()
21+
} catch (e: Exception) {
22+
1 // Fallback version code
23+
}
24+
}
25+
726
android {
827
namespace = "com.sasakulab.yure_android_client"
928
compileSdk {
@@ -14,8 +33,8 @@ android {
1433
applicationId = "com.sasakulab.yure_android_client"
1534
minSdk = 26
1635
targetSdk = 36
17-
versionCode = 1
18-
versionName = "1.2.0"
36+
versionCode = getVersionCode()
37+
versionName = getGitVersion()
1938

2039
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2140
}

0 commit comments

Comments
 (0)