Skip to content

Commit

Permalink
Add build workflow for GitHub Actions
Browse files Browse the repository at this point in the history
Include Git hash in debug version name and detailed APK file name
  • Loading branch information
pilot51 committed Dec 4, 2023
1 parent 0b0a429 commit 434a446
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .github/workflows/auto-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "Auto Build"

on:
push:
branches:
- "main"
paths:
- "app/**"
- "build.gradle.kts"
- "gradle.properties"
- "settings.gradle.kts"
- "!**/.gitignore"
- "!app/src/*[Tt]est/**"

jobs:
build:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build Debug APK
id: build-debug
run: ./gradlew assembleDebug

- name: Automatic Releases
uses: marvinpinto/action-automatic-releases@latest
if: ${{ steps.build-debug.outcome == 'success' }}
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: true
title: "Auto build [debug]"
files: 'app/build/outputs/apk/**/*.apk'
20 changes: 19 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import com.android.build.gradle.internal.api.BaseVariantOutputImpl
import java.io.ByteArrayOutputStream
import java.io.FileInputStream
import java.util.*

Expand All @@ -30,6 +32,15 @@ if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}

val gitCommitHash by lazy {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "rev-parse", "--short", "HEAD")
standardOutput = stdout
}
stdout.toString().trim()
}

android {
namespace = "com.pilot51.voicenotify"
compileSdk = 33
Expand Down Expand Up @@ -71,7 +82,14 @@ android {
signingConfig = signingConfigs.getByName("release")
}
getByName("debug") {
versionNameSuffix = "-debug"
versionNameSuffix = "-debug [$gitCommitHash]"
}
}

applicationVariants.all {
outputs.all {
this as BaseVariantOutputImpl
outputFileName = "VoiceNotify_v${defaultConfig.versionName}-${name}_$gitCommitHash.apk"
}
}
}
Expand Down

0 comments on commit 434a446

Please sign in to comment.