diff --git a/.github/workflows/gradle-publish-nightly-snapshot.yml b/.github/workflows/gradle-publish-nightly-snapshot.yml new file mode 100644 index 0000000..cec4f59 --- /dev/null +++ b/.github/workflows/gradle-publish-nightly-snapshot.yml @@ -0,0 +1,48 @@ +#name: Publish nightly snapshots +# +#on: +# push +# +##on: +## # schedule: +## # - cron: "5 0 * * TUE-SAT" +## push: +## branches: +## - 'zm/cicd-pipeline' +# +#jobs: +# build-and-publish-snapshot: +# runs-on: ubuntu-latest +# permissions: +# contents: read +# steps: +# - uses: actions/checkout@v4 +# with: +# fetch-depth: 0 +# - name: Set up JDK 18 +# uses: actions/setup-java@v4 +# with: +# java-version: '18' +# distribution: 'temurin' +# # server-id: github # Value of the distributionManagement/repository/id field of the pom.xml +# # settings-path: ${{ github.workspace }} # location for the settings.xml file +# - name: Define library version env var at run-time - SNAPSHOT +# run: | +# echo "ORG_GRADLE_PROJECT_LIBRARY_VERSION=`git tag | tail -1`-SNAPSHOT" >> $GITHUB_ENV +# +# # This step is needed because Gradle doesn't like to see GPG keys from env vars (for reasons unbeknownst to me) +## - name: Inject Gradle signing key from GHA secret +## run: | +## echo $GPG_SIGNING_KEY \ +## | awk 'NR == 1 { print "SIGNING_KEY=" } 1' ORS='\\n' \ +## >> gradle.properties +# +# - name: Publish snapshots to Maven Central +# env: +# ORG_GRADLE_PROJECT_MAVEN_CENTRAL_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_MAVEN_CENTRAL_USERNAME }} +# ORG_GRADLE_PROJECT_MAVEN_CENTRAL_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_MAVEN_CENTRAL_PASSWORD }} +# ORG_GRADLE_PROJECT_GPG_SIGNING_IN_MEMORY_KEY: ${{ secrets.ORG_GRADLE_PROJECT_GPG_SIGNING_IN_MEMORY_KEY }} +# ORG_GRADLE_PROJECT_GPG_SIGNING_IN_MEMORY_KEY_PWD: ${{ secrets.ORG_GRADLE_PROJECT_GPG_SIGNING_IN_MEMORY_KEY_PWD }} +# +# run: | +# ./gradlew publish diff --git a/.github/workflows/gradle-publish-release.yml b/.github/workflows/gradle-publish-release.yml new file mode 100644 index 0000000..b91d8bc --- /dev/null +++ b/.github/workflows/gradle-publish-release.yml @@ -0,0 +1,43 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle + +name: Publish Release + +on: + release: + types: [ released ] + + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + + - uses: actions/checkout@v4 + with: + fetch-tags: true + - name: Set up JDK 18 + uses: actions/setup-java@v4 + with: + java-version: '18' + distribution: 'temurin' + + - name: Define library version env var at run-time - RELEASE + run: | + echo 'ORG_GRADLE_PROJECT_LIBRARY_VERSION=${{ github.event.release.tag_name }}' >> $GITHUB_ENV + + - name: Publish to Maven Central + env: + ORG_GRADLE_PROJECT_MAVEN_CENTRAL_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_MAVEN_CENTRAL_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_GPG_SIGNING_IN_MEMORY_KEY: ${{ secrets.ORG_GRADLE_PROJECT_GPG_SIGNING_IN_MEMORY_KEY }} + ORG_GRADLE_PROJECT_GPG_SIGNING_IN_MEMORY_KEY_PWD: ${{ secrets.ORG_GRADLE_PROJECT_GPG_SIGNING_IN_MEMORY_KEY_PWD }} + run: | + ./gradlew publish diff --git a/.gitignore b/.gitignore index 427f6ec..a264945 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ # here. # ############################################################ +# Local Env vars +.env ############################################################ # macOS # diff --git a/build.gradle b/build.gradle index 5663298..6c8d221 100644 --- a/build.gradle +++ b/build.gradle @@ -3,3 +3,5 @@ plugins { alias libs.plugins.com.android.library apply false alias libs.plugins.org.jetbrains.kotlin.android apply false } + +version = findProperty("LIBRARY_VERSION") diff --git a/gradle/deploy.gradle b/gradle/deploy.gradle index ab6d03c..37b1729 100644 --- a/gradle/deploy.gradle +++ b/gradle/deploy.gradle @@ -1,31 +1,23 @@ apply plugin: 'maven-publish' apply plugin: 'signing' -def getValueFromPropertiesFile = { propFile, key -> - if (!propFile.isFile() || !propFile.canRead()) - return null - def prop = new Properties() - def reader = propFile.newReader() - try { - prop.load(reader) - } finally { - reader.close() +def signingKeyBase64 = findProperty("GPG_SIGNING_IN_MEMORY_KEY") +def signingPassword = findProperty("GPG_SIGNING_IN_MEMORY_KEY_PWD") + +def base64Decode(encodedString){ + if(encodedString != null) { + byte[] decoded = encodedString.decodeBase64() + String decode = new String(decoded) + return decode } - return prop.get(key) + return null; } -def getProperty = { name, defValue -> - def prop = project.properties[name] ?: - getValueFromPropertiesFile(project.rootProject.file('local.properties'), name) - return (null == prop) ? defValue : prop +signing { + useInMemoryPgpKeys(base64Decode(signingKeyBase64), signingPassword) + sign publishing.publications } -ext['signing.keyId'] = getProperty('signing.keyId', null) -ext['signing.password'] = getProperty('signing.password', null) -ext['signing.secretKeyRingFile'] = getProperty('signing.secretKeyRingFile', null) -ext.ossrhUsername = getProperty('ossrhUsername', null) -ext.ossrhPassword = getProperty('ossrhPassword', null) - android { publishing { singleVariant("release") { @@ -37,12 +29,13 @@ android { afterEvaluate { publishing { + publications { release(MavenPublication) { from components.release - groupId libraryGroupId artifactId libraryArtifactId - version libraryVersion + groupId = 'live.ditto' + version = findProperty("LIBRARY_VERSION") pom { name = 'Ditto Tools' @@ -73,25 +66,22 @@ afterEvaluate { } } } - repositories { maven { - name = "sonatype" - url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" - credentials { - username ossrhUsername - password ossrhPassword + username = findProperty("MAVEN_CENTRAL_USERNAME") + password = findProperty("MAVEN_CENTRAL_PASSWORD") } + + def releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") + def snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") + + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl } } } } -signing { - sign publishing.publications -} - tasks.withType(GenerateModuleMetadata) { enabled = false } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5dcb770..610cf29 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -24,6 +24,8 @@ core-ktx = "1.9.0" espresso-core = "3.5.1" material = "1.11.0" +gradle-nexus-publish-plugin = "2.0.0" + [libraries] androidx-activity-activityCompose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidx-activity" } androidx-appcompat-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" } @@ -53,4 +55,5 @@ material = { group = "com.google.android.material", name = "material", version.r [plugins] com-android-application = { id = "com.android.application", version.ref = "android-gradle-plugin" } com-android-library = { id = "com.android.library", version.ref = "android-gradle-plugin" } -org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin-gradle-plugin" } \ No newline at end of file +org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin-gradle-plugin" } +io-github-gradle-nexus-publish-plugin = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "gradle-nexus-publish-plugin"} \ No newline at end of file