Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create workflow actions for automated releasing #86

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/gradle-publish-nightly-snapshot.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions .github/workflows/gradle-publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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 'export ORG_GRADLE_PROJECT_LIBRARY_VERSION=${{ github.event.release.tag_name }}' >> $GITHUB_ENV
source $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 assemble publish
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# here. #
############################################################

# Local Env vars
.env

############################################################
# macOS #
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
54 changes: 22 additions & 32 deletions gradle/deploy.gradle
Original file line number Diff line number Diff line change
@@ -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") {
Expand All @@ -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'
Expand Down Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
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"}