Skip to content

Commit

Permalink
Merge pull request #12 from jponge/ci/release-workflow
Browse files Browse the repository at this point in the history
Release workflow based on JReleaser and Maven Central compliance
  • Loading branch information
ebaron authored Nov 21, 2023
2 parents 1370c72 + 11b6d6a commit 9f7eed9
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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: '8'
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.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_NEXUS2_USERNAME: ${{ secrets.JRELEASER_NEXUS2_USERNAME }}
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.JRELEASER_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"
119 changes: 119 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@
<artifactId>runtimes-agent</artifactId>
<version>1.0.0-SNAPSHOT</version>

<name>Red Hat Insights Java Agent</name>
<description>Red Hat Insights Java Agent</description>
<url>https://github.com/RedHatInsights/insights-java-agent</url>
<inceptionYear>2023</inceptionYear>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<developers>
<developer>
<name>Benjamin Evans</name>
<email>beevans@redhat.com</email>
<organization>Red Hat</organization>
<organizationUrl>https://www.redhat.com/</organizationUrl>
</developer>
<developer>
<id>ebaron</id>
<name>Elliott Baron</name>
<email>ebaron@redhat.com</email>
<organization>Red Hat</organization>
<organizationUrl>https://www.redhat.com/</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/RedHatInsights/insights-java-agent.git</connection>
<developerConnection>scm:git:ssh://github.com:RedHatInsights/insights-java-agent.git</developerConnection>
<url>http://github.com/RedHatInsights/insights-java-agent/tree/main</url>
</scm>

<properties>
<!-- <maven.compiler.release>8</maven.compiler.release>-->
<maven.compiler.source>8</maven.compiler.source>
Expand Down Expand Up @@ -39,6 +73,9 @@
<maven-install-plugin.version>3.1.0</maven-install-plugin.version>
<maven-clean-plugin.version>3.2.0</maven-clean-plugin.version>
<maven-resources-plugin.version>3.3.0</maven-resources-plugin.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>

<shade.prefix>com.redhat.insights.agent.shaded</shade.prefix>
</properties>
Expand Down Expand Up @@ -440,6 +477,7 @@
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<attach>true</attach>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -515,5 +553,86 @@
</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://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>
</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 9f7eed9

Please sign in to comment.