Skip to content

Commit

Permalink
Add scripts for releasing and update pom to allow pushing to sonatype (
Browse files Browse the repository at this point in the history
…#12)

## Description

This PR contains scripts and workflows that handles releasing to github
and sonatype.

## Type of Change

* New feature (non-breaking change which adds functionality)

## Checklist

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings

---------

Signed-off-by: Jakub Stejskal <[email protected]>
  • Loading branch information
Frawless authored Jul 12, 2024
1 parent 6a998a1 commit 368680a
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/scripts/prepare-tag-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# Script change version and run build
# then adds changes and do a release commit
# then creates tag with version specified by argument
# user must then push tags using `git push --tags` and do a release in github

TAG=$1
echo "Tagging version to ${TAG}"

mvn versions:set -DnewVersion=${TAG}
mvn clean install
git add "."
git diff --staged --quiet || git commit -m "Release ${TAG}"
git tag -a ${TAG} -m "${TAG}"
12 changes: 12 additions & 0 deletions .github/scripts/push-to-nexus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

export GPG_TTY=$(tty)

echo $GPG_SIGNING_KEY | base64 -d > signing.gpg
gpg --batch --import signing.gpg

GPG_EXECUTABLE=gpg mvn -DskipTests -s ./.github/scripts/settings.xml -P central-sonatype clean deploy

rm -rf signing.gpg
gpg --delete-keys
gpg --delete-secret-keys
11 changes: 11 additions & 0 deletions .github/scripts/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>central</id>
<username>${env.NEXUS_USERNAME}</username>
<password>${env.NEXUS_PASSWORD}</password>
</server>
</servers>
</settings>
40 changes: 40 additions & 0 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish-release

on:
push:
tags:
- '*'

jobs:
publish-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
server-id: github
settings-path: ${{ github.workspace }}

- name: Cache m2 repo
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build
run: mvn clean install

- name: Publish to sonatype
run: ./.github/scripts/push-to-nexus.sh
env:
BUILD_ENV: 'github-actions'
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
GPG_KEYNAME: ${{ secrets.GPG_KEYNAME }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
45 changes: 45 additions & 0 deletions .github/workflows/publish-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish-snapshot

on:
push:
branches: [ main ]

jobs:
publish-snapshot:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
server-id: github
settings-path: ${{ github.workspace }}

- name: Setup Maven settings.xml
uses: whelk-io/maven-settings-xml-action@v11
with:
servers:
'[
{
"id": "github",
"username": "${env.GITHUB_USERNAME}",
"password": "${env.GITHUB_TOKEN}"
}
]'

- name: Cache m2 repo
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Publish to GitHub Packages Apache Maven
run: mvn deploy
env:
GITHUB_USERNAME: x-access-token
GITHUB_TOKEN: ${{ secrets.TOKEN }}
BUILD_ENV: 'github-actions'
83 changes: 83 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
<maven.javadoc.version>3.7.0</maven.javadoc.version>
<maven.assembly.version>3.4.2</maven.assembly.version>
<maven.plugin.plugin.version>3.9.0</maven.plugin.plugin.version>
<maven.gpg.version>3.1.0</maven.gpg.version>
<maven.assembly.version>3.4.2</maven.assembly.version>
<sonatype.nexus.central>0.5.0</sonatype.nexus.central>

<log4j.version>2.23.1</log4j.version>
<junit.jupiter.version>5.10.2</junit.jupiter.version>
Expand Down Expand Up @@ -310,4 +313,84 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>central-sonatype</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<!--suppress UnresolvedMavenProperty -->
<gpg.executable>${env.GPG_EXECUTABLE}</gpg.executable>
<!--suppress UnresolvedMavenProperty -->
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
<!--suppress UnresolvedMavenProperty -->
<gpg.keyname>${env.GPG_KEYNAME}</gpg.keyname>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven.gpg.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--batch</arg>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>${sonatype.nexus.central}</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<tokenAuth>true</tokenAuth>
<checksums>all</checksums>
<autoPublish>true</autoPublish>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<tarLongFileMode>posix</tarLongFileMode>
<descriptors>
<descriptor>src/main/assembly/dist.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
35 changes: 35 additions & 0 deletions src/assembly/dist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>zip</id>
<includeBaseDirectory>true</includeBaseDirectory>

<formats>
<format>tar.gz</format>
<format>zip</format>
<format>dir</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<includes>
<include>README*</include>
</includes>
<fileMode>0644</fileMode>
</fileSet>
<fileSet>
<directory>${project.basedir}</directory>
<includes>
<include>LICENSE</include>
</includes>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<scope>runtime</scope>
<outputDirectory>libs</outputDirectory>
<fileMode>0644</fileMode>
</dependencySet>
</dependencySets>
</assembly>

0 comments on commit 368680a

Please sign in to comment.