Skip to content

Commit 38e88fb

Browse files
committed
Setup CI for publishing to maven central
1 parent 152dc03 commit 38e88fb

File tree

12 files changed

+206
-100
lines changed

12 files changed

+206
-100
lines changed

.github.tar.gpg

5.2 KB
Binary file not shown.

.github/workflows/publish-release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Publish Library Release
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
8+
jobs:
9+
# Library Release Steps ##########################################################
10+
release-lib:
11+
if: startsWith(github.ref, 'refs/tags/v')
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v1
17+
- name: Set Info
18+
id: info
19+
run: |
20+
echo "::set-output name=version::$(cat .lib-version)"
21+
echo "::set-output name=ref::${GITHUB_REF##*/}"
22+
- name: Decrypt secrets
23+
run: ./bin/decrypt-secrets
24+
env:
25+
GITHUB_SECRET_PASSPHRASE: ${{ secrets.SECRETS_TAR_PASSPHRASE }}
26+
- name: Download release assets
27+
uses: RadiusNetworks/fetch-release-asset-action@v1
28+
id: downloadassets
29+
with:
30+
token: ${{ secrets.GITHUB_API_TOKEN }}
31+
- name: Publish to MavenCentral
32+
run: ./gradlew :publishReleasePublicationToSonaTypeRepository :closeAndReleaseRepository

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,10 @@ fastlane/google_play_creds.json
6969

7070
# Travis
7171
.travis.tar
72+
73+
# Maven files
74+
ossrh.properties
75+
76+
# Encrypted files
77+
.github.tar
78+
secring.gpg

.lib-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.1.1

barcode/build.gradle

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44
apply plugin: 'kotlin-kapt'
5-
apply plugin: 'com.jfrog.bintray'
6-
apply plugin: 'com.github.dcendents.android-maven'
75

86
// Build config types set by the variants
97
final String CONFIG_TYPE_BOOLEAN = 'boolean'
@@ -23,26 +21,13 @@ version = "$coreVersion"
2321

2422
ext {
2523
artifact = project.name
26-
libraryDescription = 'Barcode Module'
2724

28-
bintrayRepo = "$binTrayRepo"
29-
bintrayName = "$binTrayName"
3025
publishedGroupId = "$coreGroupId"
31-
libraryName = "$libraryName"
26+
publishArtifactId = "$artifact"
3227

28+
libraryName = "$libraryName"
29+
libraryDescription = 'Util Module'
3330
libraryVersion = "$coreVersion"
34-
35-
siteUrl = "$siteUrl"
36-
gitUrl = "$gitUrl"
37-
38-
developerId = "$developerId"
39-
developerName = "$developerName"
40-
developerEmail = "$developerEmail"
41-
42-
licenseName = "$licenseName"
43-
licenseUrl = "$licenseUrl"
44-
allLicenses = "$allLicenses"
45-
4631
}
4732

