Skip to content

Migrate Maven Central deployment #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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: 11

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

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

- name: Publish to Maven Central
if: ${{ !inputs.skip-deploy-maven-central }}
run: |
./gradlew jreleaserConfig
./gradlew publish --info --warning-mode all
./gradlew jreleaserFullRelease --info --warning-mode all
env:
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.CENTRAL_PORTAL_USERNAME }}
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.CENTRAL_PORTAL_TOKEN }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.OSSRH_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
JRELEASER_DRY_RUN: true

- name: Create GitHub Release
run: ./.github/workflows/github_release.sh
env:
GH_TOKEN: ${{ github.token }}
34 changes: 34 additions & 0 deletions .github/workflows/github_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/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
readonly build_dir="$base_dir/build"
readonly release_artifacts_dir="$build_dir/release-artifacts"

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"

mkdir -p "$release_artifacts_dir"
cp -v "$build_dir/libs/fritzbox-java-api-$project_version.jar" "$release_artifacts_dir/fritzbox-java-api-$project_version.jar"

release_artifacts=$(find "$release_artifacts_dir" -type f)
readonly release_artifacts

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

# shellcheck disable=SC2086
release_url=$(gh release create --latest --title "$title" --target main "$tag" $release_artifacts)
readonly release_url
echo "Release URL: $release_url"
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.8.0] - unreleased

## [1.7.1] - 2025-05-09

- [#65](https://github.com/kaklakariada/fritzbox-java-api/pull/65) Upgrade dependencies
- [#67](https://github.com/kaklakariada/fritzbox-java-api/pull/67) Upgrade dependencies, migrate Maven Central deployment

## [1.7.0] - 2023-10-07

Expand Down
36 changes: 12 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,20 @@ Install to local maven repository:
./gradlew clean publishToMavenLocal
```

### Publish to Maven Central
### Creating a Release

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

```properties
ossrhUsername=<your maven central username>
ossrhPassword=<your maven central passwort>
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`.

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
```

4. Run the following command to publish to Maven Central:

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

5. Create a new [release](https://github.com/kaklakariada/fritzbox-java-api/releases) on GitHub.
1. Start the release workflow
* Run command `gh workflow run release.yml --repo kaklakariada/fritzbox-java-api --ref main`
* or go to [GitHub Actions](https://github.com/kaklakariada/fritzbox-java-api/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/kaklakariada/fritzbox-java-api/releases).
6. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/com/github/kaklakariada/fritzbox-java-api/).
53 changes: 24 additions & 29 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
plugins {
id "java-library"
id "signing"
id "maven-publish"
id "jacoco"
id "com.github.hierynomus.license" version "0.16.1"
id "org.sonarqube" version "6.0.1.5171"
id "io.github.gradle-nexus.publish-plugin" version "2.0.0"
id "com.github.ben-manes.versions" version "0.51.0"
id "org.sonatype.gradle.plugins.scan" version "2.8.3"
id "org.sonarqube" version "6.1.0.5360"
id "org.jreleaser" version "1.18.0"
id "com.github.ben-manes.versions" version "0.52.0"
id "org.sonatype.gradle.plugins.scan" version "3.1.0"
}

group = 'com.github.kaklakariada'
version = '1.7.0'
version = '1.7.1'

java {
toolchain {
Expand Down Expand Up @@ -43,12 +42,12 @@ testing {
dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.subshell.simpleframework:simple-xml:2.9.0'
implementation 'org.slf4j:slf4j-api:2.0.16'
implementation 'org.slf4j:slf4j-api:2.0.17'

testRuntimeOnly 'ch.qos.logback:logback-classic:1.5.15'
testRuntimeOnly 'ch.qos.logback:logback-classic:1.5.18'

testImplementation 'org.mockito:mockito-core:5.14.2'
testImplementation 'org.assertj:assertj-core:3.27.0'
testImplementation 'org.mockito:mockito-core:5.17.0'
testImplementation 'org.assertj:assertj-core:3.27.3'
}

license {
Expand Down Expand Up @@ -115,32 +114,28 @@ 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")
}
url = layout.buildDirectory.dir('staging-deploy')
}
}
}


signing {
sign publishing.publications.mavenJava
}

nexusPublishing {
packageGroup = project.group
repositories {
jreleaser {
signing {
active = 'ALWAYS'
armored = true
verify = true
}
deploy {
maven {
mavenCentral {
sonatype {
stagingProfileId = "4f1b95618be44"
username = getOptionalProperty("ossrhUsername")
password = getOptionalProperty("ossrhPassword")
active = 'ALWAYS'
url = 'https://central.sonatype.com/api/v1/publisher'
stagingRepository('build/staging-deploy')
}
}
}
}
}

def isNonStable = { String version ->
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.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
CLASSPATH="\\\"\\\""


# Determine the Java command to use to start the JVM.
Expand Down Expand Up @@ -205,15 +205,15 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

# Stop when "xargs" is not available.
Expand Down
4 changes: 2 additions & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ goto fail
:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
set CLASSPATH=


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down