Skip to content

Commit

Permalink
[Spike] : Add Sonatype Publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
radityagumay committed Apr 27, 2022
1 parent 0dc17e9 commit 9b10ebf
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 41 deletions.
33 changes: 28 additions & 5 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,39 @@ on:
branches: [ main ]

jobs:
unit-test:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run Unit Test
run: ./gradlew :clickstream:testDebugUnitTest
- name: Run Static Analysis
run: ./gradlew :clickstream:check

build:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
- name: Run Unit Test
run: ./gradlew :clickstream:testDebugUnitTest
- name: Run Static Analysis
run: ./gradlew :clickstream:check
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew :clickstream:assembleRelease
- name: Archive aar
uses: actions/upload-artifact@v2
with:
name: clickstream
path: clickstream/build/outputs/aar/**.aar
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- '[0-9]+.[0-9]+.[0-9]+' # Push events to any matching semantic tag. For example, 1.10.1 or 2.0.0.
# For more details, see https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
# and https://docs.npmjs.com/about-semantic-versioning

jobs:
publish:
name: Release build and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
cache: gradle
- name: Release build
run: ./gradlew :clickstream:assembleRelease
- name: Publish to MavenCentral
run: ./gradlew :clickstream:publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
12 changes: 9 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ apply(plugin = "binary-compatibility-validator")

buildscript {
repositories {
google()
maven { setUrl("https://maven-central-asia.storage-download.googleapis.com/repos/central/data") }
maven(url = "https://plugins.gradle.org/m2/")
maven(url = "https://maven-central-asia.storage-download.googleapis.com/repos/central/data")
mavenCentral()
google()
jcenter()
}

dependencies {
Expand All @@ -16,6 +18,7 @@ buildscript {
classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.12")
classpath("org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4")
classpath("com.google.dagger:hilt-android-gradle-plugin:2.40.5")
classpath("io.github.gradle-nexus:publish-plugin:1.1.0")
}
}

Expand All @@ -28,4 +31,7 @@ val clean by tasks.creating(Delete::class) {
delete("${rootDir}/buildSrc/build")
delete("${rootDir}/clickstream/build")
delete("${rootDir}/report")
}
}

apply(plugin = "io.github.gradle-nexus.publish-plugin")
apply(from = "${rootDir}/scripts/publish-root.gradle")
2 changes: 1 addition & 1 deletion clickstream/api/clickstream.api
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ public final class clickstream/model/CSUserInfo {
public fun toString ()Ljava/lang/String;
}

public final class com/gojek/android/clickstream/BuildConfig {
public final class com/gojek/clickstream/BuildConfig {
public static final field BUILD_TYPE Ljava/lang/String;
public static final field DEBUG Z
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String;
Expand Down
17 changes: 9 additions & 8 deletions clickstream/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import plugin.AndroidLibraryConfigurationPlugin

apply<AndroidLibraryConfigurationPlugin>()
apply("$rootDir/gradle/script-git-version.gradle")

ext {
set("name", "clickstream")
set("publish", true)
set("version", ext.get("gitVersionName"))
}

plugins {
id("com.android.library")
Expand Down Expand Up @@ -55,4 +48,12 @@ dependencies {

// Android Test
deps.androidTest.list.forEach(::androidTestImplementation)
}
}

ext {
set("PUBLISH_GROUP_ID", "com.gojek.clickstream")
set("PUBLISH_VERSION", "0.0.1")
set("PUBLISH_ARTIFACT_ID", "clickstream")
}

apply(from = "$rootDir/scripts/publish-module.gradle")
2 changes: 1 addition & 1 deletion clickstream/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gojek.android.clickstream">
package="com.gojek.clickstream">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
23 changes: 0 additions & 23 deletions gradle/script-git-version.gradle

This file was deleted.

77 changes: 77 additions & 0 deletions scripts/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
// For Android libraries
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
} else {
// For pure Kotlin libraries, in case you have them
from sourceSets.main.java.srcDirs
from sourceSets.main.kotlin.srcDirs
}
}

artifacts {
archives androidSourcesJar
}

group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

// Two artifacts, the `aar` (or `jar`) and the sources
if (project.plugins.findPlugin("com.android.library")) {
from components.release
} else {
from components.java
}

artifact androidSourcesJar
//artifact javadocJar

pom {
name = PUBLISH_ARTIFACT_ID
description = 'Clickstream'
url = 'https://github.com/gojek/clickstream-android'
licenses {
license {
name = 'Clickstream License'
url = 'https://github.com/gojek/clickstream-android/blob/main/LICENSE'
}
}
developers {
developer {
id = 'radityagumay'
name = 'Raditya Gumay'
email = 'raditya.g@gojek.com'
}
}
scm {
connection = 'scm:git:github.com/gojek/clickstream-android.git'
developerConnection = 'scm:git:ssh://github.com/gojek/clickstream-android.git'
url = 'https://github.com/gojek/clickstream-android/tree/main'
}
}
}
}
}
}

signing {
useInMemoryPgpKeys(
rootProject.ext["signing.keyId"],
rootProject.ext["signing.key"],
rootProject.ext["signing.password"],
)
sign publishing.publications
}
36 changes: 36 additions & 0 deletions scripts/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Create variables with empty default values
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.key"] = ''

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// Use system environment variables
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.key"] = System.getenv('SIGNING_KEY')
}

// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
}
}
}

0 comments on commit 9b10ebf

Please sign in to comment.