Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-kerem committed Dec 10, 2024
1 parent f2e1019 commit 970fdcc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .github/workflows/espresso-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Espresso (build)

on:
push:
branches:
- main
paths:
- 'visual-espresso/**'
- .github/workflows/espresso-build.yml
pull_request:
paths:
- 'visual-espresso/**'
- .github/workflows/espresso-build.yml

defaults:
run:
working-directory: visual-espresso

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

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

- name: Setup Android SDK
uses: android-actions/setup-android@v3

- name: Build SampleApplication
run: ./gradlew --no-daemon build
Empty file.
46 changes: 45 additions & 1 deletion visual-espresso/visual/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ android {
defaultConfig {
minSdk 21
versionCode 1
versionName "0.0.1"
versionName "0.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

buildConfigField "String", "SAUCE_USERNAME", "\"${getProperty("SAUCE_USERNAME", "")}\""
buildConfigField "String", "SAUCE_ACCESS_KEY", "\"${getProperty("SAUCE_ACCESS_KEY", "")}\""
buildConfigField "String", "VERSION_NAME", "\"${android.defaultConfig.versionName}\""

def releaseType = project.hasProperty("releaseType") ? project.releaseType : null
def currentVersionName = android.defaultConfig.versionName
if (releaseType) {
def newVersionName = calculateNewVersion(currentVersionName, releaseType)
println "Updating versionName from $currentVersionName to $newVersionName"
android.defaultConfig.versionName = newVersionName
persistVersionName(newVersionName)
}
}

buildTypes {
Expand Down Expand Up @@ -119,3 +128,38 @@ apollo {
warnOnDeprecatedUsages.set(false)
}
}

// Helper function to calculate the new version
static def calculateNewVersion(currentVersion, releaseType) {
def versionParts = currentVersion.split('\\.').collect { it.toInteger() }
if (versionParts.size() != 3) {
throw new GradleException("Invalid versionName format: $currentVersion. Expected format: MAJOR.MINOR.PATCH")
}

def (major, minor, patch) = versionParts
switch (releaseType) {
case "major":
major++
minor = 0
patch = 0
break
case "minor":
minor++
patch = 0
break
case "patch":
patch++
break
default:
throw new GradleException("Unknown release type: $releaseType. Use 'major', 'minor', or 'patch'.")
}

return "$major.$minor.$patch"
}

// Helper function to persist the updated versionName back to build.gradle
def persistVersionName(newVersionName) {
def buildFile = file("build.gradle")
def buildFileContent = buildFile.text.replaceAll(/versionName\s+"[^"]+"/, "versionName \"$newVersionName\"")
buildFile.text = buildFileContent
}

0 comments on commit 970fdcc

Please sign in to comment.