Skip to content

Commit

Permalink
VIDEO-4165: Deploy to MavenCentral (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
paynerc authored Feb 24, 2021
1 parent 745aed4 commit 302bbc8
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 63 deletions.
9 changes: 8 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ aliases:
command: >
echo $GCP_KEY | base64 -d | gcloud auth activate-service-account --key-file=-
- &signing-key
name: Install signing key
command: >
echo $SIGNING_KEY | base64 -d >> $SIGNING_SECRET_KEY_RING_FILE
- &release-filter
filters:
tags:
Expand Down Expand Up @@ -126,6 +131,7 @@ jobs:
- attach_workspace:
at: *workspace
- restore_cache: *restore_cache-gradle
- run: *signing-key
- run:
name: Publish AudioSwitch pre release
command: ./gradlew -q jfrogOssSnapshotsAudioSwitchUpload
Expand All @@ -139,9 +145,10 @@ jobs:
- attach_workspace:
at: *workspace
- restore_cache: *restore_cache-gradle
- run: *signing-key
- run:
name: Publish AudioSwitch release
command: ./gradlew -q bintrayAudioSwitchReleaseUpload
command: ./gradlew -q sonatypeAudioSwitchReleaseUpload
- save_cache: *save_cache-gradle

bump-version:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Enhancements

- Updated the library to use Android Gradle Plugin 4.1.1

- Now published to MavenCentral

### 1.1.1

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Thank you to all our contributors!
* [John Qualls](https://github.com/Alton09)
* [Aaron Alaniz](https://github.com/aaalaniz)
* [Tejas Nandanikar](https://github.com/tejas-n)
* [Ryan C. Payne](https://github.com/paynerc)
68 changes: 42 additions & 26 deletions audioswitch/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: "com.jfrog.artifactory"
apply plugin: 'kotlin-android'
apply plugin: "org.jetbrains.dokka"
Expand Down Expand Up @@ -76,8 +77,7 @@ def audioSwitchGroupId = 'com.twilio'
def audioSwitchArtifactId = 'audioswitch'

/*
* The publishing and artifactory blocks enable publishing AudioSwitch as snapshot to
* JFrog OSS.
* The publishing block enables publishing to both Artifactory and MavenCentral
*/
publishing {
publications {
Expand All @@ -92,15 +92,51 @@ publishing {
artifactId = audioSwitchArtifactId
version = audioSwitchVersion

pom.withXml {
def root = asNode()
root.appendNode('name', 'Audioswitch')
root.appendNode('url', 'https://github.com/twilio/audioswitch')
pom {
name = 'Audioswitch'
description = 'An Android audio management library for real-time communication apps.'
url = 'https://github.com/twilio/audioswitch'
licenses {
license {
name = 'Apache 2.0'
url = 'https://github.com/twilio/audioswitch/blob/master/LICENSE.txt'
}
}
developers {
developer {
id = 'Twilio'
name = 'Twilio'
}
}
scm {
connection = 'scm:git:github.com/twilio/audioswitch.git'
developerConnection = 'scm:git:ssh://github.com/twilio/audioswitch.git'
url = 'https://github.com/twilio/audioswitch/tree/main'
}
// A slightly hacky fix so that your POM will include any transitive dependencies
// that your library builds upon
withXml {
def dependenciesNode = asNode().appendNode('dependencies')

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

signing {
sign publishing.publications
}

/*
* The artifactory block enables publishing AudioSwitch as a snapshot to JFrog OSS.
*/
artifactory {
contextUrl = 'https://oss.jfrog.org'
publish {
Expand All @@ -117,23 +153,3 @@ artifactory {
}
clientConfig.info.setBuildNumber(getShortCommitSha())
}

/*
* The uploadArchives block is used to publish to Bintray
*/
uploadArchives {
repositories {
mavenDeployer {
repository(url: "${mavenRepo}") {
authentication(
userName: mavenUsername,
password: mavenPassword
)
}
pom.version = audioSwitchVersion
pom.groupId = audioSwitchGroupId
pom.artifactId = audioSwitchArtifactId
pom.packaging = 'aar'
}
}
}
77 changes: 42 additions & 35 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ buildscript {
ext.dokka_version = '1.4.10'

/**
* Properties and environment variables needed to publish to Bintray.
* Properties and environment variables needed to publish.
*/
ext.mavenRepo = (project.hasProperty('maven.repo') ?
project.property("maven.repo") : '')
ext.mavenUsername = (project.hasProperty('maven.username') ?
project.property("maven.username") : '')
ext.mavenPassword = (project.hasProperty('maven.password') ?
project.property("maven.password") : '')
ext.jfrogUsername = (project.hasProperty('jfrog.username') ?
project.property("jfrog.username") : '')
ext.jfrogPassword = (project.hasProperty('jfrog.password') ?
project.property("jfrog.password") : '')
ext["signing.keyId"] = (project.hasProperty('signing.keyId') ?
project.property("signing.keyId") : '')
ext["signing.password"] = (project.hasProperty('signing.password') ?
project.property("signing.password") : '')
ext["signing.secretKeyRingFile"] = (project.hasProperty('signing.secretKeyRingFile') ?
project.property("signing.secretKeyRingFile") : '')
ext["ossrhUsername"] = (project.hasProperty('ossrhUsername') ?
project.property("ossrhUsername") : '')
ext["ossrhPassword"] = (project.hasProperty('ossrhPassword') ?
project.property("ossrhPassword") : '')
ext["sonatypeStagingProfileId"] = (project.hasProperty('sonatypeStagingProfileId') ?
project.property("sonatypeStagingProfileId") : '')

ext.getPropertyValue = { propertyKey ->
def property = System.getenv(propertyKey)
Expand All @@ -36,26 +42,6 @@ buildscript {
return property
}

ext.getAudioSwitchJfrogOssPassword = {
def audioSwitchJfrogOssPassword = System.getenv("AUDIOSWITCH_JFROG_OSS_PASSWORD");

if (audioSwitchJfrogOssPassword == null) {
logger.log(LogLevel.INFO, "Could not locate AUDIOSWITCH_JFROG_OSS_PASSWORD environment variable. " +
"Trying local.properties")
Properties properties = new Properties()
if (project.rootProject.file('local.properties').exists()) {
properties.load(project.rootProject.file('local.properties').newDataInputStream())
audioSwitchJfrogOssPassword = properties.getProperty('AUDIOSWITCH_JFROG_OSS_PASSWORD')
}
}

if (audioSwitchJfrogOssPassword == null) {
logger.log(LogLevel.WARN, "AudioSwitch Jfrog OSS password unavailable.")
}

return audioSwitchJfrogOssPassword;
}

ext.getShortCommitSha = {
def gitSha = System.getenv("CIRCLE_SHA1")

Expand All @@ -82,7 +68,9 @@ buildscript {
plugins {
id "com.diffplug.spotless" version "5.6.1"
id "com.jfrog.artifactory" version "4.15.2"
id "org.jetbrains.dokka" version "1.4.10"
id "org.jetbrains.dokka" version "$dokka_version"
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
id "maven-publish"
}
apply plugin: "com.diffplug.spotless"
spotless {
Expand Down Expand Up @@ -111,6 +99,19 @@ allprojects {
}
}

nexusPublishing {
repositories {
sonatype {
username = ossrhUsername
password = ossrhPassword
stagingProfileId = sonatypeStagingProfileId
}
}

clientTimeout = Duration.ofSeconds(300)
connectTimeout = Duration.ofSeconds(60)
}

/*
* Utility GradleBuild task that enables defining custom tasks derived from gradle modules in a
* root level gradle file.
Expand Down Expand Up @@ -226,20 +227,26 @@ task jfrogOssSnapshotsAudioSwitchUpload(type: RootGradleBuild) {
startParameter.projectProperties += gradle.startParameter.projectProperties + [
'preRelease': true,
'jfrog.username': "${getPropertyValue("AUDIOSWITCH_JFROG_OSS_USERNAME")}",
'jfrog.password': "${getPropertyValue("AUDIOSWITCH_JFROG_OSS_PASSWORD")}"
'jfrog.password': "${getPropertyValue("AUDIOSWITCH_JFROG_OSS_PASSWORD")}",
'signing.keyId': "${getPropertyValue("SIGNING_KEY_ID")}",
'signing.password' : "${getPropertyValue("SIGNING_PASSWORD")}",
'signing.secretKeyRingFile' : "${getPropertyValue("SIGNING_SECRET_KEY_RING_FILE")}"
]
}

task bintrayAudioSwitchReleaseUpload(type: RootGradleBuild) {
task sonatypeAudioSwitchReleaseUpload(type: RootGradleBuild) {
description = 'Publish an AudioSwitch release'
group = 'Publishing'
dependsOn validateReleaseTag
buildFile = file('audioswitch/build.gradle')
tasks = ['assembleRelease', 'uploadArchives']
buildFile = file('build.gradle')
tasks = ['assembleRelease', 'publishAudioSwitchReleasePublicationToSonatypeRepository', 'closeAndReleaseSonatypeStagingRepository']
startParameter.projectProperties += gradle.startParameter.projectProperties + [
'maven.repo': 'https://api.bintray.com/maven/twilio/releases/audioswitch/;publish=1',
'maven.username': "${getPropertyValue("AUDIOSWITCH_BINTRAY_USERNAME")}",
'maven.password': "${getPropertyValue("AUDIOSWITCH_BINTRAY_PASSWORD")}"
'signing.keyId': "${getPropertyValue("SIGNING_KEY_ID")}",
'signing.password' : "${getPropertyValue("SIGNING_PASSWORD")}",
'signing.secretKeyRingFile' : "${getPropertyValue("SIGNING_SECRET_KEY_RING_FILE")}",
'ossrhUsername' : "${getPropertyValue("OSSRH_USERNAME")}",
'ossrhPassword' : "${getPropertyValue("OSSRH_PASSWORD")}",
'sonatypeStagingProfileId' : "${getPropertyValue("SONATYPE_STAGING_PROFILE_ID")}"
]
}

Expand Down

0 comments on commit 302bbc8

Please sign in to comment.