Skip to content

Commit

Permalink
Add Sonatype publications to CI
Browse files Browse the repository at this point in the history
Add a github action to automatize the publication of the Sonatype nexus staging repository.
The action will trigger when a release or draft of a release is published, or a pre-release is changed to a release.

Note: a manual interaction is still required to release the package from the staging repository to the public one. This step is deliberately left to an admin user because is not possible to remove a packet published by mistake.

Signed-off-by: Francesco Vaiani <francesco.vaiani@secomind.com>
Signed-off-by: Antonio Gisondi <antonio.gisondi@secomind.com>
  • Loading branch information
FrancescoVaiani authored and harlem88 committed Oct 4, 2024
1 parent 294e039 commit ebd5cc0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 13 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/sonatype-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Sonatype publication with Gradle

on:
release:
types: [released]
# Run on pull requests
pull_request:

jobs:
sonatype-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
#Run JDK configuration
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8

#Gradle cache configuration
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

#Authorizing gradlew files
- name: Grant execute permission for gradlew
run: chmod +x gradlew

#Build project
- name: Build with Gradle
run: ./gradlew build

#Publish project
- name: Publish DeviceSDK
run: ./gradlew DeviceSDK:publish
env:
OSSRH_USERNAME: ${{secrets.OSSRH_USERNAME}}
OSSRH_PASSWORD: ${{secrets.OSSRH_PASSWORD}}
SONATYPE_STAGING_PROFILE_ID: ${{secrets.SONATYPE_STAGING_PROFILE_ID}}
SIGNING_KEY: ${{secrets.SIGNING_KEY}}
- name: Publish DeviceSDKAndroid -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg)
run: ./gradlew DeviceSDKAndroid:publish
env:
OSSRH_USERNAME: ${{secrets.OSSRH_USERNAME}}
OSSRH_PASSWORD: ${{secrets.OSSRH_PASSWORD}}
SONATYPE_STAGING_PROFILE_ID: ${{secrets.SONATYPE_STAGING_PROFILE_ID}}
SIGNING_KEY: ${{secrets.SIGNING_KEY}}
- name: Publish DeviceSDKGeneric
run: ./gradlew DeviceSDKGeneric:publish -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg)
env:
OSSRH_USERNAME: ${{secrets.OSSRH_USERNAME}}
OSSRH_PASSWORD: ${{secrets.OSSRH_PASSWORD}}
SONATYPE_STAGING_PROFILE_ID: ${{secrets.SONATYPE_STAGING_PROFILE_ID}}
SIGNING_KEY: ${{secrets.SIGNING_KEY}}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
java.util.logging.MemoryHandler.push=ALL
version=1.1.0
version=1.1.0-test-ci
group=org.astarte-platform
org.gradle.parallel=false
# AndroidX package structure to make it clearer which packages are bundled with the
Expand Down
17 changes: 9 additions & 8 deletions scripts/publish-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ afterEvaluate {
}
developers {
developer {
id = 'rbino'
name = 'Riccardo Binetti'
email = ' riccardo.binetti@ispirata.com'
id = 'harlem88'
name = 'Antonio Gisondi'
email = 'antonio.gisondi@secomind.com'
}
}
scm {
Expand All @@ -66,12 +66,13 @@ afterEvaluate {
}
}

ext["signing.keyId"] = rootProject.ext["signing.keyId"]
ext["signing.password"] = rootProject.ext["signing.password"]
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]
ext["signing.key"] = rootProject.ext["signing.key"]

signing {
if( !rootProject.ext["signing.secretKeyRingFile"].toString().isEmpty() ){
sign publishing.publications
}
def signingKey = rootProject.ext["signing.key"].toString()
def signingPassword = rootProject.ext["signing.password"].toString()

useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications
}
6 changes: 2 additions & 4 deletions scripts/publish-root.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = ''
ext["signing.key"] = ''

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
Expand All @@ -17,9 +16,8 @@ if (secretPropsFile.exists()) {
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.key"] = System.getenv('SIGNING_KEY')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
}

// Set up Sonatype repository
Expand Down

0 comments on commit ebd5cc0

Please sign in to comment.