Skip to content

Commit ada0330

Browse files
authoredJun 11, 2024··
Merge pull request #8 from diffblue/thomas/addAutomatedRelease
Automate releases
2 parents 17d719d + 52d8ef6 commit ada0330

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed
 

‎.github/settings.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
<servers>
6+
<server>
7+
<id>${env.GPG_ID}</id>
8+
<passphrase>${env.GPG_PASSPHRASE}</passphrase>
9+
</server>
10+
<server>
11+
<id>ossrh</id>
12+
<username>${env.MAVEN_USERNAME}</username>
13+
<password>${env.MAVEN_PASSWORD}</password>
14+
</server>
15+
</servers>
16+
<profiles>
17+
<profile>
18+
<id>release</id>
19+
<activation>
20+
<activeByDefault>true</activeByDefault>
21+
</activation>
22+
<properties>
23+
<gpg.keyname>${env.GPG_ID}</gpg.keyname>
24+
</properties>
25+
</profile>
26+
</profiles>
27+
</settings>

‎.github/workflows/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# CI Readme
2+
3+
## Release
4+
5+
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).
6+
7+
Once this is complete create a mergeback from `main` into `develop` to keep both branches in sync.

‎.github/workflows/release.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Release to Maven Central
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
sign-build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout this branch
13+
uses: actions/checkout@v4
14+
with:
15+
token: ${{ github.token }}
16+
fetch-depth: 0
17+
18+
- name: Check version number has been increased
19+
run: |
20+
CURRENT_VERSION="v$(awk -F'[<>]' '/<version>/ {print $3; exit}' pom.xml)"
21+
echo "Current version: '$CURRENT_VERSION'"
22+
PREVIOUS_VERSION=$(git describe --tags --abbrev=0)
23+
echo "Previous version: '$PREVIOUS_VERSION'"
24+
if [[ "$CURRENT_VERSION" == "$PREVIOUS_VERSION" ]]; then
25+
echo "Version number has not changed"
26+
echo "skip=true" >> $GITHUB_ENV
27+
else
28+
echo "skip=false" >> $GITHUB_ENV
29+
fi
30+
31+
- name: Configure GPG Key
32+
if: ${{ env.skip == 'false' }}
33+
run: |
34+
echo -n "$GPG_KEY_BASE64" | base64 --decode | gpg --batch --passphrase ${GPG_PASSPHRASE} --import
35+
env:
36+
GPG_KEY_BASE64: ${{ secrets.GPG_KEY_BASE64 }}
37+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
38+
39+
- name: Deploy Signed Jar to Maven Central
40+
if: ${{ env.skip == 'false' }}
41+
run: |
42+
mvn clean deploy -B -P sign,stdbuild --settings .github/settings.xml repository:bundle-create
43+
env:
44+
GPG_ID: ${{ secrets.GPG_ID }}
45+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
46+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
47+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
48+
49+
- name: Create Release on GitHub
50+
if: ${{ env.skip == 'false' }}
51+
env:
52+
GH_TOKEN: ${{ github.token }}
53+
run: |
54+
VERSION_NUMBER=$(awk -F'[<>]' '/<version>/ {print $3; exit}' pom.xml)
55+
git tag "v$VERSION_NUMBER"
56+
git push origin "v$VERSION_NUMBER"
57+
gh release create "v$VERSION_NUMBER" --repo="$GITHUB_REPOSITORY" --title="v$VERSION_NUMBER" --generate-notes

‎pom.xml

+31
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
<!-- nb this must be the same as the 'id' field in 'settings.xml' -->
5252
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
5353
</snapshotRepository>
54+
<repository>
55+
<id>ossrh</id>
56+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
57+
</repository>
5458
</distributionManagement>
5559

5660
<properties>
@@ -64,6 +68,21 @@
6468
<gpg.plugin.version>3.2.1</gpg.plugin.version>
6569
</properties>
6670

71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.sonatype.plugins</groupId>
75+
<artifactId>nexus-staging-maven-plugin</artifactId>
76+
<version>1.6.13</version>
77+
<extensions>true</extensions>
78+
<configuration>
79+
<serverId>ossrh</serverId>
80+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
81+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
82+
</configuration>
83+
</plugin>
84+
</plugins>
85+
</build>
6786
<profiles>
6887
<profile>
6988
<id>stdbuild</id>
@@ -92,6 +111,7 @@
92111
<executions>
93112
<execution>
94113
<id>attach-sources</id>
114+
<phase>verify</phase>
95115
<goals>
96116
<goal>jar</goal>
97117
</goals>
@@ -107,6 +127,7 @@
107127
<executions>
108128
<execution>
109129
<id>attach-javadocs</id>
130+
<phase>verify</phase>
110131
<goals>
111132
<goal>jar</goal>
112133
</goals>
@@ -195,6 +216,16 @@
195216
<goal>sign</goal>
196217
</goals>
197218
<phase>verify</phase>
219+
<configuration>
220+
<useAgent>true</useAgent>
221+
<keyname>${gpg.keyname}</keyname>
222+
<passphraseServerId>${gpg.keyname}</passphraseServerId>
223+
<gpgArguments>
224+
<arg>--batch</arg>
225+
<arg>--pinentry-mode</arg>
226+
<arg>loopback</arg>
227+
</gpgArguments>
228+
</configuration>
198229
</execution>
199230
</executions>
200231
</plugin>

0 commit comments

Comments
 (0)
Please sign in to comment.