diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 068c5a5..57f3e69 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,9 +26,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' @@ -38,7 +38,7 @@ jobs: - name: Zip artifacts run: zip -r assemble.zip . -i '**/build/*.apk' '**/build/*.aab' '**/build/*.aar' '**/build/*.so' - name: Upload artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v7 with: name: assemble path: assemble.zip diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..edd4828 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,31 @@ +name: Publish to Maven Central + +on: + push: + tags: + - v* + +jobs: + publish: + name: Publish release + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + + - name: Publish library to Maven Central + run: ./gradlew :library:publishAndReleaseToMavenCentral --no-configuration-cache + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.GPG_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_SIGNING_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_SIGNING_PASSWORD }} diff --git a/build.gradle.kts b/build.gradle.kts index 1a28748..6384d15 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,9 +15,4 @@ plugins { id("com.android.application") version "8.1.1" apply false id("com.android.library") version "8.1.1" apply false id("org.jetbrains.kotlin.android") version "1.7.0" apply false -} - -task("clean") { - delete(rootProject.buildDir) - delete(project.buildDir) -} +} \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 71a4c7d..f895c98 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,30 +1,42 @@ +import com.vanniktech.maven.publish.SonatypeHost + plugins { id("com.android.library") - `maven-publish` kotlin("android") + id("com.vanniktech.maven.publish") version "0.29.0" } -val artifact = "crashhandler" -group = "com.dzeio" -val projectVersion = project.findProperty("version") as String? ?: "1.1.0" -version = projectVersion - -publishing { - publications { - register("release") { - groupId = group as String? - artifactId = artifact - version = projectVersion - - afterEvaluate { - from(components["release"]) - } +// from: https://discuss.kotlinlang.org/t/use-git-hash-as-version-number-in-build-gradle-kts/19818/8 +fun String.runCommand( + workingDir: File = File("."), + timeoutAmount: Long = 60, + timeoutUnit: TimeUnit = TimeUnit.SECONDS +): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex())) + .directory(workingDir) + .redirectOutput(ProcessBuilder.Redirect.PIPE) + .redirectError(ProcessBuilder.Redirect.PIPE) + .start() + .apply { waitFor(timeoutAmount, timeoutUnit) } + .run { + val error = errorStream.bufferedReader().readText().trim() + if (error.isNotEmpty()) { + return@run "" } + inputStream.bufferedReader().readText().trim() } + +val branch = "git rev-parse --abbrev-ref HEAD".runCommand(workingDir = rootDir) +val tag = "git tag -l --points-at HEAD".runCommand(workingDir = rootDir) +val commitId = "git rev-parse HEAD".runCommand(workingDir = rootDir) + +val libGroup = "com.dzeio" +val libArtifact = "crashhandler" +val libVersion = System.getenv("version") ?: tag.drop(1).ifEmpty { + project.findProperty("VERSION_NAME") as String? ?: "1.1.0" } android { - namespace = "$group.$artifact" + namespace = "$libGroup.$libArtifact" compileSdk = 33 buildToolsVersion = "33.0.0" @@ -37,20 +49,13 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") - buildConfigField("String", "VERSION", "\"$projectVersion\"") + buildConfigField("String", "VERSION", "\"$libVersion\"") } testFixtures { enable = true } - publishing { - singleVariant("release") { - withSourcesJar() - withJavadocJar() - } - } - buildTypes { getByName("release") { isMinifyEnabled = false @@ -65,6 +70,7 @@ android { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } + kotlinOptions { jvmTarget = "11" } @@ -75,6 +81,49 @@ android { } } +mavenPublishing { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + + signAllPublications() + + coordinates(libGroup, libArtifact, libVersion) + + pom { + name.set("Crash Handler") + description.set("An Android library that helps handling and reporting crashes gracefully.") + url.set("https://github.com/dzeiocom/crashhandler") + inceptionYear.set("2022") + + licenses { + license { + name.set("MIT License") + url.set("https://github.com/dzeiocom/crashhandler/blob/master/LICENSE") + distribution.set("repo") + } + } + + developers { + developer { + id.set("avior") + name.set("Avior") + email.set("contact@dze.io") + url.set("https://github.com/Aviortheking") + } + } + + scm { + url.set("https://github.com/dzeiocom/crashhandler") + connection.set("scm:git:git://github.com/dzeiocom/crashhandler.git") + developerConnection.set("scm:git:ssh://git@github.com/dzeiocom/crashhandler.git") + } + + issueManagement { + system.set("GitHub Issues") + url.set("https://github.com/dzeiocom/crashhandler/issues") + } + } +} + dependencies { // Necessary for the Activity (well to make it pretty :D) implementation("com.google.android.material:material:1.8.0")