From bc9e06186260fe09230e42e37fbf51b69810f055 Mon Sep 17 00:00:00 2001 From: Kerem Date: Thu, 12 Dec 2024 14:07:52 +0100 Subject: [PATCH] Fix espresso release (#177) Co-authored-by: sauce-visual-bot --- .github/workflows/espresso-release.yml | 24 ++--- README.md | 1 + visual-espresso/README.md | 34 +++++++ visual-espresso/build.gradle | 3 +- visual-espresso/gradle/libs.versions.toml | 4 +- visual-espresso/visual/build.gradle | 106 ++++++++-------------- 6 files changed, 85 insertions(+), 87 deletions(-) create mode 100644 visual-espresso/README.md diff --git a/.github/workflows/espresso-release.yml b/.github/workflows/espresso-release.yml index d871d82f..94801cc5 100644 --- a/.github/workflows/espresso-release.yml +++ b/.github/workflows/espresso-release.yml @@ -6,7 +6,7 @@ on: releaseType: description: 'Release type - major, minor or patch' required: true - default: 'minor' + default: 'patch' options: - 'major' - 'minor' @@ -28,8 +28,6 @@ jobs: java-version: '17' distribution: 'temurin' server-id: ossrh - gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} - gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} - name: Set up Git if: ${{ steps.prep.outputs.tag_name == '' }} @@ -43,20 +41,16 @@ jobs: - name: Bump version id: upgrade run: | - ./gradlew -q bumpVersion -PreleaseType=${{ github.event.inputs.releaseType }} + new_version=$(./gradlew -q bumpVersion -PreleaseType=${{ github.event.inputs.releaseType }}) echo "version=$new_version" >> "$GITHUB_OUTPUT" - - name: Publish to Sonatype OSSRH (staging) - run: ./gradlew publish + - name: Build, publish and release artifact + run: ./gradlew build publishAndReleaseToMavenCentral --no-configuration-cache env: - OSSRH_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME }} - OSSRH_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }} - - - name: Close and release the repository - run: ./gradlew nexusStagingRelease - env: - OSSRH_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME }} - OSSRH_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }} + 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 @@ -75,5 +69,5 @@ jobs: with: fail_on_unmatched_files: true tag_name: ${{ steps.push_to_git.outputs.tag_name }} - files: visual-espresso/target/visual-release.aar + files: visual-espresso/visual/build/outputs/aar/visual-release.aar generate_release_notes: true diff --git a/README.md b/README.md index bd3ed379..b614d85a 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,4 @@ This repository contains the SDKs for Sauce Labs Visual. - [Java](./visual-java) - [JavaScript/TypeScript](./visual-js) - [Python](./visual-python) +- [Espresso](./visual-espresso/) diff --git a/visual-espresso/README.md b/visual-espresso/README.md new file mode 100644 index 00000000..2560bb73 --- /dev/null +++ b/visual-espresso/README.md @@ -0,0 +1,34 @@ +# Sauce Labs Visual for Espresso + +Sauce Labs Visual for Espresso exposes Sauce Labs Visual Testing for your Android apps. + +## Installation & Usage + +View installation and usage instructions on the [Sauce Docs website](https://docs.saucelabs.com/visual-testing/integrations/espresso/). + +## Building + +Sauce Visual Java SDK uses [Gradle](https://gradle.org/). + +`gradlew` binary, that is included in the source, can be used as a replacement if you don't have Maven. + +You'll also need [Android command line tools](https://developer.android.com/tools/). + +It can be setup either using [Android Studio](https://developer.android.com/studio) or using [homebrew](https://formulae.brew.sh/cask/android-commandlinetools). + +```sh +./gradlew build +``` + +## Running the tests + +To run the smoke test you'll need a running Android Emulator. + +You can either start an emulator from Android Studio or using [command line](https://developer.android.com/studio/run/emulator-commandline). + +Then you can run the smoke test using the following command. Make sure that SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables +are in place before running the test. + +```sh +./gradlew connectedAndroidTest +``` diff --git a/visual-espresso/build.gradle b/visual-espresso/build.gradle index 3d9a05c7..9693c98c 100644 --- a/visual-espresso/build.gradle +++ b/visual-espresso/build.gradle @@ -2,5 +2,4 @@ plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.android.library) apply false - alias(libs.plugins.gradle.nexus.publish) -} \ No newline at end of file +} 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 2c1ff0a6..7650d7d1 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 "0.0.0" + 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,53 +71,34 @@ ext { artifactName = 'visual-espresso' } -publishing { - publications { - release(MavenPublication) { - groupId = android.namespace - artifactId = "${artifactName}" - version = android.defaultConfig.versionName - afterEvaluate { - from components.release - } - 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/' - } - } +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' } } - } - repositories { - mavenLocal() - } -} - -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") + developers { + developer { + name = 'Sauce Labs Visual Team' + email = 'visual.team@saucelabs.com' + organization = 'Sauce Labs' + organizationUrl = 'https://saucelabs.com/' + } } } } @@ -132,14 +111,6 @@ 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 @@ -147,11 +118,10 @@ tasks.register('bumpVersion') { throw new GradleException("Please provide a release type using -PreleaseType=") } - def currentVersionName = android.defaultConfig.versionName - def newVersionName = calculateNewVersion(currentVersionName, releaseType) - persistVersionName(newVersionName) + def newVersion = calculateNewVersion(android.defaultConfig.versionName, releaseType) + persistNewVersion(newVersion) - println "$newVersionName" + print "$newVersion" } } @@ -182,8 +152,8 @@ static def calculateNewVersion(currentVersion, releaseType) { return "$major.$minor.$patch" } -def persistVersionName(newVersionName) { +def persistNewVersion(newVersion) { def buildFile = file("build.gradle") - def buildFileContent = buildFile.text.replaceAll(/versionName\s+"[^"]+"/, "versionName \"$newVersionName\"") + def buildFileContent = buildFile.text.replaceAll(/versionName\s+"[^"]+"/, "versionName \"$newVersion\"") buildFile.text = buildFileContent }