Skip to content

Commit 3b6a365

Browse files
Merge pull request #18 from PowerGridModel/publish-snapshot
Publish library
2 parents 67a6dbb + f4aae07 commit 3b6a365

2 files changed

Lines changed: 125 additions & 2 deletions

File tree

‎.github/workflows/java-gradle-ci.yml‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ name: Java CI with Gradle for library
77
on:
88
push:
99
workflow_dispatch:
10+
inputs:
11+
create_release:
12+
type: boolean
13+
description: Create a release when CI passes
14+
default: false
15+
required: true
1016

1117
concurrency:
1218
group: ${{ github.workflow }}-${{ github.ref }}
@@ -51,3 +57,51 @@ jobs:
5157
reuse-compliance:
5258
name: REUSE Compliance
5359
uses: ./.github/workflows/reuse-compliance.yml
60+
61+
publish:
62+
name: Publish to maven central
63+
needs: [build-and-test]
64+
if: github.ref_type == 'tag'
65+
runs-on: ubuntu-latest
66+
environment: release
67+
permissions:
68+
contents: read
69+
70+
steps:
71+
- name: Checkout repository
72+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1
73+
with:
74+
fetch-depth: 1
75+
persist-credentials: false
76+
77+
- name: Setup runtime
78+
uses: ./.github/actions/setup-runtime
79+
80+
- name: Cache Gradle
81+
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 #v6.1.0
82+
with:
83+
path: |
84+
~/.gradle/caches
85+
~/.gradle/wrapper
86+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/settings.gradle*') }}
87+
88+
- name: Optimize Gradle
89+
shell: bash
90+
run: |
91+
mkdir -p ~/.gradle
92+
echo "org.gradle.caching=true" >> ~/.gradle/gradle.properties
93+
echo "org.gradle.configuration-cache=true" >> ~/.gradle/gradle.properties
94+
95+
- name: Gradle Release Build
96+
env:
97+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
98+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
99+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
100+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVEN_USERNAME }}
101+
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
102+
SANITIZED_TAG: ${{ github.ref_name }}
103+
run: |
104+
echo "Performing release Gradle publish for tag: $SANITIZED_TAG"
105+
106+
./gradlew clean build publish -Pversion=$SANITIZED_TAG
107+
./gradlew jreleaserDeploy -Pversion=$SANITIZED_TAG

‎build.gradle‎

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import javax.inject.Inject
77
plugins {
88
id 'java'
99
id 'maven-publish'
10+
id 'org.jreleaser' version '1.26.0'
1011
}
1112

1213
interface InjectedExecOps {
@@ -15,7 +16,6 @@ interface InjectedExecOps {
1516
}
1617

1718
group = 'org-power-grid-model'
18-
version = '1.0-SNAPSHOT'
1919

2020
repositories {
2121
mavenCentral()
@@ -268,6 +268,21 @@ sourceSets {
268268
}
269269
}
270270

271+
tasks.register('sourcesJar', Jar) {
272+
dependsOn(tasks.named('generatePGMBindings'))
273+
from sourceSets.main.java
274+
archiveClassifier.set('sources')
275+
}
276+
277+
artifacts {
278+
archives sourcesJar
279+
}
280+
281+
java {
282+
withSourcesJar()
283+
withJavadocJar()
284+
}
285+
271286
tasks.named('compileJava') {
272287
dependsOn(tasks.named('generatePGMBindings'))
273288
}
@@ -277,10 +292,64 @@ tasks.named('processResources') {
277292
}
278293

279294
publishing {
295+
repositories {
296+
maven {
297+
url = layout.buildDirectory.dir("staging-deploy")
298+
}
299+
}
280300
publications {
281301
mavenJava(MavenPublication) {
282302
from components.java
283-
artifactId = 'lib-power-grid-model'
303+
groupId = 'org.lfenergy.powergridmodel'
304+
artifactId = 'power-grid-model-ffm'
305+
306+
pom {
307+
name = 'power-grid-model-ffm'
308+
description = 'Java package which wraps PGM core shared library'
309+
url = 'https://github.com/PowerGridModel/libpower-grid-model-java'
310+
organization {
311+
name = 'LF Energy'
312+
url = 'https://lfenergy.org'
313+
}
314+
licenses {
315+
license {
316+
name = 'Mozilla Public License, Version 2.0'
317+
url = 'https://www.mozilla.org/en-US/MPL/2.0/'
318+
}
319+
}
320+
developers {
321+
developer {
322+
id = 'contributors'
323+
name = 'Power Grid Model Contributors'
324+
email = 'powergridmodel@lfenergy.org'
325+
url = 'https://github.com/PowerGridModel/libpower-grid-model-java'
326+
}
327+
}
328+
scm {
329+
url = 'https://github.com/PowerGridModel/libpower-grid-model-java'
330+
connection = 'scm:git:git://github.com/PowerGridModel/libpower-grid-model-java.git'
331+
developerConnection = 'scm:git:ssh://git@github.com/PowerGridModel/libpower-grid-model-java.git'
332+
}
333+
}
334+
335+
}
336+
}
337+
}
338+
339+
jreleaser {
340+
signing {
341+
active = 'ALWAYS'
342+
armored = true
343+
}
344+
deploy {
345+
maven {
346+
mavenCentral {
347+
'release-deploy' {
348+
active = 'RELEASE'
349+
url = 'https://central.sonatype.com/api/v1/publisher'
350+
stagingRepository('build/staging-deploy')
351+
}
352+
}
284353
}
285354
}
286355
}

0 commit comments

Comments
 (0)