Skip to content

Commit d626537

Browse files
authored
Merge pull request #31 from hotwired/sonatype-publish
Add Sonatype publishing scripts
2 parents d69ee0c + 0b94a8a commit d626537

File tree

2 files changed

+97
-9
lines changed

2 files changed

+97
-9
lines changed

.github/workflows/sonatype.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish to Sonatype
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
jobs:
8+
publish-release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Setup Java
12+
uses: actions/setup-java@v3
13+
with:
14+
distribution: 'temurin'
15+
java-version: '17'
16+
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: Publish artifact to Sonatype
21+
env:
22+
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
23+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
24+
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
25+
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
26+
GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
27+
run: ./gradlew -Psonatype -Pversion=${{ github.event.release.tag_name }} clean build -x test publish

strada/build.gradle

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@ apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlinx-serialization'
44
apply plugin: 'maven-publish'
5+
apply plugin: 'signing'
56

67
ext {
78
libVersionName = version
8-
libraryName = 'Strada for Android'
9-
libraryDescription = 'Android framework for making better hybrid apps'
9+
libraryName = 'Strada Android'
10+
libraryDescription = 'Create fully native Android controls, driven by your web app'
1011

1112
publishedGroupId = 'dev.hotwire'
1213
publishedArtifactId = 'strada'
1314

1415
siteUrl = 'https://github.com/hotwired/strada-android'
1516
gitUrl = 'https://github.com/hotwired/strada-android.git'
17+
18+
licenseType = 'MIT License'
19+
licenseUrl = 'https://github.com/hotwired/strada-android/blob/main/LICENSE'
20+
21+
developerId = 'basecamp'
22+
developerEmail = '[email protected]'
23+
24+
isSonatypeRelease = project.hasProperty('sonatype')
1625
}
1726

1827
buildscript {
@@ -98,12 +107,53 @@ task androidSourcesJar(type: Jar) {
98107
from android.sourceSets.main.java.srcDirs
99108
}
100109

110+
// Only sign Sonatype release artifacts
111+
tasks.withType(Sign) {
112+
onlyIf { isSonatypeRelease }
113+
}
114+
115+
// Sign Sonatype published release artifacts
116+
if (isSonatypeRelease) {
117+
signing {
118+
def keyId = System.getenv('GPG_KEY_ID')
119+
def secretKey = System.getenv("GPG_SECRET_KEY")
120+
def password = System.getenv("GPG_PASSWORD")
121+
122+
useInMemoryPgpKeys(keyId, secretKey, password)
123+
124+
required { gradle.taskGraph.hasTask("publish") }
125+
sign publishing.publications
126+
}
127+
}
128+
101129
// Publish to GitHub Packages via ./gradlew -Pversion=<version> clean build publish
102130
// https://github.com/orgs/hotwired/packages?repo_name=strada-android
103131
afterEvaluate {
104132
publishing {
105133
publications {
106134
release(MavenPublication) {
135+
pom {
136+
name = libraryName
137+
description = libraryDescription
138+
url = siteUrl
139+
licenses {
140+
license {
141+
name = licenseType
142+
url = licenseUrl
143+
}
144+
}
145+
developers {
146+
developer {
147+
id = developerId
148+
name = developerId
149+
email = developerEmail
150+
}
151+
}
152+
scm {
153+
url = gitUrl
154+
}
155+
}
156+
107157
// Applies the component for the release build variant
108158
from components.release
109159

@@ -117,13 +167,24 @@ afterEvaluate {
117167
}
118168
}
119169
repositories {
120-
maven {
121-
name = 'GitHubPackages'
122-
url = uri('https://maven.pkg.github.com/hotwired/strada-android')
123-
124-
credentials {
125-
username = System.getenv('GITHUB_ACTOR')
126-
password = System.getenv('GITHUB_TOKEN')
170+
if (isSonatypeRelease) {
171+
maven {
172+
url = uri('https://s01.oss.sonatype.org/content/repositories/releases/')
173+
174+
credentials {
175+
username = System.getenv('SONATYPE_USER')
176+
password = System.getenv('SONATYPE_PASSWORD')
177+
}
178+
}
179+
} else {
180+
maven {
181+
name = 'GitHubPackages'
182+
url = uri('https://maven.pkg.github.com/hotwired/strada-android')
183+
184+
credentials {
185+
username = System.getenv('GITHUB_ACTOR')
186+
password = System.getenv('GITHUB_TOKEN')
187+
}
127188
}
128189
}
129190
}

0 commit comments

Comments
 (0)