Skip to content

Commit

Permalink
Merge pull request #31 from hotwired/sonatype-publish
Browse files Browse the repository at this point in the history
Add Sonatype publishing scripts
  • Loading branch information
jayohms authored Sep 19, 2023
2 parents d69ee0c + 0b94a8a commit d626537
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 9 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/sonatype.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish to Sonatype

on:
release:
types: [released]

jobs:
publish-release:
runs-on: ubuntu-latest
steps:
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Checkout code
uses: actions/checkout@v2

- name: Publish artifact to Sonatype
env:
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
run: ./gradlew -Psonatype -Pversion=${{ github.event.release.tag_name }} clean build -x test publish
79 changes: 70 additions & 9 deletions strada/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'
apply plugin: 'maven-publish'
apply plugin: 'signing'

ext {
libVersionName = version
libraryName = 'Strada for Android'
libraryDescription = 'Android framework for making better hybrid apps'
libraryName = 'Strada Android'
libraryDescription = 'Create fully native Android controls, driven by your web app'

publishedGroupId = 'dev.hotwire'
publishedArtifactId = 'strada'

siteUrl = 'https://github.com/hotwired/strada-android'
gitUrl = 'https://github.com/hotwired/strada-android.git'

licenseType = 'MIT License'
licenseUrl = 'https://github.com/hotwired/strada-android/blob/main/LICENSE'

developerId = 'basecamp'
developerEmail = 'androidteam@basecamp.com'

isSonatypeRelease = project.hasProperty('sonatype')
}

buildscript {
Expand Down Expand Up @@ -98,12 +107,53 @@ task androidSourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
}

// Only sign Sonatype release artifacts
tasks.withType(Sign) {
onlyIf { isSonatypeRelease }
}

// Sign Sonatype published release artifacts
if (isSonatypeRelease) {
signing {
def keyId = System.getenv('GPG_KEY_ID')
def secretKey = System.getenv("GPG_SECRET_KEY")
def password = System.getenv("GPG_PASSWORD")

useInMemoryPgpKeys(keyId, secretKey, password)

required { gradle.taskGraph.hasTask("publish") }
sign publishing.publications
}
}

// Publish to GitHub Packages via ./gradlew -Pversion=<version> clean build publish
// https://github.com/orgs/hotwired/packages?repo_name=strada-android
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
pom {
name = libraryName
description = libraryDescription
url = siteUrl
licenses {
license {
name = licenseType
url = licenseUrl
}
}
developers {
developer {
id = developerId
name = developerId
email = developerEmail
}
}
scm {
url = gitUrl
}
}

// Applies the component for the release build variant
from components.release

Expand All @@ -117,13 +167,24 @@ afterEvaluate {
}
}
repositories {
maven {
name = 'GitHubPackages'
url = uri('https://maven.pkg.github.com/hotwired/strada-android')

credentials {
username = System.getenv('GITHUB_ACTOR')
password = System.getenv('GITHUB_TOKEN')
if (isSonatypeRelease) {
maven {
url = uri('https://s01.oss.sonatype.org/content/repositories/releases/')

credentials {
username = System.getenv('SONATYPE_USER')
password = System.getenv('SONATYPE_PASSWORD')
}
}
} else {
maven {
name = 'GitHubPackages'
url = uri('https://maven.pkg.github.com/hotwired/strada-android')

credentials {
username = System.getenv('GITHUB_ACTOR')
password = System.getenv('GITHUB_TOKEN')
}
}
}
}
Expand Down

0 comments on commit d626537

Please sign in to comment.