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 (#335)
  • Loading branch information
andrewazores authored Feb 12, 2024
1 parent b104081 commit 93291ae
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 6 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/maven-central-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Inspired from https://foojay.io/today/how-to-release-a-java-module-with-jreleaser-to-maven-central-with-github-actions/
name: Publish a new Maven Central release

on:
workflow_dispatch:
# inputs:
# version:
# description: 'Release version'
# 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: 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.SUBMODULE_TOKEN }}
run: ./release.sh
6 changes: 3 additions & 3 deletions .github/workflows/maven-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ jobs:
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Build with Maven
run: mvn -B -U package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml
run: ./mvnw -B -U package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml

- name: Publish to GitHub Packages Apache Maven
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
run: ./mvnw deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}

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

<modelVersion>4.0.0</modelVersion>

<name>Cryostat Agent</name>
<description>JVM Agent for Cryostat</description>
<url>https://github.com/cryostatio/cryostat-agent</url>
<inceptionYear>2022</inceptionYear>
<packaging>jar</packaging>

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

<version>0.4.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cryostat-agent</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>
</licenses>

<developers>
<developer>
<name>Andrew Azores</name>
<email>[email protected]</email>
<organization>Red Hat</organization>
<organizationUrl>https://www.redhat.com</organizationUrl>
</developer>
<developer>
<name>Elliott Baron</name>
<email>[email protected]</email>
<organization>Red Hat</organization>
<organizationUrl>https://www.redhat.com</organizationUrl>
</developer>
</developers>

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

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

<properties>
<mainClass>io.cryostat.agent.Agent</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -67,6 +101,10 @@
<com.google.googlejavaformat.version>1.17.0</com.google.googlejavaformat.version>
<org.jsoup.version>1.15.3</org.jsoup.version>

<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
<jreleaser-maven-plugin.version>1.10.0</jreleaser-maven-plugin.version>

<shade.prefix>io.cryostat.agent.shaded</shade.prefix>
</properties>

Expand Down Expand Up @@ -498,6 +536,87 @@
</plugins>
</build>
</profile>

<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://s01.oss.sonatype.org/service/local</url>
<snapshotUrl>https://s01.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>

</project>
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 93291ae

Please sign in to comment.