diff --git a/.github/workflows/sonatype.yml b/.github/workflows/sonatype.yml new file mode 100644 index 0000000..e07684b --- /dev/null +++ b/.github/workflows/sonatype.yml @@ -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 diff --git a/strada/build.gradle b/strada/build.gradle index 7a00894..ed3a443 100644 --- a/strada/build.gradle +++ b/strada/build.gradle @@ -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 { @@ -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= 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 @@ -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') + } } } }