Skip to content

Commit 7350c67

Browse files
committed
auto build release apk through gh actions
1 parent 52f5f11 commit 7350c67

File tree

2 files changed

+94
-38
lines changed

2 files changed

+94
-38
lines changed

.github/workflows/release.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ on:
99
env:
1010
VERSION_BRANCH: version
1111
VERSION_FILE: version.properties
12+
ARTIFACT_APK: release.apk
13+
ARTIFACT_MAPPINGS: mappings
1214

1315
jobs:
1416
build:
1517
runs-on: ubuntu-latest
18+
env:
19+
QNEVO_SIGNING_STORE_PATH: ${{ github.workspace }}/release.jks
1620

1721
steps:
1822
- uses: actions/checkout@v4
@@ -27,6 +31,33 @@ jobs:
2731
- name: Grant execute permission for gradlew
2832
run: chmod +x gradlew
2933

34+
- name: Write KeyStore File
35+
uses: RollyPeres/base64-to-path@v1
36+
with:
37+
filePath: ${{ env.QNEVO_SIGNING_STORE_PATH }}
38+
encodedString: ${{ secrets.SIGNING_KEYSTORE }}
39+
40+
- name: Assemble Release APK
41+
run: ./gradlew assembleRelease
42+
env:
43+
QNEVO_SIGNING_STORE_PWD: ${{ secrets.SIGNING_STORE_PASSWORD }}
44+
QNEVO_SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
45+
QNEVO_SIGNING_KEY_PWD: ${{ secrets.SIGNING_KEY_PASSWORD }}
46+
47+
- name: Upload APK
48+
uses: actions/upload-artifact@v3
49+
with:
50+
name: ${{ env.ARTIFACT_APK }}
51+
path: "app/build/outputs/apk/release/app-release.apk"
52+
if-no-files-found: error
53+
54+
- name: Upload Mapping Files
55+
uses: actions/upload-artifact@v3
56+
with:
57+
name: ${{ env.ARTIFACT_MAPPINGS }}
58+
path: "app/build/outputs/mapping/release"
59+
if-no-files-found: error
60+
3061
- name: Generate Version Info
3162
run: ./gradlew appVersion
3263

@@ -38,6 +69,37 @@ jobs:
3869
if-no-files-found: error
3970
retention-days: 1
4071

72+
draft-release:
73+
runs-on: ubuntu-latest
74+
needs: build
75+
permissions:
76+
contents: write
77+
78+
steps:
79+
- name: Download APK
80+
uses: actions/download-artifact@v3
81+
with:
82+
name: ${{ env.ARTIFACT_APK }}
83+
84+
- name: Download Mappings
85+
uses: actions/download-artifact@v3
86+
with:
87+
name: ${{ env.ARTIFACT_MAPPINGS }}
88+
path: mappings
89+
90+
- name: Tar Mapping Files
91+
run: |
92+
cd mappings
93+
tar -zcf mappings.tar.gz ./*
94+
mv mappings.tar.gz ../
95+
cd ..
96+
97+
- name: Release
98+
uses: ncipollo/release-action@v1
99+
with:
100+
draft: true
101+
artifactErrorsFailBuild: true
102+
artifacts: "app-release.apk,mappings.tar.gz"
41103

42104
# commit the version file to 'version' branch so that F-Droid can utilize it for new version detecting
43105
update-version:

app/build.gradle.kts

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import org.jetbrains.kotlin.config.JvmTarget
2-
import java.io.ByteArrayOutputStream
32
import java.util.Properties
43

54
plugins {
@@ -32,11 +31,25 @@ android {
3231
// must correspond to kotlin version: https://developer.android.com/jetpack/androidx/releases/compose-kotlin#pre-release_kotlin_compatibility
3332
kotlinCompilerExtensionVersion = "1.5.3"
3433
}
34+
signingConfigs {
35+
readSigningConfig()?.also { config ->
36+
logger.lifecycle("Use key alias '{}' to sign release", config.keyAlias)
37+
create("release") {
38+
storeFile = config.storeFile
39+
storePassword = "chenhe"
40+
keyAlias = "weargallery"
41+
keyPassword = "chenhe"
42+
43+
enableV2Signing = true
44+
}
45+
}
46+
}
3547
buildTypes {
3648
release {
3749
isMinifyEnabled = true
3850
isShrinkResources = true
3951
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
52+
signingConfigs.findByName("release")?.also { signingConfig = it }
4053
}
4154
}
4255
compileOptions {
@@ -80,43 +93,24 @@ dependencies {
8093
testImplementation("org.json:json:20231013") // JSONObject
8194
}
8295

83-
fun String.runCommand(currentWorkingDir: File = file("./")): String {
84-
val byteOut = ByteArrayOutputStream()
85-
project.exec {
86-
workingDir = currentWorkingDir
87-
commandLine = this@runCommand.split(" ")
88-
standardOutput = byteOut
89-
}
90-
return String(byteOut.toByteArray()).trim()
91-
}
92-
93-
fun getVersionCode(): Int {
94-
val cmd = "git rev-list HEAD --first-parent --count"
95-
return try {
96-
cmd.runCommand().toInt()
97-
} catch (e: Exception) {
98-
logger.error("Failed to get version code with git, return 1 by default.\n${e.message}")
99-
1
100-
}
101-
}
96+
data class SigningConfig(
97+
val storeFile: File,
98+
val storePwd: String,
99+
val keyAlias: String,
100+
val keyPwd: String,
101+
)
102102

103-
104-
fun getVersionName(): String {
105-
val cmd = "git describe --tags --long --first-parent --abbrev=7 --dirty=_dev"
106-
try {
107-
val v = cmd.runCommand()
108-
val pattern = """^v(?<v>[\d|.]+)-\d+-g[A-Za-z0-9]{7}(?<s>_dev)?$""".toRegex()
109-
val g = pattern.matchEntire(v)?.groups
110-
if (g == null || g["v"] == null) {
111-
logger.error(
112-
"Failed to get version name with git.\n" +
113-
"Cannot match git tag describe, return <UNKNOWN> by default. raw=$v"
114-
)
115-
return "UNKNOWN"
116-
}
117-
return g["v"]!!.value + (g["s"]?.value ?: "")
118-
} catch (e: Exception) {
119-
logger.error("Failed to get version name with git, return <UNKNOWN> by default.\n${e.message}")
120-
return "UNKNOWN"
103+
fun readSigningConfig(): SigningConfig? {
104+
val path = System.getenv("QNEVO_SIGNING_STORE_PATH") ?: return null
105+
val f = File(path)
106+
if (!f.isFile) {
107+
logger.warn("Key store file not exist: {}", path)
108+
return null
121109
}
110+
return SigningConfig(
111+
storeFile = f,
112+
storePwd = System.getenv("QNEVO_SIGNING_STORE_PWD") ?: return null,
113+
keyAlias = System.getenv("QNEVO_SIGNING_KEY_ALIAS") ?: return null,
114+
keyPwd = System.getenv("QNEVO_SIGNING_KEY_PWD") ?: return null
115+
)
122116
}

0 commit comments

Comments
 (0)