Skip to content

Commit

Permalink
Update dependencies (#26)
Browse files Browse the repository at this point in the history
* Upgrade gradle

* Upgrade dependencies

* Configure automatic release

* Fix sonar warnings

* Run integration tests during CI build

* Increment version

---------

Co-authored-by: kaklakariada <[email protected]>
  • Loading branch information
kaklakariada and kaklakariada authored Sep 1, 2024
1 parent cedb247 commit bd690a1
Show file tree
Hide file tree
Showing 35 changed files with 276 additions and 167 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,28 @@ jobs:
key: ${{ runner.os }}-sonar-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-sonar-

- uses: gradle/actions/wrapper-validation@v3

- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
cache: 'gradle'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Enable testcontainer reuse
run: echo 'testcontainers.reuse.enable=true' > "$HOME/.testcontainers.properties"

- name: Build with Java ${{ matrix.java }}
run: |
./gradlew clean build --info \
--exclude-task integrationTest \
-PjavaVersion=${{matrix.java}}
- name: Build with Java ${{ matrix.java }} without integration tests
run: ./gradlew clean build --info --exclude-task integrationTest -PjavaVersion=${{matrix.java}}

- name: Build with Java ${{ matrix.java }} with integration tests
if: ${{ env.DEFAULT_JAVA == matrix.java }}
run: ./gradlew clean build --info -PjavaVersion=${{matrix.java}}

- name: Sonar analysis
if: ${{ env.DEFAULT_JAVA == matrix.java && env.SONAR_TOKEN != null }}
run: |
./gradlew sonar --info \
--exclude-task integrationTest \
-Dsonar.token=$SONAR_TOKEN
run: ./gradlew sonar --info --exclude-task integrationTest -Dsonar.token=$SONAR_TOKEN
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ jobs:
with:
distribution: 'temurin'
java-version: 17
cache: 'gradle'

- uses: gradle/actions/wrapper-validation@v3
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/github_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

base_dir="$( cd "$(dirname "$0")/../.." >/dev/null 2>&1 ; pwd -P )"
readonly base_dir

cd "$base_dir"
echo "Reading project version from Gradle project at ${base_dir}..."
project_version=$(./gradlew properties --console=plain --quiet | grep "^version:" | awk '{print $2}')
readonly project_version
echo "Read project version '$project_version' from Gradle project"

readonly title="Release $project_version"
readonly tag="$project_version"
echo "Creating release:"
echo "Git tag : $tag"
echo "Title : $title"

release_url=$(gh release create --latest --title "$title" --target main "$tag")
readonly release_url
echo "Release URL: $release_url"
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

on:
workflow_dispatch:
inputs:
skip-deploy-maven-central:
description: "Skip deployment to Maven Central"
required: true
type: boolean
default: false

jobs:
release:
runs-on: ubuntu-latest
defaults:
run:
shell: "bash"
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
contents: write # Required for creating GitHub release
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Fail if not running on main branch
if: ${{ github.ref != 'refs/heads/main' }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('Not running on main branch, github.ref is ${{ github.ref }}. Please start this workflow only on main')
- uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 17

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Build
run: ./gradlew build --warning-mode all

- name: Publish to Maven Central
if: ${{ !inputs.skip-deploy-maven-central }}
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --warning-mode all
env:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.OSSRH_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}

- name: Create GitHub Release
run: ./.github/workflows/github_release.sh
env:
GH_TOKEN: ${{ github.token }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.8.0] - unreleased

## [0.7.1] - 2024-09-01

- [PR #26](https://github.com/itsallcode/simple-jdbc/pull/26): Update dependencies

## [0.7.0] - 2024-05-04

- [PR #22](https://github.com/itsallcode/simple-jdbc/pull/22): Added `module-info.java`
Expand Down
45 changes: 21 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,24 @@ Add dependency to your gradle project:

```groovy
dependencies {
implementation 'org.itsallcode:simple-jdbc:0.7.0'
implementation 'org.itsallcode:simple-jdbc:0.7.1'
}
```

```java

// Define a model record or class
record Name(int id, String name) {
Object[] toRow() {
return new Object[] { id, name };
}
}

import org.itsallcode.jdbc.ConnectionFactory;
import org.itsallcode.jdbc.SimpleConnection;
import org.itsallcode.jdbc.resultset.SimpleResultSet;

// Execute query and fetch result
ConnectionFactory connectionFactory = ConnectionFactory.create();
try (SimpleConnection connection = connectionFactory.create("jdbc:h2:mem:", "user", "password")) {
connection.executeScript(readResource("/schema.sql"));
Expand All @@ -46,6 +53,7 @@ try (SimpleConnection connection = connectionFactory.create("jdbc:h2:mem:", "use
}
}
```

## Development

### Check if dependencies are up-to-date
Expand Down Expand Up @@ -73,29 +81,18 @@ open build/reports/jacoco/test/html/index.html

### Publish to Maven Central

1. Add the following to your `~/.gradle/gradle.properties`:

```properties
ossrhUsername=<your maven central username>
ossrhPassword=<your maven central passwort>

signing.keyId=<gpg key id (last 8 chars)>
signing.password=<gpg key password>
signing.secretKeyRingFile=<path to secret keyring file>
```

2. Increment version number in `build.gradle` and `README.md`, update [CHANGELOG.md](CHANGELOG.md), commit and push.
3. Optional: run the following command to do a dry-run:

```sh
./gradlew clean check build publishToSonatype closeSonatypeStagingRepository --info
```
#### Preparations

4. Run the following command to publish to Maven Central:
1. Checkout the `main` branch, create a new branch.
2. Update version number in `build.gradle` and `README.md`.
3. Add changes in new version to `CHANGELOG.md`.
4. Commit and push changes.
5. Create a new pull request, have it reviewed and merged to `main`.

```sh
./gradlew clean check build publishToSonatype closeAndReleaseSonatypeStagingRepository --info
```
#### Perform the Release

5. Create a new [release](https://github.com/itsallcode/simple-jdbc/releases) on GitHub.
6. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/org/itsallcode/simple-jdbc/).
1. Start the release workflow
* Run command `gh workflow run release.yml --repo itsallcode/simple-jdbc --ref main`
* or go to [GitHub Actions](https://github.com/itsallcode/simple-jdbc/actions/workflows/release.yml) and start the `release.yml` workflow on branch `main`.
2. Update title and description of the newly created [GitHub release](https://github.com/itsallcode/simple-jdbc/releases).
3. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/org/itsallcode/simple-jdbc/).
49 changes: 12 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ plugins {
id 'jacoco-report-aggregation'
id 'signing'
id 'maven-publish'
id 'org.sonarqube' version '5.0.0.4638'
id 'org.sonarqube' version '5.1.0.4882'
id "io.github.gradle-nexus.publish-plugin" version "2.0.0"
id 'com.github.ben-manes.versions' version '0.51.0'
}

group 'org.itsallcode'
version = '0.7.0'
version = '0.7.1'

dependencies {
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(getPropertyWithDefault('javaVersion', '17'))
def javaVersion = project.hasProperty('javaVersion') ? project.getProperty('javaVersion') : 17
languageVersion = JavaLanguageVersion.of(javaVersion)
}
withJavadocJar()
withSourcesJar()
Expand All @@ -39,7 +40,7 @@ tasks.withType(JavaCompile) {
testing {
suites {
configureEach {
useJUnitJupiter('5.10.1')
useJUnitJupiter()
dependencies {
implementation project()
implementation libs.assertj
Expand Down Expand Up @@ -93,6 +94,10 @@ jacocoTestReport {
}
}

test {
finalizedBy jacocoTestReport
}

sonar {
properties {
property("sonar.organization", "itsallcode")
Expand All @@ -102,24 +107,6 @@ sonar {

rootProject.tasks['sonar'].dependsOn(tasks['testCodeCoverageReport'], tasks['integrationTestCodeCoverageReport'])

def getPropertyWithDefault(String name, String defaultValue) {
if(project.hasProperty(name)) {
def value = project.property(name)
logger.info("Found value '${value}' for project property '${name}'")
return value
}
logger.info("Project property '${name}' not defined, using default '${defaultValue}'")
return defaultValue
}

def getOptionalProperty(String name) {
if(project.hasProperty(name)) {
return project.property(name)
}
logger.info("Project property '${name}' not available. Please it to ~/.gradle/gradle.properties")
return null
}

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down Expand Up @@ -150,22 +137,12 @@ publishing {
}
}
}

repositories {
maven {
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
allowInsecureProtocol = false
credentials(PasswordCredentials) {
username = getOptionalProperty("ossrhUsername")
password = getOptionalProperty("ossrhPassword")
}
}
}
}

signing {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.mavenJava
}

Expand All @@ -174,8 +151,6 @@ nexusPublishing {
repositories {
sonatype {
stagingProfileId = "546ea6ce74787e"
username = getOptionalProperty("ossrhUsername")
password = getOptionalProperty("ossrhPassword")
}
}
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Loading

0 comments on commit bd690a1

Please sign in to comment.