Skip to content

Commit a6d19ed

Browse files
committed
JVMCBC-1638 Publish via GitHub Actions
Modifications ------------- Add GitHub Actions for publishing snapshots and releases. Automatically publish a snapshot when something is pushed to master. The release action is initiated by a human who specifies an existing tag to release. Use maven-enforcer-plugin to require: - Release version does not have -SNAPSHOT suffix - Snapshot version DOES have -SNAPSHOT suffix - Either the `snapshot` or `release` profile is active when deploying. - When deploying, it is an error to specify an unrecognized profile. Change-Id: I98603f41bd3eaebcaec0ca118f5db0dbeb7ab8a3 Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/227011 Reviewed-by: Michael Reiche <[email protected]> Tested-by: David Nault <[email protected]>
1 parent 5099633 commit a6d19ed

File tree

5 files changed

+199
-0
lines changed

5 files changed

+199
-0
lines changed

.github/scripts/deploy.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
# CI script for publishing to Maven Central.
4+
5+
if [ $# -ne 1 ]; then
6+
echo 1>&2 "$0: requires exactly one argument, the Maven profile (snapshot or release)"
7+
exit 2
8+
fi
9+
10+
MAVEN_PROFILE=$1
11+
12+
set -e
13+
set -x
14+
15+
./mvnw --batch-mode --file protostellar/pom.xml clean install
16+
./mvnw --batch-mode --file tracing-opentelemetry-deps/pom.xml clean install
17+
./mvnw --batch-mode --file core-io-deps/pom.xml clean install
18+
19+
# Improper shading should have been caught during PR verification, but let's double check.
20+
./mvnw --batch-mode --file core-io/pom.xml install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true
21+
cd core-io ; ./shade-check.sh ; cd ..
22+
./mvnw --batch-mode --file java-client/pom.xml install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true
23+
./mvnw --batch-mode --file tracing-opentelemetry/pom.xml install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true
24+
cd tracing-opentelemetry ; ./shade-check.sh ; cd ..
25+
26+
./mvnw --batch-mode --settings deploy-settings.xml deploy -Dgpg.signer=bc -Dsurefire.rerunFailingTestsCount=1 --activate-profiles ${MAVEN_PROFILE}
27+
./mvnw --batch-mode --settings deploy-settings.xml clean deploy -Dgpg.signer=bc -Dmaven.test.skip=true --activate-profiles ${MAVEN_PROFILE},scala-2.13 --projects scala-implicits,scala-client
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Maven Deploy Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
type: string
8+
description: Tag to release. Must already exist.
9+
required: true
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
ref: ${{ inputs.tag }}
21+
22+
- name: Verify the ref is actually a tag
23+
run: git tag --list | grep --line-regexp ${{ inputs.tag }}
24+
25+
- name: Set up JDK 21
26+
uses: actions/setup-java@v4
27+
with:
28+
java-version: '21'
29+
distribution: 'temurin'
30+
31+
- name: Build and deploy to Maven Central
32+
run: .github/scripts/deploy.sh release
33+
env:
34+
MAVEN_USERNAME: ${{ vars.MAVEN_USERNAME }}
35+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
36+
MAVEN_GPG_KEY: ${{ secrets.SDK_ROBOT_GPG_PRIVATE_KEY }}
37+
MAVEN_GPG_PASSPHRASE: ''
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Maven Deploy Snapshot
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
paths-ignore:
11+
- '.gitignore'
12+
- '.editorconfig'
13+
- '.scalafmt.conf'
14+
- '*-fit-*/**'
15+
- '*-examples/**'
16+
- 'test-utils/**'
17+
- 'Jenkinsfile'
18+
- '*.md'
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Set up JDK 21
30+
uses: actions/setup-java@v4
31+
with:
32+
java-version: '21'
33+
distribution: 'temurin'
34+
35+
- name: Build and deploy to Maven Central
36+
run: .github/scripts/deploy.sh snapshot
37+
env:
38+
MAVEN_USERNAME: ${{ vars.MAVEN_USERNAME }}
39+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
40+
MAVEN_GPG_KEY: ${{ secrets.SDK_ROBOT_GPG_PRIVATE_KEY }}
41+
MAVEN_GPG_PASSPHRASE: ''

deploy-settings.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- This is a Maven settings.xml file for publishing to Maven Central
2+
using credentials stored in environment variables. -->
3+
<settings>
4+
<servers>
5+
<server>
6+
<id>central</id>
7+
<username>${env.MAVEN_USERNAME}</username>
8+
<password>${env.MAVEN_PASSWORD}</password>
9+
</server>
10+
</servers>
11+
</settings>

pom.xml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@
253253
<autoReleaseAfterClose>true</autoReleaseAfterClose>
254254
</configuration>
255255
</plugin>
256+
<plugin>
257+
<groupId>org.apache.maven.plugins</groupId>
258+
<artifactId>maven-enforcer-plugin</artifactId>
259+
<version>3.5.0</version>
260+
</plugin>
256261
</plugins>
257262
</pluginManagement>
258263

@@ -360,6 +365,34 @@
360365
<executable>java</executable>
361366
</configuration>
362367
</plugin>
368+
369+
<!-- Require profile `snapshot` or `release` when deploying.
370+
Having explicit profiles (instead of relying on deploy plugin's
371+
automatic snapshot/release routing) prevents the "on push"
372+
snapshot publish action from accidentally publishing a release version. -->
373+
<plugin>
374+
<groupId>org.apache.maven.plugins</groupId>
375+
<artifactId>maven-enforcer-plugin</artifactId>
376+
<executions>
377+
<execution>
378+
<id>enforce-deploy-has-active-profile</id>
379+
<phase>deploy</phase>
380+
<goals>
381+
<goal>enforce</goal>
382+
</goals>
383+
<configuration>
384+
<rules>
385+
<requireProfileIdsExist/>
386+
<requireActiveProfile>
387+
<profiles>snapshot,release</profiles>
388+
<all>false</all>
389+
</requireActiveProfile>
390+
</rules>
391+
<fail>true</fail>
392+
</configuration>
393+
</execution>
394+
</executions>
395+
</plugin>
363396
</plugins>
364397
</build>
365398

@@ -416,6 +449,56 @@
416449
</execution>
417450
</executions>
418451
</plugin>
452+
<plugin>
453+
<groupId>org.apache.maven.plugins</groupId>
454+
<artifactId>maven-enforcer-plugin</artifactId>
455+
<executions>
456+
<execution>
457+
<id>enforce-release</id>
458+
<goals>
459+
<goal>enforce</goal>
460+
</goals>
461+
<configuration>
462+
<rules>
463+
<requireReleaseVersion>
464+
<message>Not a release version (remove -SNAPSHOT suffix!)</message>
465+
</requireReleaseVersion>
466+
<requireReleaseDeps>
467+
<message>Can't release with snapshot dependencies!</message>
468+
</requireReleaseDeps>
469+
</rules>
470+
<fail>true</fail>
471+
</configuration>
472+
</execution>
473+
</executions>
474+
</plugin>
475+
</plugins>
476+
</build>
477+
</profile>
478+
<profile>
479+
<id>snapshot</id>
480+
<build>
481+
<plugins>
482+
<plugin>
483+
<groupId>org.apache.maven.plugins</groupId>
484+
<artifactId>maven-enforcer-plugin</artifactId>
485+
<executions>
486+
<execution>
487+
<id>enforce-snapshot</id>
488+
<goals>
489+
<goal>enforce</goal>
490+
</goals>
491+
<configuration>
492+
<rules>
493+
<requireSnapshotVersion>
494+
<message>Not a SNAPSHOT version!</message>
495+
</requireSnapshotVersion>
496+
</rules>
497+
<fail>true</fail>
498+
</configuration>
499+
</execution>
500+
</executions>
501+
</plugin>
419502
</plugins>
420503
</build>
421504
</profile>

0 commit comments

Comments
 (0)