Skip to content

Commit fb45677

Browse files
flatten poms and deploy snapshots (#32)
This pull request includes significant changes to the build and release workflows, transitioning from Maven to Gradle, and refactoring the GitHub Actions workflows to use reusable workflows. With Gradle we can simplify our build configuration by using [shared build logic](https://docs.gradle.org/current/samples/sample_convention_plugins.html) and apply publishing to the projects that need it. Gradle also handles the complexity of resolving dependencies to a pom that makes sense by default which has been causing problems since we migrated to submodules. We also removed the concept of a stand-alone `jdbc-proto` project entirely and now publish it with a "proto" classifier under `jdbc-grpc`. Once we publish we'll have a set of jars that look like this: ``` Project: jdbc - jdbc-0.25.7-shaded.jar - jdbc-0.25.7.jar - jdbc-0.25.7-javadoc.jar - jdbc-0.25.7-sources.jar Project: jdbc-core - jdbc-core-0.25.7-javadoc.jar - jdbc-core-0.25.7.jar - jdbc-core-0.25.7-sources.jar Project: jdbc-grpc - jdbc-grpc-0.25.7-proto.jar - jdbc-grpc-0.25.7.jar - jdbc-grpc-0.25.7-javadoc.jar - jdbc-grpc-0.25.7-sources.jar ```
1 parent 3bc850a commit fb45677

File tree

57 files changed

+1365
-1641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1365
-1641
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
* text=auto eol=lf
22
*.java text diff=java
3+
gradle.bat text eol=crlf

.github/workflows/build.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

.github/workflows/pr.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Build and test pull request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
call-reusable-workflow:
10+
uses: './.github/workflows/reusable-build-publish.yml'
11+
with:
12+
publish: false

.github/workflows/release.yml

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,18 @@
1-
name: Release to staging
1+
name: Build, test, and release tag
22

33
on:
44
release:
55
types: [ "created" ]
66

7-
env:
8-
MAVEN_ARGS: --batch-mode --no-transfer-progress -V -e -Dstyle.color=always
9-
107
jobs:
11-
release:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v4
15-
- name: Set up JDK 8
16-
uses: actions/setup-java@v4
17-
with:
18-
java-version: '8'
19-
distribution: 'temurin'
20-
server-id: ossrh
21-
server-username: 'MAVEN_USERNAME'
22-
server-password: 'MAVEN_PASSWORD'
23-
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }}
24-
gpg-passphrase: 'MAVEN_GPG_PASSPHRASE'
25-
- name: Get hyperd version
26-
id: evaluate-property
27-
run: |
28-
HYPER_VERSION=$(grep "<hyperapi.version>" pom.xml | sed -n 's/.*<hyperapi.version>\(.*\)<\/hyperapi.version>.*/\1/p')
29-
echo "HYPER_VERSION=$HYPER_VERSION" >> $GITHUB_ENV
30-
- name: Cache hyperd
31-
uses: actions/cache@v3
32-
with:
33-
path: |
34-
target/.cache
35-
key: ${{ runner.os }}-hyper-${{ env.HYPER_VERSION }}
36-
restore-keys: |
37-
${{ runner.os }}-hyper-${{ env.HYPER_VERSION }}
38-
- name: Set version
39-
run: mvn $MAVEN_ARGS versions:set -DnewVersion=${{ github.event.release.tag_name }}
40-
- name: Deploy with Maven
41-
run: mvn $MAVEN_ARGS clean deploy -Prelease --file pom.xml
42-
env:
43-
MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
44-
MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
45-
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
8+
call-reusable-workflow:
9+
uses: './.github/workflows/reusable-build-publish.yml'
10+
with:
11+
publish: true
12+
version: ${{ github.event.release.tag_name }}
13+
secrets:
14+
signing_key: ${{ secrets.GPG_SIGNING_KEY }}
15+
signing_pass: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
16+
publish_user: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
17+
publish_pass: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
18+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Reusable Build and Publish
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
publish:
7+
required: true
8+
type: boolean
9+
description: 'Whether to publish or not'
10+
version:
11+
required: false
12+
type: string
13+
description: 'Version to publish (tag name or snapshot)'
14+
default: ''
15+
secrets:
16+
signing_pass:
17+
required: false
18+
signing_key:
19+
required: false
20+
publish_user:
21+
required: false
22+
publish_pass:
23+
required: false
24+
25+
jobs:
26+
build-and-publish:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- name: Setup Java with 8 and 17 toolchains
31+
uses: actions/setup-java@v4
32+
with:
33+
distribution: 'temurin'
34+
java-version: |
35+
8
36+
17
37+
- name: Get hyperd version
38+
run: |
39+
HYPER_VERSION=$(sed -n 's/^hyperApiVersion=\(.*\)/\1/p' gradle.properties)
40+
echo "HYPER_VERSION=$HYPER_VERSION" >> $GITHUB_ENV
41+
- name: Cache hyperd zip
42+
uses: actions/cache@v3
43+
with:
44+
path: build/hyper-${{ env.HYPER_VERSION }}.zip
45+
key: ${{ runner.os }}-hyper-${{ env.HYPER_VERSION }}
46+
restore-keys: ${{ runner.os }}-hyper-${{ env.HYPER_VERSION }}
47+
- name: Setup Gradle
48+
uses: gradle/actions/setup-gradle@v4
49+
with:
50+
dependency-graph: generate-and-submit
51+
build-scan-publish: true
52+
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
53+
build-scan-terms-of-use-agree: "yes"
54+
gradle-version: "8.12"
55+
- name: Gradle build
56+
id: build
57+
run: gradle clean build
58+
- name: Publish on release
59+
id: publish
60+
if: ${{ inputs.publish && (success() || steps.build.outcome == 'success') }}
61+
env:
62+
RELEASE_VERSION: ${{ inputs.version }}
63+
OSSRH_USERNAME: ${{ secrets.publish_user }}
64+
OSSRH_PASSWORD: ${{ secrets.publish_pass }}
65+
# https://docs.gradle.org/current/userguide/signing_plugin.html#sec:in-memory-keys
66+
# https://central.sonatype.org/publish/requirements/gpg/#generating-a-key-pair
67+
# gpg --export-secret-key --armor <key id> | pbcopy
68+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.signing_key }}
69+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.signing_pass }}
70+
run: gradle publishAllPublicationsToMavenCentralRepository --no-scan --no-configuration-cache
71+
- name: Upload hyper logs on failure
72+
if: ${{ failure() || steps.build.outcome == 'failure' || steps.publish.outcome == 'failure' }}
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: test-results
76+
path: |
77+
build/hyperd/*.log
78+
retention-days: 5

.github/workflows/snapshot.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Build, test, and publish main as snapshot
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
call-reusable-workflow:
10+
uses: './.github/workflows/reusable-build-publish.yml'
11+
with:
12+
publish: true
13+
secrets:
14+
signing_key: ${{ secrets.GPG_SIGNING_KEY }}
15+
signing_pass: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
16+
publish_user: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
17+
publish_pass: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
18+

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ buildNumber.properties
1818
.classpath
1919
jdbc-driver/src/main/resources/config/config.properties
2020
.flattened-pom.xml
21+
build
2122

2223
*.iml
2324
pom.xml.bak
2425
.codegenie
2526

26-
.vscode
27+
.vscode
28+
.gradle
29+
.hyper
30+
.kotlin

.hooks/pre-commit

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/usr/bin/env bash
2-
set -e
1+
!/usr/bin/env bash
2+
#set -e
33

4-
echo '[git pre-commit] mvn spotless:apply sortpom:sort'
5-
MAVEN_OPTS='-Dorg.slf4j.simpleLogger.defaultLogLevel=error' mvn spotless:apply sortpom:sort
6-
7-
staged_files=$(git diff --name-only --cached)
8-
for file in $staged_files; do
9-
git add "$file"
10-
done
4+
#echo '[git pre-commit] mvn spotless:apply sortpom:sort'
5+
#MAVEN_OPTS='-Dorg.slf4j.simpleLogger.defaultLogLevel=error' mvn spotless:apply sortpom:sort
6+
#
7+
#staged_files=$(git diff --name-only --cached)
8+
#for file in $staged_files; do
9+
# git add "$file"
10+
#done

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ com.salesforce.datacloud.jdbc.DataCloudJDBCDriver
2727
Use the following command to build and test the driver:
2828

2929
```shell
30-
mvn clean install
30+
./gradlew clean build
31+
```
32+
33+
To inspect the jars that will be published run and take a look in `build/maven-repo`:
34+
35+
```shell
36+
./gradlew build publishAllPublicationsToRootBuildDirRepository
3137
```
3238

3339
## Usage

build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id("hyper-conventions")
3+
id("base-conventions")
4+
id("com.diffplug.spotless")
5+
}
6+
7+
subprojects {
8+
plugins.withId("java-conventions") {
9+
tasks.withType<Test>().configureEach {
10+
dependsOn(rootProject.tasks.named("extractHyper"))
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)