Skip to content

Commit

Permalink
chore(build): update dependencies and Gradle settings (#313)
Browse files Browse the repository at this point in the history
* chore(build): update dependencies and Gradle settings

- Replace plugin IDs with versions from libs.versions.toml.
- Update compileSdk to 34.
- Update various dependencies to their latest versions.
- Modify onDraw method arguments to be non-nullable.
- Refactor build scripts to align with new dependency management practices.

* chore(deps): update buildTools and targetSdk to version 34.0.0

* feat(build): integrate spotless plugin and update versioning system

- Import `spotless` plugin and configure for Kotlin and Gradle scripts.
- Read versioning from `gradle.properties` and dynamically generate `versionCode` and `versionName`.
- Update APK file naming convention.
- Simplify and update GitHub Actions workflows for build and release.
- Remove deprecated configurations and improve caching mechanisms.

* fix(ci): rollback Java version from 21 to 17 in pr_pre_check.yml

* chore: remove setup of Android SDK from pr_pre_check.yml

* ci: update GitHub Actions to use setup-java and setup-gradle

Updated the `pr_pre_check.yml` and `release.yml` workflows to include `actions/setup-java@v4` with Zulu distribution and Java 17, along with caching for Gradle. Added `gradle/actions/setup-gradle@v3` with Gradle home cache cleanup.

* fix(ci): update Gradle commands for assembling debug and release builds

* fix: update Gradle version to wrapper in workflows
  • Loading branch information
rosuH committed Jul 14, 2024
1 parent 6e03bc4 commit e9ca85c
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 85 deletions.
44 changes: 29 additions & 15 deletions .github/workflows/pr_pre_check.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
name: PR Basic Check
name: Basic Check

on:
pull_request:
types: [opened,reopened,synchronize]
branches:
- master
- dev
jobs:
check:
name: Check
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Skip duplicate actions
uses: fkirc/skip-duplicate-actions@v5
with:
cancel_others: true
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'
- uses: gradle/actions/setup-gradle@v3
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
# - run: ./gradlew spotlessCheck
simple_compile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v2
- uses: actions/setup-java@v4
with:
distribution: 'adopt'
distribution: 'zulu'
java-version: 17
- name: Cache Gradle
uses: actions/cache@v2
cache: 'gradle'
- uses: gradle/actions/setup-gradle@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-app-${{ github.sha }}
restore-keys: |
gradle-
gradle-version: wrapper
gradle-home-cache-cleanup: true
- name: Build apk with Gradle
run: bash ./gradlew assembleRelease --scan --debug
run: ./gradlew :app:assembleDebug
37 changes: 37 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Generated APK AAB (Upload - Create Artifact To Github Action)

env:
# The name of the main module repository
main_project_module: app

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- id: fetchLatestRelease
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
excludes: prerelease, draft
token: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare Release Artifact
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: 'dsaltares/godot-wild-jam-18'
version: ${{ steps.keydb.fetchLatestRelease.release }}
file: '*.aab'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Android Release to Play Store
uses: r0adkll/[email protected]
with:
serviceAccountJsonPlainText: ${{ SERVICE_ACCOUNT_JSON }}
packageName: me.rosuh.easywatermark
releaseFiles: '*.aab'
track: production
status: inProgress
mappingFile: app/build/outputs/mapping/release/mapping.txt
91 changes: 66 additions & 25 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,97 @@
name: Android CI
name: Generated APK AAB (Upload - Create Artifact To Github Action)

env:
# The name of the main module repository
main_project_module: app

on:
# on merge to master
push:
tags:
- "*"
branches:
- master
paths-ignore:
- '.idea/**'
- '.gitattributes'
- '.github/**.json'
- '.gitignore'
- '.gitmodules'
- '**.md'
- 'LICENSE'
- 'NOTICE'

jobs:
check:
name: Check
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Skip duplicate actions
uses: fkirc/skip-duplicate-actions@v5
with:
cancel_others: true
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
cache: 'gradle'
- uses: gradle/actions/setup-gradle@v3
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
# - run: ./gradlew spotlessCheck
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Skip duplicate actions
uses: fkirc/skip-duplicate-actions@v5
with:
cancel_others: true
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v2
- uses: actions/setup-java@v4
with:
distribution: 'adopt'
distribution: 'zulu'
java-version: 17
- name: Cache Gradle
uses: actions/cache@v2
cache: 'gradle'
- uses: gradle/actions/setup-gradle@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-app-${{ github.sha }}
restore-keys: |
gradle-
- name: Build apk with Gradle
run: bash ./gradlew assembleRelease

- name: Build bundle with Gradle
run: bash ./gradlew bundleRelease

gradle-version: wrapper
gradle-home-cache-cleanup: true
- name: Retrieve version
run: |
echo VERSION=$(echo ${{ github.event.head_commit.id }} | head -c 10) >> $GITHUB_ENV
# Set Repository Name As Env Variable
- name: Set repository name as env variable
run: echo "repository_name=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
# Create APK Release
- name: Build apk release project (APK) - ${{ env.main_project_module }} module
run: ./gradlew -PappVerName=${{ env.VERSION }} ${{ env.main_project_module }}:assembleRelease
# Create Bundle AAB Release
# Noted for main module build [main_project_module]:bundleRelease
- name: Build app bundle release (AAB) - ${{ env.main_project_module }} module
run: ./gradlew ${{ env.main_project_module }}:bundleRelease

- name: Sign apk release
if: success()
id: sign_apk
uses: r0adkll/[email protected]
env:
BUILD_TOOLS_VERSION: "31.0.0"
BUILD_TOOLS_VERSION: "34.0.0"
with:
releaseDirectory: app/build/outputs/apk/release
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
alias: ${{ secrets.ALIAS }}
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}

