From efecdc69155946ec1c6ae61fa813fc0b033e7143 Mon Sep 17 00:00:00 2001 From: Kerem Date: Tue, 10 Dec 2024 23:44:26 +0100 Subject: [PATCH] try different plugin --- .github/workflows/espresso-release.yml | 51 ++++----- visual-espresso/build.gradle | 62 ----------- visual-espresso/gradle/libs.versions.toml | 4 +- visual-espresso/visual/build.gradle | 127 +++++++++++++--------- 4 files changed, 104 insertions(+), 140 deletions(-) diff --git a/.github/workflows/espresso-release.yml b/.github/workflows/espresso-release.yml index 3825cd6e..e957870c 100644 --- a/.github/workflows/espresso-release.yml +++ b/.github/workflows/espresso-release.yml @@ -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 diff --git a/visual-espresso/build.gradle b/visual-espresso/build.gradle index 7864f66f..9693c98c 100644 --- a/visual-espresso/build.gradle +++ b/visual-espresso/build.gradle @@ -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=") - } - - 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 } diff --git a/visual-espresso/gradle/libs.versions.toml b/visual-espresso/gradle/libs.versions.toml index 8cdf1cc3..8429461d 100644 --- a/visual-espresso/gradle/libs.versions.toml +++ b/visual-espresso/gradle/libs.versions.toml @@ -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" } @@ -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"} diff --git a/visual-espresso/visual/build.gradle b/visual-espresso/visual/build.gradle index f9acb50e..898b1d34 100644 --- a/visual-espresso/visual/build.gradle +++ b/visual-espresso/visual/build.gradle @@ -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 = 'visual.team@saucelabs.com' - organization = 'Sauce Labs' - organizationUrl = 'https://saucelabs.com/' - } - } + } + developers { + developer { + name = 'Sauce Labs Visual Team' + email = 'visual.team@saucelabs.com' + 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=") + } + + 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 +} \ No newline at end of file