From 72d3d3a79778333ec066c5d93188ef04b9dbe4ec Mon Sep 17 00:00:00 2001 From: Emma Date: Sat, 3 Feb 2024 12:31:36 -0500 Subject: [PATCH] Add CI for new android build --- .github/workflows/buildAndroid.yml | 48 ++++++++++++++++++++++++++++++ android/app/build.gradle.kts | 34 +++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/buildAndroid.yml diff --git a/.github/workflows/buildAndroid.yml b/.github/workflows/buildAndroid.yml new file mode 100644 index 000000000000..119cd9b7cbb5 --- /dev/null +++ b/.github/workflows/buildAndroid.yml @@ -0,0 +1,48 @@ +name: Build Android + +on: + push: + branches: [ "android" ] + pull_request: + branches: [ "android" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: 📚Read package.json + id: pkg + uses: jaywcjlove/github-action-package@v1.3.0 + + - name: Set Version Number Variable + id: versionNumber + uses: actions/github-script@v6 + with: + result-encoding: string + script: | + return '${{ steps.pkg.outputs.version }}-new-nightly-${{ github.run_number }}' + + - name: Move into directory + run: cd android/ + + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: cd android/ && ../gradlew build + + - name: 📡 Upload APK Artifact + uses: actions/upload-artifact@v3 + with: + name: freetube-${{ steps.versionNumber.outputs.result }}-Android.apk + path: app/build/outputs/apk/debug/app-debug.apk diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index bd8af5775df7..12c98433765e 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -1,3 +1,31 @@ +import groovy.json.JsonSlurper + +fun getVersionInfo(project: Project): Pair? { + val json = JsonSlurper() + val packageJsonPath = project.file("../../package.json") + + val packageJson = json.parse(packageJsonPath) as Map + val versionName = packageJson["version"] as String + + val parts = versionName.split("-") + val numbers = parts[0].split(".") + val major = numbers[0].toInt() + val minor = numbers[1].toInt() + val patch = numbers[2].toInt() + var build = 0 + if (parts.size > 2) { + build = parts[2].toInt() + } else if (numbers.size > 3) { + build = numbers[3].toInt() + } + + val versionCode = major * 10000000 + minor * 10000000 + patch * 1000 + build + + return Pair(versionName, versionCode) +} + +val versionInfo = getVersionInfo(project) + plugins { id("com.android.application") id("org.jetbrains.kotlin.android") @@ -10,11 +38,11 @@ android { enable = true } defaultConfig { - applicationId = "io.freetubeapp.freetube.newdevelopment" + applicationId = "io.freetubeapp.freetube.development" minSdk = 24 targetSdk = 34 - versionCode = 1 - versionName = "1.0" + versionCode = versionInfo!!.second + versionName = versionInfo!!.first testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" }