Skip to content

Commit

Permalink
try fix espresso release
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-kerem committed Dec 10, 2024
1 parent b30eccc commit c0f2525
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 63 deletions.
63 changes: 62 additions & 1 deletion visual-espresso/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,65 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.gradle.nexus.publish)
}
}

nexusPublishing {
repositories {
sonatype {
nexusUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
snapshotRepositoryUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
username = project.findProperty("ossrhUsername") ?: System.getenv("OSSRH_USERNAME")
password = project.findProperty("ossrhPassword") ?: System.getenv("OSSRH_PASSWORD")
}
}
}

group = "com.saucelabs.visual"
version = "0.0.0"

tasks.register('bumpVersion') {
doLast {
def releaseType = project.hasProperty("releaseType") ? project.releaseType : null
if (!releaseType) {
throw new GradleException("Please provide a release type using -PreleaseType=<major|minor|patch>")
}

def newVersion = calculateNewVersion(version, releaseType)
persistNewVersion(newVersion)

println "$newVersion"
}
}

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"
}

def persistNewVersion(newVersion) {
def buildFile = file("build.gradle")
def buildFileContent = buildFile.text.replaceAll(/version\s*=\s*["'].*?["']/, "version = \"$newVersion\"")
buildFile.text = buildFileContent
}
64 changes: 2 additions & 62 deletions visual-espresso/visual/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
plugins {
alias libs.plugins.android.library
alias libs.plugins.apollographql
alias libs.plugins.gradle.nexus.publish
id 'maven-publish'
id 'signing'
}

android {
namespace 'com.saucelabs.visual'
namespace rootProject.group
compileSdk 34

defaultConfig {
minSdk 21
versionCode 1
versionName "0.0.0"
versionName rootProject.version
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

Expand Down Expand Up @@ -114,17 +113,6 @@ publishing {
}
}

nexusPublishing {
repositories {
sonatype {
nexusUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
snapshotRepositoryUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
username = project.findProperty("ossrhUsername") ?: System.getenv("OSSRH_USERNAME")
password = project.findProperty("ossrhPassword") ?: System.getenv("OSSRH_PASSWORD")
}
}
}

apollo {
service("service") {
packageName.set("com.saucelabs.visual.graphql")
Expand All @@ -140,51 +128,3 @@ signing {
)
sign publishing.publications
}

tasks.register('bumpVersion') {
doLast {
def releaseType = project.hasProperty("releaseType") ? project.releaseType : null
if (!releaseType) {
throw new GradleException("Please provide a release type using -PreleaseType=<major|minor|patch>")
}

def currentVersionName = android.defaultConfig.versionName
def newVersionName = calculateNewVersion(currentVersionName, releaseType)
persistVersionName(newVersionName)

println "$newVersionName"
}
}

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"
}

def persistVersionName(newVersionName) {
def buildFile = file("build.gradle")
def buildFileContent = buildFile.text.replaceAll(/versionName\s+"[^"]+"/, "versionName \"$newVersionName\"")
buildFile.text = buildFileContent
}

0 comments on commit c0f2525

Please sign in to comment.