-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary | ||
import com.vanniktech.maven.publish.SonatypeHost | ||
|
||
plugins { | ||
alias libs.plugins.android.library | ||
alias libs.plugins.apollographql | ||
id 'maven-publish' | ||
id 'signing' | ||
alias libs.plugins.vanniktech.maven.publish | ||
} | ||
|
||
android { | ||
|
@@ -12,7 +14,7 @@ android { | |
defaultConfig { | ||
minSdk 21 | ||
versionCode 1 | ||
versionName rootProject.version | ||
versionName "0.0.1" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
|
||
|
@@ -27,16 +29,12 @@ android { | |
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_11 | ||
targetCompatibility JavaVersion.VERSION_11 | ||
} | ||
publishing { | ||
singleVariant("release") { | ||
withSourcesJar() | ||
withJavadocJar() | ||
} | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = true | ||
} | ||
|
@@ -73,44 +71,36 @@ ext { | |
artifactName = 'visual-espresso' | ||
} | ||
|
||
publishing { | ||
publications { | ||
release(MavenPublication) { | ||
groupId = android.namespace | ||
artifactId = "${artifactName}" | ||
version = android.defaultConfig.versionName | ||
afterEvaluate { | ||
from components.release | ||
mavenPublishing { | ||
configure(new AndroidSingleVariantLibrary("release", true, true)) | ||
publishToMavenCentral(SonatypeHost.DEFAULT) | ||
signAllPublications() | ||
coordinates(android.namespace, "${artifactName}", android.defaultConfig.versionName) | ||
|
||
pom { | ||
name = "${artifactName}" | ||
description = 'Sauce Visual Espresso SDK' | ||
url = 'https://github.com/saucelabs/visual-sdks' | ||
scm { | ||
connection = "scm:git:${scmUrl}" | ||
developerConnection = "scm:git:${scmUrl}" | ||
url = "${scmUrl}" | ||
} | ||
licenses { | ||
license { | ||
name = 'Apache-2.0' | ||
url = 'https://github.com/saucelabs/visual-sdks/blob/main/LICENSE' | ||
} | ||
pom { | ||
name = "${artifactName}" | ||
description = 'Sauce Visual Espresso SDK' | ||
url = 'https://github.com/saucelabs/visual-sdks' | ||
scm { | ||
connection = "scm:git:${scmUrl}" | ||
developerConnection = "scm:git:${scmUrl}" | ||
url = "${scmUrl}" | ||
} | ||
licenses { | ||
license { | ||
name = 'Apache-2.0' | ||
url = 'https://github.com/saucelabs/visual-sdks/blob/main/LICENSE' | ||
} | ||
} | ||
developers { | ||
developer { | ||
name = 'Sauce Labs Visual Team' | ||
email = '[email protected]' | ||
organization = 'Sauce Labs' | ||
organizationUrl = 'https://saucelabs.com/' | ||
} | ||
} | ||
} | ||
developers { | ||
developer { | ||
name = 'Sauce Labs Visual Team' | ||
email = '[email protected]' | ||
organization = 'Sauce Labs' | ||
organizationUrl = 'https://saucelabs.com/' | ||
} | ||
} | ||
} | ||
repositories { | ||
mavenLocal() | ||
} | ||
} | ||
|
||
apollo { | ||
|
@@ -121,10 +111,49 @@ apollo { | |
} | ||
} | ||
|
||
signing { | ||
useInMemoryPgpKeys( | ||
project.findProperty("signingKey") ?: System.getenv("GPG_PRIVATE_KEY"), | ||
project.findProperty("signingPassword") ?: System.getenv("GPG_PASSPHRASE") | ||
) | ||
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 newVersion = calculateNewVersion(android.defaultConfig.versionName, releaseType) | ||
persistNewVersion(newVersion) | ||
|
||
print "$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(/versionName\s+"[^"]+"/, "versionName \"$newVersion\"") | ||
buildFile.text = buildFileContent | ||
} |