Skip to content

Commit

Permalink
Publish artifacts to Maven Central (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
wborn authored Dec 18, 2024
1 parent 9deb556 commit 893daf8
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 48 deletions.
17 changes: 17 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
changelog:
categories:
- title: 🎉 New features
labels:
- Feature
- title: ⭐ Enhancements
labels:
- Enhancement
- title: 🐞 Bug fixes
labels:
- Bug
- title: 📝 Documentation
labels:
- Documentation
- title: Other changes
labels:
- "*"
52 changes: 43 additions & 9 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
name: CI/CD

on:
# Push on main excluding tags
# Push on main and release tags
push:
branches:
- 'main'
tags-ignore:
- '*.*'
tags:
- '[0-9]+.[0-9]+.[0-9]+'

# PR
pull_request:
branches:
- 'main'

# Manual trigger
workflow_dispatch:

jobs:

Expand All @@ -32,15 +40,41 @@ jobs:
java-version: '17'
cache: 'gradle'

- name: Run build
- name: Check if main repo
id: is_main_repo
run: |
if [ $GITHUB_REPOSITORY == 'openremote/console-android' ]; then
echo "value=true" >> $GITHUB_OUTPUT
fi
- name: Run assemble
if: ${{ !steps.is_main_repo.outputs.value || github.event_name == 'pull_request' }}
run: |
gradle assemble
- name: Run assemble and publish
if: ${{ steps.is_main_repo.outputs.value && github.event_name != 'pull_request' }}
run: |
cd GenericApp
gradle build
echo "$KEYSTORE_BASE64" | base64 -d > keystore
gradle assemble publishToSonatype closeAndReleaseSonatypeStagingRepository \
-PsigningKey=$MAVEN_SIGNING_KEY -PsigningPassword=$MAVEN_SIGNING_PASSWORD -PpublishUsername=$MAVEN_USERNAME -PpublishPassword=$MAVEN_PASSWORD \
-PkeystoreKeyAlias=$KEYSTORE_KEY_ALIAS -PkeystoreKeyPassword=$KEYSTORE_KEY_PASSWORD -PkeystoreFile=$PWD/keystore -PkeystorePassword=$KEYSTORE_PASSWORD
env:
MAVEN_SIGNING_KEY: ${{ secrets._TEMP_MAVEN_SIGNING_KEY || secrets.MAVEN_SIGNING_KEY }}
MAVEN_SIGNING_PASSWORD: ${{ secrets._TEMP_MAVEN_SIGNING_PASSWORD || secrets.MAVEN_SIGNING_PASSWORD }}
MAVEN_USERNAME: ${{ secrets._TEMP_MAVEN_USERNAME || secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets._TEMP_MAVEN_PASSWORD || secrets.MAVEN_PASSWORD }}
KEYSTORE_BASE64: |
${{ secrets.ANDROID_KEYSTORE_BASE64 }}
KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
KEYSTORE_KEY_ALIAS: ${{ secrets.ANDROID_KEYSTORE_KEY_ALIAS }}
KEYSTORE_KEY_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_KEY_PASSWORD }}

- name: Upload APKs
- name: Upload build outputs
if: success()
uses: actions/upload-artifact@v4
with:
name: apks
name: build-outputs
path: |
**/*.apk
**/build/outputs/**/*.aar
**/build/outputs/**/*.apk
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release

on:
# Manual trigger
workflow_dispatch:
inputs:
VERSION_INCREMENT:
description: 'The version number part to increment (major.minor.patch)'
default: Minor
type: choice
options:
- Major
- Minor
- Patch
required: false
VERSION_OVERRIDE:
description: 'Version override (when not incrementing the previous version)'
type: string
required: false


permissions:
actions: write
contents: write

jobs:

build:
name: Release
runs-on: ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 17 and gradle cache
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'