- name: Sign bundle release
if: success()
id: sign_bundle
uses: r0adkll/[email protected]
env:
BUILD_TOOLS_VERSION: "31.0.0"
BUILD_TOOLS_VERSION: "34.0.0"
with:
releaseDirectory: app/build/outputs/bundle/release
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
Expand All @@ -67,4 +108,4 @@ jobs:
files: |
app/build/outputs/apk/release/*-signed.apk
app/build/outputs/bundle/release/*.aab
app/build/outputs/mapping/release/mapping.txt
app/build/outputs/mapping/release/mapping.txt
45 changes: 26 additions & 19 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
import com.android.build.gradle.internal.api.ApkVariantOutputImpl

plugins {
id(libs.plugins.android.application.get().pluginId)
id(libs.plugins.kotlin.android.get().pluginId)
id(libs.plugins.kotlin.parcelize.get().pluginId)
id(libs.plugins.ksp.get().pluginId)
id(libs.plugins.hilt.plugin.get().pluginId)
id(libs.plugins.spotless.get().pluginId)
}

/**
* read version from gradle.properties
*/
val majorVersion by properties
val minorVersion by properties
val patchVersion by properties

fun getVersionCode(): Int {
return (majorVersion as String).toInt() * 10000 + (minorVersion as String).toInt() * 100 + (patchVersion as String).toInt()
}

fun getVersionName(): String {
return "$majorVersion.$minorVersion.$patchVersion"
}

android {
Expand All @@ -15,10 +31,9 @@ android {
applicationId = "me.rosuh.easywatermark"
minSdk = (Apps.minSdk)
targetSdk = (Apps.targetSdk)
versionCode = 20900
versionName = "2.9.0"
versionCode = getVersionCode()
versionName = getVersionName()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", "$applicationId-v$versionName($versionCode)")
}

buildTypes {
Expand Down Expand Up @@ -46,14 +61,6 @@ android {
}
}

// change output apk name
applicationVariants.all {
outputs.all {
(this as? BaseVariantOutputImpl)?.outputFileName =
"$applicationId-v$versionName($versionCode).apk"
}
}

packagingOptions {
resources.excludes.add("DebugProbesKt.bin")
}
Expand All @@ -62,13 +69,6 @@ android {

namespace = "me.rosuh.easywatermark"

// lint {
// baseline = file("lint-baseline.xml")
// quiet = true
// abortOnError = false
// checkReleaseBuilds = false
// }

buildFeatures {
compose = true
}
Expand All @@ -80,6 +80,13 @@ android {
kotlin {
jvmToolchain(17)
}

applicationVariants.configureEach {
outputs.configureEach {
(this as? ApkVariantOutputImpl)?.outputFileName =
"EasyWatermark-$versionName-$versionCode.apk"
}
}
}


Expand Down
36 changes: 16 additions & 20 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.diffplug.gradle.spotless.SpotlessExtension

buildscript {
repositories {
mavenCentral()
Expand All @@ -13,27 +15,21 @@ buildscript {
}


tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}

//apply(plugin = "org.jlleitschuh.gradle.ktlint")
//
//subprojects {
// apply(plugin = "org.jlleitschuh.gradle.ktlint") // Version should be inherited from parent
//
// repositories {
// // Required to download KtLint
// mavenCentral()
// }
//
// // Optionally configure plugin
// configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
// debug.set(true)
// }
//}

plugins {
alias(libs.plugins.hilt) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.spotless) apply false
}

allprojects {
plugins.apply(rootProject.libs.plugins.spotless.get().pluginId)
extensions.configure<SpotlessExtension> {
kotlin {
target("src/**/*.kt")
ktlint(rootProject.libs.ktlint.get().version)
}
kotlinGradle {
ktlint(rootProject.libs.ktlint.get().version)
}
}
}
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object Apps {
const val compileSdk = 34
const val buildTools = "33.0.0"
const val buildTools = "34.0.0"
const val minSdk = 23
const val targetSdk = 33
const val targetSdk = 34
}
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ org.gradle.unsafe.configuration-cache=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
#org.gradle.unsafe.configuration-cache=true
#org.gradle.unsafe.configuration-cache=true

majorVersion=2
minorVersion=9
patchVersion=1
Loading

0 comments on commit e9ca85c

Please sign in to comment.