Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Espresso GH actions #175

Merged
merged 10 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/espresso-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Espresso (build)

on:
push:
branches:
- main
paths:
- 'visual-espresso/**'
- .github/workflows/espresso-build.yml
pull_request:
paths:
- 'visual-espresso/**'
- .github/workflows/espresso-build.yml

defaults:
run:
working-directory: visual-espresso

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Android SDK
uses: android-actions/setup-android@v3

- name: Build
run: ./gradlew --no-daemon build
79 changes: 79 additions & 0 deletions .github/workflows/espresso-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Espresso (Release)

on:
workflow_dispatch:
inputs:
releaseType:
description: 'Release type - major, minor or patch'
required: true
default: 'minor'
options:
- 'major'
- 'minor'
- 'patch'

defaults:
run:
working-directory: visual-espresso

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
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 == '' }}
run: |
git config --global user.name "sauce-visual-bot"
git config --global user.email "visual@saucelabs.com"

- name: Set up Android SDK
uses: android-actions/setup-android@v3

- name: Bump version
id: upgrade
run: |
./gradlew -q bumpVersion -PreleaseType=${{ github.event.inputs.releaseType }}
echo "version=$new_version" >> "$GITHUB_OUTPUT"

- name: Publish to Sonatype OSSRH (staging)
run: ./gradlew publish
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 }}

- name: Push new version to Git
id: push_to_git
run: |
tag_name="espresso-${{ steps.upgrade.outputs.version }}"
git add ./visual/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: 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/target/visual-release.aar
generate_release_notes: true
1 change: 1 addition & 0 deletions visual-espresso/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.gradle.nexus.publish)
}
2 changes: 2 additions & 0 deletions visual-espresso/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ espressoCore = "3.6.1"
appcompat = "1.7.0"
material = "1.12.0"
uiautomator = "2.2.0"
gradleNexusPublish = "2.0.0"

[libraries]
jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoup" }
Expand All @@ -24,3 +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"}
70 changes: 69 additions & 1 deletion visual-espresso/visual/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
alias libs.plugins.android.library
alias libs.plugins.apollographql
id 'maven-publish'
id 'signing'
}

android {
Expand All @@ -11,7 +12,7 @@ android {
defaultConfig {
minSdk 21
versionCode 1
versionName "0.0.1"
versionName "0.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

Expand Down Expand Up @@ -112,10 +113,77 @@ 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")
generateKotlinModels.set(false)
warnOnDeprecatedUsages.set(false)
}
}

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