Skip to content

Commit 0a3ac02

Browse files
committed
Use GitHub actions to deploy to OSS Sonatype/Maven Central
[resolves #186]
1 parent 97f35ab commit 0a3ac02

14 files changed

+194
-410
lines changed

.github/workflows/ci.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow will build a Java project with Maven
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: Java CI with Maven
5+
6+
on:
7+
push:
8+
branches: [ main, 0.8.x ]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up JDK 1.8
16+
uses: actions/setup-java@v1
17+
with:
18+
java-version: 1.8
19+
- name: Cache local Maven repository
20+
uses: actions/cache@v2
21+
with:
22+
path: ~/.m2/repository
23+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
24+
restore-keys: |
25+
${{ runner.os }}-maven-
26+
- name: Build with Maven
27+
env:
28+
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
29+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
30+
run: ./mvnw -B deploy -P snapshot -s settings.xml

.github/workflows/pullrequests.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This workflow will build a Java project with Maven
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: Build Pull request with Maven
5+
6+
on: [pull_request]
7+
8+
jobs:
9+
pr-build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up JDK 1.8
14+
uses: actions/setup-java@v1
15+
with:
16+
java-version: 1.8
17+
- name: Cache local Maven repository
18+
uses: actions/cache@v2
19+
with:
20+
path: ~/.m2/repository
21+
key: ${{ runner.os }}-maven-pr-${{ hashFiles('**/pom.xml') }}
22+
restore-keys: |
23+
${{ runner.os }}-maven-pr-
24+
- name: Build with Maven
25+
run: ./mvnw -B verify

.github/workflows/release.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This workflow will build a Java project with Maven
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: Stage release to Maven Central
5+
6+
on:
7+
push:
8+
branches: [ release-0.x ]
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up JDK 1.8
16+
uses: actions/setup-java@v1
17+
with:
18+
java-version: 1.8
19+
- name: Initialize Maven Version
20+
run: ./mvnw -q org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version
21+
- name: GPG Check
22+
run: gpg -k
23+
- name: Release with Maven
24+
env:
25+
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
26+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
27+
GPG_KEY_BASE64: ${{ secrets.GPG_KEY_BASE64 }}
28+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
29+
run: ci/build-and-deploy-to-maven-central.sh

CI.adoc

-23
This file was deleted.

Jenkinsfile

-116
This file was deleted.

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ If you'd rather like the latest snapshots of the upcoming major version, use our
3838
</dependency>
3939

4040
<repository>
41-
<id>spring-libs-snapshot</id>
42-
<name>Spring Snapshot Repository</name>
43-
<url>https://repo.spring.io/libs-snapshot</url>
41+
<id>sonatype-nexus-snapshots</id>
42+
<name>Sonatype OSS Snapshot Repository</name>
43+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
4444
</repository>
4545
```
4646

@@ -81,6 +81,10 @@ If you want to build with the regular `mvn` command, you will need [Maven v3.5.0
8181

8282
_Also see [CONTRIBUTING.adoc](https://github.com/r2dbc/.github/blob/main/CONTRIBUTING.adoc) if you wish to submit pull requests, and in particular please sign the [Contributor's Agreement](https://cla.pivotal.io/sign/reactor) before your first change, however trivial._
8383

84+
## Staging to Maven Central
85+
86+
To stage a release to Maven Central, you need to create a release tag (release version) that contains the desired state and version numbers (`mvn versions:set versions:commit -q -o -DgenerateBackupPoms=false -DnewVersion=x.y.z.(RELEASE|Mnnn|RCnnn`) and force-push it to the `release-0.x` branch. This push will trigger a Maven staging build (see `build-and-deploy-to-maven-central.sh`).
87+
8488
## License
8589
This project is released under version 2.0 of the [Apache License][l].
8690

ci/Dockerfile

-9
This file was deleted.

ci/build-and-deploy-to-artifactory.sh

-10
This file was deleted.

ci/build-and-deploy-to-maven-central.sh

+33-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1-
#!/bin/bash -x
1+
#!/bin/bash
22

33
set -euo pipefail
44

5-
#
6-
# Stage on Maven Central
7-
#
8-
echo 'Staging on Maven Central...'
5+
VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version -o | grep -v INFO)
96

10-
GNUPGHOME=/tmp/gpghome
11-
export GNUPGHOME
7+
if [[ $VERSION =~ [^.*-SNAPSHOT$] ]] ; then
128

13-
mkdir $GNUPGHOME
14-
cp $KEYRING $GNUPGHOME
9+
echo "Cannot deploy a snapshot: $VERSION"
10+
exit 1
11+
fi
12+
13+
if [[ $VERSION =~ [^(\d+\.)+(RC(\d+)|M(\d+)|RELEASE)$] ]] ; then
14+
15+
#
16+
# Prepare GPG Key is expected to be in base64
17+
# Exported with gpg -a --export-secret-keys "your@email" | base64 > gpg.base64
18+
#
19+
printf "$GPG_KEY_BASE64" | base64 --decode > gpg.asc
20+
echo ${GPG_PASSPHRASE} | gpg --batch --yes --passphrase-fd 0 --import gpg.asc
21+
gpg -k
22+
23+
#
24+
# Stage on Maven Central
25+
#
26+
echo "Staging $VERSION to Maven Central"
27+
28+
./mvnw \
29+
-s settings.xml \
30+
-Pcentral \
31+
-Dmaven.test.skip=true \
32+
-Dgpg.passphrase=${GPG_PASSPHRASE} \
33+
clean deploy -B
34+
else
35+
36+
echo "Not a release: $VERSION"
37+
exit 1
38+
fi
1539

16-
MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw \
17-
-s settings.xml \
18-
-P${PROFILE} \
19-
-Dmaven.test.skip=true \
20-
-Dgpg.passphrase=${PASSPHRASE} \
21-
-Dgpg.secretKeyring=${GNUPGHOME}/secring.gpg \
22-
clean deploy -B

ci/create-release.sh

-18
This file was deleted.

ci/test.sh

-5
This file was deleted.

0 commit comments

Comments
 (0)