Skip to content

Commit 00898b9

Browse files
committed
Update for Maven Release process.
1 parent 191dd44 commit 00898b9

3 files changed

Lines changed: 115 additions & 29 deletions

File tree

.github/workflows/release.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
on:
22
push:
3-
# Sequence of patterns matched against refs/tags
43
tags:
5-
- '*' # Push events to matching v*, i.e. v1.0, v20.15.10
4+
- '*.*.*'
65

7-
name: Upload Release Asset
6+
name: Publish Release
87

98
jobs:
109
build:
11-
name: Upload Release Asset
10+
name: Publish Release
1211
runs-on: ubuntu-latest
1312
steps:
1413
- name: Checkout code
@@ -25,8 +24,7 @@ jobs:
2524
- name: Get Release Version
2625
id: get_version
2726
run: VERSION=$(./gradlew currentVersion -q -Prelease.quiet) && echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
28-
- name: Create Release and Upload Asset
29-
id: create_release
27+
- name: Create Release
3028
run: |
3129
gh release create \
3230
--generate-notes \
@@ -35,3 +33,10 @@ jobs:
3533
build/libs/ansible-plugin-${{ steps.get_version.outputs.VERSION }}.jar
3634
env:
3735
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
- name: Publish to Maven Central
37+
run: ./gradlew -PsigningKey=${SIGNING_KEY_B64} -PsigningPassword=${SIGNING_PASSWORD} -PsonatypeUsername=${SONATYPE_USERNAME} -PsonatypePassword=${SONATYPE_PASSWORD} publishToSonatype closeAndReleaseSonatypeStagingRepository
38+
env:
39+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
40+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
41+
SIGNING_KEY_B64: ${{ secrets.SIGNING_KEY_B64 }}
42+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}

build.gradle

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
plugins {
22
id 'pl.allegro.tech.build.axion-release' version '1.17.2'
3-
id 'maven-publish'
3+
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
44
}
55

6-
group = 'com.rundeck.plugins'
6+
group = 'org.rundeck.plugins'
7+
8+
ext.publishName = "Ansible Integration ${project.version}"
9+
ext.githubSlug = 'rundeck-plugins/ansible-plugin'
10+
ext.developers = [
11+
[id: 'rundeck', name: 'Rundeck Engineering', email: 'product@rundeck.com']
12+
]
713

814
ext.rundeckPluginVersion = '1.2'
915
ext.pluginClassNames = [
@@ -76,7 +82,9 @@ configurations {
7682

7783
dependencies {
7884
pluginLibs libs.gson
79-
implementation libs.rundeck.core
85+
// rundeck-core: compileOnly so SNAPSHOT is not in published POM; testImplementation for tests
86+
compileOnly libs.rundeck.core
87+
testImplementation libs.rundeck.core
8088
implementation libs.groovy.all
8189
pluginLibs libs.jackson.core
8290
pluginLibs libs.jackson.dataformat.yaml
@@ -139,27 +147,14 @@ jar {
139147
dependsOn(copyToLib)
140148
}
141149

142-
publishing {
143-
publications {
144-
maven(MavenPublication) {
145-
groupId = 'com.rundeck.plugins'
146-
artifactId = 'ansible-plugin'
147-
version = project.version
148-
from components.java
149-
}
150-
}
151-
150+
nexusPublishing {
151+
packageGroup = 'org.rundeck.plugins'
152152
repositories {
153-
maven {
154-
name = "PackageCloudTest"
155-
url = uri("https://packagecloud.io/pagerduty/rundeckpro-test/maven2")
156-
authentication {
157-
header(HttpHeaderAuthentication)
158-
}
159-
credentials(HttpHeaderCredentials) {
160-
name = "Authorization"
161-
value = "Bearer " + (System.getenv("PKGCLD_WRITE_TOKEN") ?: project.findProperty("pkgcldWriteToken"))
162-
}
153+
sonatype {
154+
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
155+
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
163156
}
164157
}
165158
}
159+
160+
apply from: "${rootDir}/gradle/publishing.gradle"

gradle/publishing.gradle

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Define project extension values in the project gradle file before including this file:
3+
*
4+
* publishName = 'Name of Package'
5+
* publishDescription = 'description' (optional)
6+
* githubSlug = Github slug e.g. 'rundeck/rundeck-cli'
7+
* developers = [ [id:'id', name:'name', email: 'email' ] ] list of developers
8+
*
9+
* Define project properties to sign and publish when invoking publish task:
10+
*
11+
* ./gradlew \
12+
* -PsigningKey="base64 encoded gpg key" \
13+
* -PsigningPassword="password for key" \
14+
* -PsonatypeUsername="sonatype token user" \
15+
* -PsonatypePassword="sonatype token password" \
16+
* publishToSonatype closeAndReleaseSonatypeStagingRepository
17+
*/
18+
apply plugin: 'maven-publish'
19+
apply plugin: 'signing'
20+
21+
publishing {
22+
publications {
23+
"${project.name}"(MavenPublication) { publication ->
24+
from components.java
25+
26+
pom {
27+
name = publishName
28+
description = project.ext.hasProperty('publishDescription') ? project.ext.publishDescription :
29+
project.description ?: publishName
30+
url = "https://github.com/${githubSlug}"
31+
licenses {
32+
license {
33+
name = 'The Apache Software License, Version 2.0'
34+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
35+
distribution = 'repo'
36+
}
37+
}
38+
scm {
39+
url = "https://github.com/${githubSlug}"
40+
connection = "scm:git:git@github.com/${githubSlug}.git"
41+
developerConnection = "scm:git:git@github.com:${githubSlug}.git"
42+
}
43+
if (project.ext.developers) {
44+
developers {
45+
project.ext.developers.each { dev ->
46+
developer {
47+
id = dev.id
48+
name = dev.name
49+
email = dev.email
50+
}
51+
}
52+
}
53+
}
54+
}
55+
56+
}
57+
}
58+
repositories {
59+
def pkgcldWriteToken = System.getenv("PKGCLD_WRITE_TOKEN") ?: project.findProperty("pkgcldWriteToken")
60+
if (pkgcldWriteToken) {
61+
maven {
62+
name = "PackageCloudTest"
63+
url = uri("https://packagecloud.io/pagerduty/rundeckpro-test/maven2")
64+
authentication {
65+
header(HttpHeaderAuthentication)
66+
}
67+
credentials(HttpHeaderCredentials) {
68+
name = "Authorization"
69+
value = "Bearer " + pkgcldWriteToken
70+
}
71+
}
72+
}
73+
}
74+
}
75+
def base64Decode = { String prop ->
76+
project.findProperty(prop) ?
77+
new String(Base64.getDecoder().decode(project.findProperty(prop).toString())).trim() :
78+
null
79+
}
80+
81+
if (project.hasProperty('signingKey') && project.hasProperty('signingPassword')) {
82+
signing {
83+
useInMemoryPgpKeys(base64Decode("signingKey"), project.signingPassword)
84+
sign(publishing.publications)
85+
}
86+
}

0 commit comments

Comments
 (0)