Skip to content

Automate releases #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>${env.GPG_ID}</id>
<passphrase>${env.GPG_PASSPHRASE}</passphrase>
</server>
<server>
<id>ossrh</id>
<username>${env.MAVEN_USERNAME}</username>
<password>${env.MAVEN_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<id>release</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.keyname>${env.GPG_ID}</gpg.keyname>
</properties>
</profile>
</profiles>
</settings>
7 changes: 7 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CI Readme

## Release

To create a new release make a PR from `develop` into `main`. Once this is merged if the version number has changed a signed build will then be created and pushed to maven central. If all checks pass this will go live automatically (This may take up to 48 hours).

Once this is complete create a mergeback from `main` into `develop` to keep both branches in sync.
57 changes: 57 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Release to Maven Central

on:
push:
branches:
- "main"

jobs:
sign-build:
runs-on: ubuntu-latest
steps:
- name: Checkout this branch
uses: actions/checkout@v4
with:
token: ${{ github.token }}
fetch-depth: 0

- name: Check version number has been increased
run: |
CURRENT_VERSION="v$(awk -F'[<>]' '/<version>/ {print $3; exit}' pom.xml)"
echo "Current version: '$CURRENT_VERSION'"
PREVIOUS_VERSION=$(git describe --tags --abbrev=0)
echo "Previous version: '$PREVIOUS_VERSION'"
if [[ "$CURRENT_VERSION" == "$PREVIOUS_VERSION" ]]; then
echo "Version number has not changed"
echo "skip=true" >> $GITHUB_ENV
else
echo "skip=false" >> $GITHUB_ENV
fi

- name: Configure GPG Key
if: ${{ env.skip == 'false' }}
run: |
echo -n "$GPG_KEY_BASE64" | base64 --decode | gpg --batch --passphrase ${GPG_PASSPHRASE} --import
env:
GPG_KEY_BASE64: ${{ secrets.GPG_KEY_BASE64 }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

- name: Deploy Signed Jar to Maven Central
if: ${{ env.skip == 'false' }}
run: |
mvn clean deploy -B -P sign,stdbuild --settings .github/settings.xml repository:bundle-create
env:
GPG_ID: ${{ secrets.GPG_ID }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}

- name: Create Release on GitHub
if: ${{ env.skip == 'false' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION_NUMBER=$(awk -F'[<>]' '/<version>/ {print $3; exit}' pom.xml)
git tag "v$VERSION_NUMBER"
git push origin "v$VERSION_NUMBER"
gh release create "v$VERSION_NUMBER" --repo="$GITHUB_REPOSITORY" --title="v$VERSION_NUMBER" --generate-notes
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<!-- nb this must be the same as the 'id' field in 'settings.xml' -->
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement>

<properties>
Expand All @@ -64,6 +68,21 @@
<gpg.plugin.version>3.2.1</gpg.plugin.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>stdbuild</id>
Expand Down Expand Up @@ -92,6 +111,7 @@
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
Expand All @@ -107,6 +127,7 @@
<executions>
<execution>
<id>attach-javadocs</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
Expand Down Expand Up @@ -195,6 +216,16 @@
<goal>sign</goal>
</goals>
<phase>verify</phase>
<configuration>
<useAgent>true</useAgent>
<keyname>${gpg.keyname}</keyname>
<passphraseServerId>${gpg.keyname}</passphraseServerId>
<gpgArguments>
<arg>--batch</arg>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Loading