Skip to content

Commit

Permalink
ci(central): add configurations for JReleaser publication to Maven Ce…
Browse files Browse the repository at this point in the history
…ntral (#338)
  • Loading branch information
andrewazores authored Jan 26, 2024
1 parent ebb773d commit 87af41a
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 2 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/maven-central-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Inspired from https://foojay.io/today/how-to-release-a-java-module-with-jreleaser-to-maven-central-with-github-actions/
name: Publish a new release

on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
nextVersion:
description: 'Next version after release (-SNAPSHOT will be added automatically)'
required: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Java setup
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Run a build of the code base before release
run: ./mvnw --batch-mode --no-transfer-progress clean install
- name: Set release version
run: ./mvnw --batch-mode --no-transfer-progress versions:set -DnewVersion=${{ github.event.inputs.version }}
- name: Commit & Push changes
uses: actions-js/push@v1.4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: "Releasing version ${{ github.event.inputs.version }}"
- name: Release with JReleaser
env:
JRELEASER_TAG_NAME: ${{ github.event.inputs.version }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE }}
JRELEASER_NEXUS2_USERNAME: ${{ secrets.MAVEN_CENTRAL_NEXUS2_USERNAME }}
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.MAVEN_CENTRAL_NEXUS2_PASSWORD }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./release.sh
- name: Set the next release version
run: ./mvnw --batch-mode --no-transfer-progress versions:set -DnewVersion=${{ github.event.inputs.nextVersion }}-SNAPSHOT
- name: Commit & Push changes
uses: actions-js/push@v1.4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: "Setting version ${{ github.event.inputs.nextVersion }}-SNAPSHOT"

131 changes: 129 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,46 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>

<name>Cryostat Core</name>
<description>Core library for Cryostat</description>
<url>https://github.com/cryostatio/cryostat-core</url>
<inceptionYear>2019</inceptionYear>

<groupId>io.cryostat</groupId>
<artifactId>cryostat-core</artifactId>

<version>2.28.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cryostat-core</name>
<url>http://maven.apache.org</url>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
<license>
<name>Universal Permissive License Version 1.0</name>
<url>http://oss.oracle.com/licenses/upl</url>
<distribution>repo</distribution>
<comments>Copyright (c) 2018, 2023, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.</comments>
</license>
</licenses>

<developers>
<developer>
<name>Andrew Azores</name>
<email>aazores@redhat.com</email>
<organization>Red Hat</organization>
<organizationUrl>https://www.redhat.com</organizationUrl>
</developer>
<developer>
<name>Elliott Baron</name>
<email>ebaron@redhat.com</email>
<organization>Red Hat</organization>
<organizationUrl>https://www.redhat.com</organizationUrl>
</developer>
</developers>

<distributionManagement>
<repository>
Expand All @@ -18,6 +52,12 @@
</repository>
</distributionManagement>

<scm>
<connection>scm:git://github.com/cryostatio/cryostat-core.git</connection>
<developerConnection>scm:git:ssh://github.com:cryostatio/cryostat-core.git</developerConnection>
<url>https://github.com/cryostatio/cryostat-core/tree/main</url>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
Expand Down Expand Up @@ -45,6 +85,10 @@
<org.jacoco.maven.plugin.version>0.8.11</org.jacoco.maven.plugin.version>
<com.diffplug.spotless.maven.plugin.version>2.43.0</com.diffplug.spotless.maven.plugin.version>
<org.slf4j.version>2.0.7</org.slf4j.version>

<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.6.2</maven-javadoc-plugin.version>
<jreleaser-maven-plugin.version>1.9.0</jreleaser-maven-plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -274,6 +318,89 @@
</plugins>
</build>

<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.jreleaser</groupId>
<artifactId>jreleaser-maven-plugin</artifactId>
<version>${jreleaser-maven-plugin.version}</version>
<inherited>false</inherited>
<configuration>
<jreleaser>
<signing>
<active>ALWAYS</active>
<armored>true</armored>
</signing>
<deploy>
<maven>
<nexus2>
<maven-central>
<active>ALWAYS</active>
<url>https://oss.sonatype.org/service/local</url>
<snapshotUrl>https://oss.sonatype.org/content/repositories/snapshots/</snapshotUrl>
<closeRepository>true</closeRepository>
<releaseRepository>true</releaseRepository>
<stagingRepositories>target/staging-deploy</stagingRepositories>
</maven-central>
</nexus2>
</maven>
</deploy>
</jreleaser>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>publication</id>
<properties>
<altDeploymentRepository>local::file:./target/staging-deploy</altDeploymentRepository>
</properties>
<build>
<defaultGoal>deploy</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<attach>true</attach>
<failOnError>false</failOnError>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
<configuration>
<attach>true</attach>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<reporting>
<plugins>
<plugin>
Expand Down
11 changes: 11 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

echo "📦 Staging artifacts..."
./mvnw --batch-mode --no-transfer-progress -Ppublication -DskipTests=true -Dskip.spotless=true

echo "🚀 Releasing..."
./mvnw --batch-mode --no-transfer-progress -Prelease jreleaser:full-release

echo "🎉 Done!"

0 comments on commit 87af41a

Please sign in to comment.