Skip to content

Commit

Permalink
Set up publishing for Maven Central (#56)
Browse files Browse the repository at this point in the history
Initial work to publish to Maven Central
  • Loading branch information
drewhannay authored Feb 16, 2021
1 parent 7a5a8c4 commit 7755478
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 229 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/deploy-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy snapshot
on:
push:
branches:
- master
jobs:
publish:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'Prepare for release') }}
steps:
- uses: actions/checkout@v2

- name: Cache Gradle Files
uses: actions/cache@v2
with:
path: |
~/.gradle/caches/
~/.gradle/wrapper/
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Build
run: ./gradlew build

- name: Publish package
run: ./gradlew publishAllPublicationsToSonatypeSnapshotRepository
env:
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
27 changes: 27 additions & 0 deletions .github/workflows/publish-maven-central.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish package to the Maven Central Repository
on:
release:
types: [published]
branches:
- master
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Build
run: ./gradlew build

- name: Publish package
run: ./gradlew publishAllPublicationsToMavenCentralRepository
env:
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SHAKY_ANDROID_GPG_PRIVATE_KEY: ${{ secrets.SHAKY_ANDROID_GPG_PRIVATE_KEY }}
SHAKY_ANDROID_GPG_PRIVATE_KEY_PASSWORD: ${{ secrets.SHAKY_ANDROID_GPG_PRIVATE_KEY_PASSWORD }}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,19 @@ to collect extra app data including device logs, user data, etc. You will also n

If you want to programmatically trigger the feedback collection flow, rather than listening for shake events, you can call `Shaky#startFeedbackFlow()` on the
object returned by `Shaky.with()`. See the demo app for a full example of how to do this.

## Snapshots

You can use snapshot builds to test the latest unreleased changes. A new snapshot is published
after every merge to the main branch by the [Deploy Snapshot Github Action workflow](.github/workflows/deploy-snapshot.yml).

Just add the Sonatype snapshot repository to your Gradle scripts:
```gradle
repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
```

You can find the latest snapshot version to use in the [gradle.properties](gradle.properties) file.
37 changes: 20 additions & 17 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
Releasing
========
# Releasing

1. Change the version in `gradle.properties` to a non-SNAPSHOT version.
2. Update the `CHANGELOG.md` for the impending release.
3. Update the `README.md` with the new version.
4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version)
5. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version)
6. `./gradlew clean distributeBuild`
7. Update the `gradle.properties` to the next SNAPSHOT version.
8. `git commit -am "Prepare next development version."`
9. `git push && git push --tags`
1. Change the version in `gradle.properties` to a non-SNAPSHOT version.
2. Update the `CHANGELOG.md` for the impending release.
3. Update the `README.md` with the new version.
4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version)
5. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version)
6. Update the `gradle.properties` to the next SNAPSHOT version.
7. `git commit -am "Prepare next development version."`
8. `git push && git push --tags`
9. Create a new release in the releases tab on GitHub
10. Wait for the [publish-maven-central.yml](.github/workflows/publish-maven-central.yml) action to complete.
11. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact.

## How it works

Prerequisites
-------------
The [deploy-snapshot.yml](.github/workflows/deploy-snapshot.yml) workflow runs on every
push to the main branch as long as the commit message does not contain `Prepare for release`. This
workflow calls Gradle to publish to the Sonatype snapshot repository.

Set the following environment variables:

* `ARTIFACTORY_USER` - LinkedIn artifactory username for releasing to `com.linkedin.shaky`.
* `ARTIFACTORY_KEY` - LinkedIn artifactory API key for releasing to `com.linkedin.shaky`.
For actual releases, there is a separate [publish-maven-central.yml](.github/workflows/publish-maven-central.yml)
workflow which runs after a new release is created in the GitHub UI. This will call Gradle on the
tagged release commit and upload to the staging repository. After that completes, you will need to
go and promote the artifacts to production.
33 changes: 5 additions & 28 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import com.linkedin.gradle.DistributeTask