4833
android {
@@ -104,10 +89,4 @@ dependencies {
10489
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
10590
}
10691

107-
//Add these lines to publish library to bintray. This is the readymade scripts made by github user nuuneoi to make uploading to bintray easy.
108-
//Place it at the end of the file
109-
if (project.rootProject.file('local.properties').exists()) {
110-
apply from: 'https://raw.githubusercontent.com/wajahatkarim3/JCenter-Gradle-Scripts/master/install.gradle'
111-
apply from: 'https://raw.githubusercontent.com/wajahatkarim3/JCenter-Gradle-Scripts/master/bintray.gradle'
112-
}
113-
92+
apply from: rootProject.file('ossrh.gradle')

bin/decrypt-secrets

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Decrypt the file
5+
# --batch to prevent interactive command --yes to assume "yes" for questions
6+
gpg --quiet --batch --yes --decrypt --passphrase="$GITHUB_SECRET_PASSPHRASE" \
7+
--output .github.tar .github.tar.gpg
8+
tar xvf .github.tar

bin/encrypt-secrets

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Since we cannot encrypt files in secrets on github we create a tarfile
5+
# with all the secrets to be encrypted. This script is to help with creating
6+
# that encrypted archive.
7+
#
8+
# Ref: https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables
9+
#
10+
# To re-encrypt you will need all the plain text files available and in their
11+
# original location. See FILES for the full list.
12+
13+
14+
FILES=(
15+
./ossrh.properties
16+
./secring.gpg
17+
)
18+
19+
COPYFILE_DISABLE=true
20+
tar cvf .github.tar ${FILES[@]}
21+
gpg --symmetric --cipher-algo AES256 .github.tar

build.gradle

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ buildscript {
77
sdkTargetVersion = 28
88
buildTools = '29.0.3'
99

10-
coreVersion = '1.1.0'
10+
coreVersion = project.rootProject.file('.lib-version').getText('UTF-8')
1111

1212
coreGroupId = 'com.botnerd.core'
1313

14-
binTrayRepo = 'android-core'
15-
binTrayName = 'com.botnerd.core'
14+
publishGroupId = coreGroupId
15+
16+
libraryArtifact = 'android-core'
17+
libraryGroup = 'com.botnerd.core'
1618
libraryName = 'android-core'
19+
libraryDescription = 'A set of helper methods for Android apps'
1720

1821
siteUrl = 'https://github.com/botnerd/android-core'
19-
gitUrl = 'https://github.com/botnerd/android-core.git'
22+
scmConnection = 'scm:git:github.com/botnerd/android-core.git'
23+
scmDeveloperConnection = 'scm:git:github.com/botnerd/android-core.git'
24+
scmUrl = 'https://github.com/botnerd/android-core.git'
2025

2126
developerId = 'botnerd'
2227
developerName = 'Tim Judkins'
@@ -69,8 +74,10 @@ buildscript {
6974
classpath 'com.android.tools.build:gradle:4.1.0'
7075
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
7176

72-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
73-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
77+
// Maven Central publishing
78+
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.13.0'
79+
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.10.2'
80+
classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.22.0'
7481

7582
// NOTE: Do not place your application dependencies here; they belong
7683
// in the individual module build.gradle files
@@ -98,3 +105,5 @@ gradle.projectsEvaluated {
98105
subprojects {
99106
tasks.withType(Javadoc).all { enabled = false }
100107
}
108+
109+
apply plugin: 'io.codearte.nexus-staging'

network/build.gradle

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,13 @@ version = "$coreVersion"
2121

2222
ext {
2323
artifact = project.name
24-
libraryDescription = 'Network Module'
2524

26-
bintrayRepo = "$binTrayRepo"
27-
bintrayName = "$binTrayName"
2825
publishedGroupId = "$coreGroupId"
29-
libraryName = "$libraryName"
26+
publishArtifactId = "$artifact"
3027

28+
libraryName = "$libraryName"
29+
libraryDescription = 'Util Module'
3130
libraryVersion = "$coreVersion"
32-
33-
siteUrl = "$siteUrl"
34-
gitUrl = "$gitUrl"
35-
36-
developerId = "$developerId"
37-
developerName = "$developerName"
38-
developerEmail = "$developerEmail"
39-
40-
licenseName = "$licenseName"
41-
licenseUrl = "$licenseUrl"
42-
allLicenses = "$allLicenses"
43-
4431
}
4532

4633
android {
@@ -106,10 +93,4 @@ configurations.all() {
10693
resolutionStrategy.force "com.squareup.okio:okio:$okioVersion"
10794
}
10895

109-
//Add these lines to publish library to bintray. This is the readymade scripts made by github user nuuneoi to make uploading to bintray easy.
110-
//Place it at the end of the file
111-
if (project.rootProject.file('local.properties').exists()) {
112-
apply from: 'https://raw.githubusercontent.com/wajahatkarim3/JCenter-Gradle-Scripts/master/install.gradle'
113-
apply from: 'https://raw.githubusercontent.com/wajahatkarim3/JCenter-Gradle-Scripts/master/bintray.gradle'
114-
}
115-
96+
apply from: rootProject.file('ossrh.gradle')

ossrh.gradle

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
2+
File ossrhProp = project.rootProject.file('ossrh.properties')
3+
if (ossrhProp.exists()) {
4+
apply plugin: 'maven-publish'
5+
apply plugin: 'signing'
6+
7+
Properties p = new Properties()
8+
p.load(new FileInputStream(ossrhProp))
9+
p.each { name, value ->
10+
ext[name] = value
11+
}
12+
13+
task androidSourcesJar(type: Jar) {
14+
classifier = 'sources'
15+
from android.sourceSets.main.java.source
16+
}
17+
18+
artifacts {
19+
archives androidSourcesJar
20+
}
21+
22+
publishing {
23+
publications {
24+
release(MavenPublication) {
25+
// The coordinates of the library, being set from variables that
26+
// we'll set up in a moment
27+
groupId publishGroupId
28+
artifactId publishArtifactId
29+
version libraryVersion
30+
31+
// Two artifacts, the `aar` and the sources
32+
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
33+
artifact androidSourcesJar
34+
35+
// Self-explanatory metadata for the most part
36+
pom {
37+
name = publishArtifactId
38+
description = libraryDescription
39+
// If your project has a dedicated site, use its URL here
40+
url = siteUrl
41+
licenses {
42+
license {
43+
name = licenseName
44+
url = licenseUrl
45+
}
46+
}
47+
developers {
48+
developer {
49+
id = developerId
50+
name = developerName
51+
email = developerEmail
52+
}
53+
}
54+
// Version control info, if you're using GitHub, follow the format as seen here
55+
scm {
56+
connection = scmConnection
57+
developerConnection = scmDeveloperConnection
58+
url = scmUrl
59+
}
60+
// A slightly hacky fix so that your POM will include any transitive dependencies
61+
// that your library builds upon
62+
withXml {
63+
def dependenciesNode = asNode().appendNode('dependencies')
64+
65+
project.configurations.implementation.allDependencies.each {
66+
def dependencyNode = dependenciesNode.appendNode('dependency')
67+
dependencyNode.appendNode('groupId', it.group)
68+
dependencyNode.appendNode('artifactId', it.name)
69+
dependencyNode.appendNode('version', it.version)
70+
}
71+
}
72+
}
73+
}
74+
}
75+
repositories {
76+
// The repository to publish to, Sonatype/MavenCentral
77+
maven {
78+
// This is an arbitrary name, you may also use "mavencentral" or
79+
// any other name that's descriptive for you
80+
name = "sonatype"
81+
82+
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
83+
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
84+
// You only need this if you want to publish snapshots, otherwise just set the URL
85+
// to the release repo directly
86+
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
87+
88+
// The username and password we've fetched earlier
89+
credentials {
90+
username ossrhUsername
91+
password ossrhPassword
92+
}
93+
}
94+
}
95+
}
96+
signing {
97+
sign publishing.publications
98+
}
99+
100+
nexusStaging {
101+
packageGroup publishGroupId
102+
stagingProfileId stagingProfileId
103+
username ossrhUsername
104+
password ossrhPassword
105+
}
106+
}

0 commit comments

Comments
 (0)