Skip to content

Commit

Permalink
try different plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-kerem committed Dec 10, 2024
1 parent 7b01da7 commit efecdc6
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 140 deletions.
51 changes: 24 additions & 27 deletions .github/workflows/espresso-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,30 @@ jobs:
new_version=$(./gradlew -q bumpVersion -PreleaseType=patch)
echo "version=$new_version" >> "$GITHUB_OUTPUT"
#- name: Publish artifact
# run: ./gradlew publishToSonatype closeSonatypeStagingRepository
# env:
# OSSRH_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME }}
# OSSRH_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }}
# GPG_PRIVATE_KEY: ${{ secrets.MVN_CENTRAL_GPG_PRIVATE_KEY }}
# GPG_PASSPHRASE: ${{ secrets.MVN_CENTRAL_GPG_PASSPHRASE }}
- name: Publish artifact
run: ./gradlew publishToMavenCentral --no-configuration-cache
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MVN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MVN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MVN_CENTRAL_GPG_PRIVATE_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MVN_CENTRAL_GPG_PASSPHRASE }}

- name: Push new version to Git
id: push_to_git
run: |
tag_name="espresso-${{ steps.upgrade.outputs.version }}"
git add ./build.gradle
git commit -m "[release] $tag_name"
git tag $tag_name
git push
git push origin $tag_name
echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT"
#- name: Push new version to Git
# id: push_to_git
# run: |
# tag_name="espresso-${{ steps.upgrade.outputs.version }}"
# git add ./build.gradle
# git commit -m "[release] $tag_name"
# git tag $tag_name
# git push
# git push origin $tag_name

- name: Build
run: ./gradlew --no-daemon build
# echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT"

- name: Github Release
uses: softprops/action-gh-release@v2
with:
fail_on_unmatched_files: true
tag_name: ${{ steps.push_to_git.outputs.tag_name }}
files: visual-espresso/visual/build/outputs/aar/visual-release.aar
generate_release_notes: true
#- name: Github Release
# uses: softprops/action-gh-release@v2
# with:
# fail_on_unmatched_files: true
# tag_name: ${{ steps.push_to_git.outputs.tag_name }}
# files: visual-espresso/visual/build/outputs/aar/visual-release.aar
# generate_release_notes: true
62 changes: 0 additions & 62 deletions visual-espresso/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,4 @@
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.visual-espresso"
version = "0.0.1"

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)

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(/version\s*=\s*["'].*?["']/, "version = \"$newVersion\"")
buildFile.text = buildFileContent
}
4 changes: 2 additions & 2 deletions visual-espresso/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ espressoCore = "3.6.1"
appcompat = "1.7.0"
material = "1.12.0"
uiautomator = "2.2.0"
gradleNexusPublish = "2.0.0"
vanniktechMavenPublish = "0.30.0"

[libraries]
jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoup" }
Expand All @@ -25,4 +25,4 @@ apollo-rx3-support = { group = "com.apollographql.apollo3", name = "apollo-rx3-s
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
apollographql = { id = "com.apollographql.apollo3", version.ref = "apolloGraphQL" }
gradle-nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "gradleNexusPublish"}
vanniktech-maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktechMavenPublish"}
127 changes: 78 additions & 49 deletions visual-espresso/visual/build.gradle
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 {
Expand All @@ -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"

Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

0 comments on commit efecdc6

Please sign in to comment.