buildscript {
repositories {
google()
mavenCentral()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.8.1"
classpath 'com.android.tools.build:gradle:4.1.2'
}
}

Expand All @@ -19,10 +15,12 @@ subprojects {

repositories {
google()
mavenCentral()
jcenter()
}

tasks.withType(Javadoc).all { enabled = false }
group = GROUP_ID
version = VERSION_NAME
}

ext {
Expand All @@ -31,24 +29,3 @@ ext {
minSdkVersion = 21
targetSdkVersion = 27
}

apply plugin: 'com.jfrog.artifactory'

artifactory {
contextUrl = 'https://linkedin.jfrog.io/linkedin'
publish {
repoKey = 'shaky-android'
username = System.getenv('ARTIFACTORY_USER') ?: ''
password = System.getenv('ARTIFACTORY_KEY') ?: ''

defaults {
publications ('aar')
publishArtifacts = true
}
}
clientConfig.setIncludeEnvVars(false)
}

task distributeBuild(type: DistributeTask) {
dependsOn ':artifactoryPublish', 'shaky:artifactoryPublish'
}
39 changes: 0 additions & 39 deletions buildSrc/build.gradle

This file was deleted.

39 changes: 0 additions & 39 deletions buildSrc/src/main/groovy/com/linkedin/gradle/DistributeTask.groovy

This file was deleted.

24 changes: 20 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true

GROUP_ID=com.linkedin.shaky
ARTIFACT=shaky
VERSION_NAME=3.0.2-SNAPSHOT
LIBRARY_NAME=Shaky
LIBRARY_DESCRIPTION=Shake-to-send-feedback library for Android
android.useAndroidX=true
91 changes: 91 additions & 0 deletions gradle/publishing.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

// Ideally AGP should provide sources and javadoc integration for their components:
// https://issuetracker.google.com/issues/145670440
tasks.register("sourcesJar", Jar) {
classifier 'sources'
from android.sourceSets.main.java.srcDirs
}

tasks.register("javadoc", Javadoc) {
failOnError false
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

tasks.register("javadocJar", Jar) {
dependsOn javadoc
classifier 'javadoc'
from javadoc.destinationDir
}

// AGP creates the components in afterEvaluate, so we need to use it too
// https://developer.android.com/studio/build/maven-publish-plugin
afterEvaluate {
publishing {
publications {
maven(MavenPublication) {
from components.release

artifact sourcesJar
artifact javadocJar

pom {
name = 'Shaky'
description = 'Shake-to-send-feedback library for Android'
url = 'https://github.com/linkedin/shaky-android'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'com.linkedin'
name = 'LinkedIn Corp'
}
}
scm {
connection = 'scm:git:git://github.com/linkedin/shaky-android.git'
developerConnection = 'scm:git:ssh://github.com:linkedin/shaky-android.git'
url = 'https://github.com/linkedin/shaky-android/tree/master'
}
}

repositories {
def sonatypeUsername = System.getenv("SONATYPE_USER")
def sonatypePassword = System.getenv("SONATYPE_PASSWORD")
maven {
name = "sonatypeSnapshot"
url = "https://oss.sonatype.org/content/repositories/snapshots"
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
maven {
name = "mavenCentral"
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}
}
}
}

// SHAKY_ANDROID_GPG_PRIVATE_KEY should contain the armoured private key that
// starts with -----BEGIN PGP PRIVATE KEY BLOCK-----
// It can be obtained with gpg --armour --export-secret-keys KEY_ID
def signingKey = System.getenv("SHAKY_ANDROID_GPG_PRIVATE_KEY")
def signingPassword = System.getenv("SHAKY_ANDROID_GPG_PRIVATE_KEY_PASSWORD")
signing {
required { signingKey != null && signingPassword != null }
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.maven
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sat Nov 10 11:59:22 PST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
Loading

0 comments on commit 7755478

Please sign in to comment.