- name: Run release
id: release
run: |
if [ -n "$VERSION_OVERRIDE" ]; then
gradle release -Prelease.forceVersion=${VERSION_OVERRIDE}
else
gradle release -Prelease.versionIncrementer=increment${VERSION_INCREMENT}
fi
env:
VERSION_INCREMENT: ${{ github.event.inputs.VERSION_INCREMENT }}
VERSION_OVERRIDE: ${{ github.event.inputs.VERSION_OVERRIDE }}

# When the 'github.token' is used events are not generated to prevent users from accidentally creating recursive workflow runs.
# See: https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
- name: Create release
run: |
git push --follow-tags
gh workflow run ci_cd.yml --ref $RELEASED_VERSION
gh release create $RELEASED_VERSION --generate-notes
env:
GH_TOKEN: ${{ github.token }}
RELEASED_VERSION: ${{ steps.release.outputs.released-version }}
1 change: 0 additions & 1 deletion GenericApp/.buildignore

This file was deleted.

1 change: 0 additions & 1 deletion GenericApp/app/.buildignore

This file was deleted.

102 changes: 98 additions & 4 deletions GenericApp/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
id 'maven-publish'
id 'signing'
}

android {
defaultConfig {
Expand All @@ -9,18 +13,31 @@ android {
compileSdk 35
targetSdkVersion 35
versionCode 44
versionName "1.1.2"
versionName version

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

resValue "string", "NOTIFICATION_CHANNEL_ID", applicationId + ".ORAppMessage"
}

if (project.hasProperty("keystoreFile")) {
signingConfigs {
release {
keyAlias keystoreKeyAlias
keyPassword keystoreKeyPassword
storeFile file(keystoreFile)
storePassword keystorePassword
}
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
if (project.hasProperty("keystoreFile")) {
signingConfig signingConfigs.release
}
}
}

Expand All @@ -36,7 +53,13 @@ android {
kotlinOptions {
jvmTarget = '17'
}

namespace 'io.openremote.app'

publishing {
singleVariant('release') {
}
}
}

dependencies {
Expand All @@ -52,3 +75,74 @@ dependencies {
implementation 'com.google.android.material:material:1.12.0'
implementation project(':ORLib')
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier = 'sources'
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release

artifact source: file('build/outputs/apk/release/app-release.apk')
artifact sourcesJar

group = "io.openremote"
artifactId = "app"

pom {
name = 'OpenRemote Android Console'
description = 'Provides the Android OpenRemote Console Application'
url = 'https://github.com/openremote/console-android'
licenses {
license {
name = 'GNU Affero General Public License v3.0'
url = 'https://www.gnu.org/licenses/agpl-3.0.en.html'
}
}
developers {
developer {
id = 'developers'
name = 'Developers'
email = 'developers@openremote.io'
organization = 'OpenRemote'
organizationUrl = 'https://openremote.io'
}
}
scm {
connection = 'scm:git:git://github.com/openremote/console-android.git'
developerConnection = 'scm:git:ssh://github.com:openremote/console-android.git'
url = 'https://github.com/openremote/console-android/tree/main'
}
}
}
}

repositories {
maven {
if (!version.endsWith('-LOCAL')) {
credentials {
username findProperty("publishUsername")
password findProperty("publishPassword")
}
}
url = version.endsWith('-LOCAL') ? layout.buildDirectory.dir('repo') : version.endsWith('-SNAPSHOT') ? findProperty("snapshotsRepoUrl") : findProperty("releasesRepoUrl")
}
}
}

signing {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
if (signingKey && signingPassword) {
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications
signReleasePublication.dependsOn(packageRelease)
}
}

publishReleasePublicationToMavenLocal.dependsOn(packageRelease)
}
26 changes: 0 additions & 26 deletions GenericApp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +0,0 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "2.0.20"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.7.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
4 changes: 0 additions & 4 deletions GenericApp/settings.gradle

This file was deleted.

1 change: 0 additions & 1 deletion ORLib/.buildignore

This file was deleted.

Loading

0 comments on commit 893daf8

Please sign in to comment.