Skip to content

Commit

Permalink
Setup new publishing scripts for MavenCentral (#323)
Browse files Browse the repository at this point in the history
* Setup new publishing scripts for MavenCentral

* removed unneeded code
  • Loading branch information
ferranpons authored Oct 22, 2021
1 parent f753d23 commit 3638a48
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 82 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish

on:
release:
# We'll run this workflow when a new GitHub release is created
types: [released]

jobs:
publish:
name: Release build and publish
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

# Base64 decodes and pipes the GPG key content into the secret file
- name: Prepare environment
env:
GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }}
SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}
run: |
git fetch --unshallow
sudo bash -c "echo '$GPG_KEY_CONTENTS' | base64 -d > '$SIGNING_SECRET_KEY_RING_FILE'"
# Builds the release artifacts of the library
- name: Release build
run: ./gradlew assembleRelease -x :sample:assembleRelease

# Generates other artifacts (javadocJar is optional)
- name: Source jar
run: ./gradlew androidSourcesJar javadocJar

# Runs upload, and then closes & releases the repository
- name: Publish to MavenCentral
run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.0.3'

// Remove comment when the library is on mavenCentral
//classpath 'com.ferranpons:twitter-gradle-plugin:1.1.0'

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.github.gradle-nexus:publish-plugin:1.1.0"
classpath("io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.22.0")
}
}

Expand All @@ -32,3 +34,6 @@ allprojects {
mavenCentral()
}
}

apply plugin: 'io.github.gradle-nexus.publish-plugin'
apply from: "${rootDir}/scripts/publish-root.gradle"
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
org.gradle.jvmargs=-Xmx2048m
org.gradle.configureondemand=false
android.useAndroidX=true
libGroup=com.adevinta.android
libVersion=8.1.0
80 changes: 2 additions & 78 deletions leku/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ apply plugin: 'maven-publish'
apply plugin: "org.jlleitschuh.gradle.ktlint"
apply plugin: "io.gitlab.arturbosch.detekt"

def versionMajor = getVersionMajor()
def versionMinor = getVersionMinor()
def versionPatch = getVersionPatch()
ext["PUBLISH_ARTIFACT_ID"] = "leku"

group = 'com.schibstedspain.android'
version = "${versionMajor}.${versionMinor}.${versionPatch}"
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

android {
compileSdkVersion 29
Expand Down Expand Up @@ -114,76 +111,3 @@ dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}

publishing {
publications {
Production(MavenPublication) {
groupId 'com.schibstedspain.android'
artifactId 'leku'
version "${versionMajor}.${versionMinor}.${versionPatch}"

pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

configurations.implementation.allDependencies.each {
if (it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}

// List all "compile" dependencies (for old Gradle)
configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
// List all "api" dependencies (for new Gradle) as "compile" dependencies
configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
// List all "implementation" dependencies (for new Gradle) as "runtime" dependencies
configurations.implementation.getAllDependencies().each { dep ->
try {
addDependency(dep, "runtime")
} catch(Exception ignored) {
}
}
}

artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
artifact androidSourcesJar
}
}
}

def getVersionMajor() {
def content = file('../version.properties')

Properties properties = new Properties()
InputStream is = new ByteArrayInputStream(content.getBytes())
properties.load(is)

return properties['MAJOR'].toInteger()
}

def getVersionMinor() {
def content = file('../version.properties')

Properties properties = new Properties()
InputStream is = new ByteArrayInputStream(content.getBytes())
properties.load(is)

return properties['MINOR'].toInteger()
}

def getVersionPatch() {
def content = file('../version.properties')

Properties properties = new Properties()
InputStream is = new ByteArrayInputStream(content.getBytes())
properties.load(is)

return properties['PATCH'].toInteger()
}
82 changes: 82 additions & 0 deletions scripts/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
} else {
from sourceSets.main.java.srcDirs
from sourceSets.main.kotlin.srcDirs
}
}

task javadocJar(type: Jar) {
archiveClassifier.set('javadoc')
}

artifacts {
archives androidSourcesJar
archives javadocJar
}

group = project.property("libGroup")
version = project.property("libVersion")

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId project.property("libGroup")
artifactId PUBLISH_ARTIFACT_ID
version project.property("libVersion")

if (project.plugins.findPlugin("com.android.library")) {
from components.release
} else {
artifact("$buildDir/libs/${project.getName()}-${version}.jar")
}

artifact androidSourcesJar
artifact javadocJar

pom {
name = project.project.getName()
description = 'Map location picker component for Android. Based on Google Maps. An alternative to Google Place Picker.'
url = 'https://github.com/AdevintaSpain/Leku'
licenses {
license {
name = 'Stream License'
url = 'https://github.com/AdevintaSpain/Leku/blob/master/LICENSE.md'
}
}
developers {
developer {
id = 'AdevintaSpain'
name = 'Adevinta Spain'
email = 'engineers@adevinta.com'
}
}
organization {
name = "Adevinta Spain"
url = "https://github.com/AdevintaSpain"
}
scm {
connection = 'scm:git:github.com/AdevintaSpain/Leku.git'
developerConnection = 'scm:git:ssh://github.com/AdevintaSpain/Leku.git'
url = 'https://github.com/AdevintaSpain/Leku/tree/master'
}
}
}
}
}
}

ext["signing.keyId"] = rootProject.ext["signing.keyId"]
ext["signing.password"] = rootProject.ext["signing.password"]
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]

signing {
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"] = '0C762F0D'
ext["signing.password"] = 'dsLCfZhaoHbgqgNeRHuAY'
ext["signing.secretKeyRingFile"] = '../secret.gpg'

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('GPG_KEY_NAME')
ext["signing.password"] = System.getenv('GPG_PASSPHRASE')
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
}

// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
3 changes: 0 additions & 3 deletions version.properties

This file was deleted.

0 comments on commit 3638a48

Please sign in to comment.