Skip to content

Commit

Permalink
feat(java): release process APIC-411 (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Apr 22, 2022
1 parent ca7c6cf commit 12e309e
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 45 deletions.
37 changes: 37 additions & 0 deletions clients/algoliasearch-client-java-2/.github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish jar

on:
push:
branches:
- next

jobs:
release:
name: Publish to Sonatype
runs-on: ubuntu-20.04
if: "startsWith(github.event.head_commit.message, 'chore: release v')"
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_PRIVATE_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PRIVATE_KEY_PASSWORD }}
steps:
- uses: actions/checkout@v2

- name: Install Java
uses: actions/setup-java@v2
with:
distribution: zulu
java-version: 11.0.4
cache: gradle

- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Upload Artifacts
run: ./gradlew clean publish --no-parallel --stacktrace

- name: Release Artifacts
if: ! cat ./gradle.properties | grep 'VERSION_NAME=.*-SNAPSHOT'
run: ./gradlew closeAndReleaseRepository
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

api/**
docs/**
gradle/**
src/**
README.md

.travis.yml
build.sbt
gradle.properties
git_push.sh
pom.xml
gradle*
gradlew.bat

# Selective source file
algoliasearch-core/src/com/algolia/auth/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id 'java-library'
id 'com.vanniktech.maven.publish'
}

description = 'algoliasearch-client-java-2'
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
mavenCentral()
}

dependencies {
implementation 'com.google.code.findbugs:jsr305:3.0.2'
api 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'
api 'com.google.code.gson:gson:2.8.9'
implementation 'io.gsonfire:gson-fire:1.8.5'
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
Binary file modified gradle/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
45 changes: 6 additions & 39 deletions templates/java/build.gradle.mustache
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
plugins {
id 'java-library'
id 'maven-publish'
}

group = '{{groupId}}'
version = '{{artifactVersion}}'
description = 'algoliasearch-client-java-2'
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
buildscript {
repositories {
mavenCentral()
}

dependencies {
implementation 'com.google.code.findbugs:jsr305:3.0.2'
api 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'
api 'com.google.code.gson:gson:2.8.9'
implementation 'io.gsonfire:gson-fire:1.8.5'
}

publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

sourceSets {
main {
java {
srcDirs = ["{{{sourceFolder}}}"]
}
}
}
dependencies {
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.19.0'
}
}
1 change: 0 additions & 1 deletion templates/java/gitignore.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

Expand Down
Binary file added templates/java/gradle-wrapper.jar.mustache
Binary file not shown.
5 changes: 5 additions & 0 deletions templates/java/gradle-wrapper.properties.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions templates/java/gradle.properties.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GROUP={{groupId}}
VERSION_NAME={{artifactVersion}}-SNAPSHOT
4 changes: 3 additions & 1 deletion templates/java/settings.gradle.mustache
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
rootProject.name = "{{artifactId}}"
rootProject.name = "{{artifactId}}"

include(":algoliasearch-core")
40 changes: 40 additions & 0 deletions website/docs/releaseProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,43 @@ The [GitHub action release](https://github.com/algolia/api-clients-automation/bl
This Part 3 runs conditionally according to what has been done in Part 2. Under "Version Changes" section of the release issue, if a language is checked, this Part 3 will creates a commit like `chore: release v<NEXT-VERSION>` in each repository. If it is not checked, it will create a commit like `chore: update repo <DATE-STAMP>`.

Each language repository should have their own release process, and should run only when the latest commit starts with `chore: release`. By doing so, we have a way to just update the repository, for example READMEs, without having to release.

## Releasing manually

### Java

Java is released to [sonatype](https://oss.sonatype.org/) before being sent to [Maven](https://search.maven.org/artifact/com.algolia/algoliasearch-core) central repository, the `jar` need to be signed before publishing, and then verified on sonatype by using `closeAndRelease` target on Gradle.
All of this is handled in the [release action](https://github.com/algolia/algoliasearch-client-java-2/tree/next/.github/workflows/release.yml), executed on the [Java repository](https://github.com/algolia/algoliasearch-client-java-2).
If you want to release manually, you need to copy some secrets to either:
- `clients/algoliasearch-client-java-2/gradle.properties` /!\ make sure to remove them before committing !
- `~/.gradle/gradle.properties` which is safer because it's not committed and can stay on your computer.

The secrets are fetched from the vault, make sure you have access to `api-clients-squad`, and then read the value and place them in the `gradle.properties` file you want (don't copy this file verbatim):
```bash
signingInMemoryKey="$(vault read -field sub_private_key secret/algolia/api-clients-squad/maven-signing | awk 'NR == 1 { } 1' ORS='\\n')"
signingInMemoryKeyId=$(vault read -field subkey_id secret/algolia/api-clients-squad/maven-signing)
signingInMemoryKeyPassword=$(vault read -field password secret/algolia/api-clients-squad/maven-signing)

mavenCentralUsername=$(vault read -field user secret/algolia/api-clients-squad/sonatype)
mavenCentralPassword=$(vault read -field password secret/algolia/api-clients-squad/sonatype)
```

To release a snapshot, you need to add `-SNAPSHOT` to the `VERSION_NAME` in `clients/algoliasearch-client-java-2/gradle.properties`, then to release run:
` ./gradle/gradlew -p clients/algoliasearch-client-java-2 --no-parallel publish`

And if it's not a snapshot, run:
` ./gradle/gradlew -p clients/algoliasearch-client-java-2 closeAndReleaseRepository`

Once the package is published, it can be used in gradle file as:
```gradle
repositories {
mavenCentral()
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
implementation 'com.algolia:algoliasearch-core:0.0.1-SNAPSHOT'
}
```

If it's not a snapshot, you can ignore the sonatype repository.

0 comments on commit 12e309e

Please sign in to comment.