Skip to content

Commit 12e309e

Browse files
authored
feat(java): release process APIC-411 (#411)
1 parent ca7c6cf commit 12e309e

File tree

12 files changed

+118
-45
lines changed

12 files changed

+118
-45
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish jar
2+
3+
on:
4+
push:
5+
branches:
6+
- next
7+
8+
jobs:
9+
release:
10+
name: Publish to Sonatype
11+
runs-on: ubuntu-20.04
12+
if: "startsWith(github.event.head_commit.message, 'chore: release v')"
13+
env:
14+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
15+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
16+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }}
17+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_PRIVATE_KEY_ID }}
18+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PRIVATE_KEY_PASSWORD }}
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Install Java
23+
uses: actions/setup-java@v2
24+
with:
25+
distribution: zulu
26+
java-version: 11.0.4
27+
cache: gradle
28+
29+
- name: Validate gradle wrapper
30+
uses: gradle/wrapper-validation-action@v1
31+
32+
- name: Upload Artifacts
33+
run: ./gradlew clean publish --no-parallel --stacktrace
34+
35+
- name: Release Artifacts
36+
if: ! cat ./gradle.properties | grep 'VERSION_NAME=.*-SNAPSHOT'
37+
run: ./gradlew closeAndReleaseRepository

clients/algoliasearch-client-java-2/.openapi-generator-ignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66

77
api/**
88
docs/**
9-
gradle/**
109
src/**
1110
README.md
1211

1312
.travis.yml
1413
build.sbt
15-
gradle.properties
1614
git_push.sh
1715
pom.xml
18-
gradle*
16+
gradlew.bat
1917

2018
# Selective source file
2119
algoliasearch-core/src/com/algolia/auth/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id 'java-library'
3+
id 'com.vanniktech.maven.publish'
4+
}
5+
6+
description = 'algoliasearch-client-java-2'
7+
java.sourceCompatibility = JavaVersion.VERSION_1_8
8+
9+
repositories {
10+
mavenCentral()
11+
}
12+
13+
dependencies {
14+
implementation 'com.google.code.findbugs:jsr305:3.0.2'
15+
api 'com.squareup.okhttp3:okhttp:4.9.1'
16+
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'
17+
api 'com.google.code.gson:gson:2.8.9'
18+
implementation 'io.gsonfire:gson-fire:1.8.5'
19+
}
20+
21+
tasks.withType(JavaCompile) {
22+
options.encoding = 'UTF-8'
23+
}
285 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

templates/java/build.gradle.mustache

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,8 @@
1-
plugins {
2-
id 'java-library'
3-
id 'maven-publish'
4-
}
5-
6-
group = '{{groupId}}'
7-
version = '{{artifactVersion}}'
8-
description = 'algoliasearch-client-java-2'
9-
java.sourceCompatibility = JavaVersion.VERSION_1_8
10-
11-
repositories {
1+
buildscript {
2+
repositories {
123
mavenCentral()
13-
}
14-
15-
dependencies {
16-
implementation 'com.google.code.findbugs:jsr305:3.0.2'
17-
api 'com.squareup.okhttp3:okhttp:4.9.1'
18-
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'
19-
api 'com.google.code.gson:gson:2.8.9'
20-
implementation 'io.gsonfire:gson-fire:1.8.5'
21-
}
22-
23-
publishing {
24-
publications {
25-
maven(MavenPublication) {
26-
from(components.java)
27-
}
28-
}
29-
}
30-
31-
tasks.withType(JavaCompile) {
32-
options.encoding = 'UTF-8'
33-
}
34-
35-
sourceSets {
36-
main {
37-
java {
38-
srcDirs = ["{{{sourceFolder}}}"]
39-
}
40-
}
4+
}
5+
dependencies {
6+
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.19.0'
7+
}
418
}

templates/java/gitignore.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
.mtj.tmp/
55

66
# Package Files #
7-
*.jar
87
*.war
98
*.ear
109

58.4 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GROUP={{groupId}}
2+
VERSION_NAME={{artifactVersion}}-SNAPSHOT
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
rootProject.name = "{{artifactId}}"
1+
rootProject.name = "{{artifactId}}"
2+
3+
include(":algoliasearch-core")

website/docs/releaseProcess.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,43 @@ The [GitHub action release](https://github.com/algolia/api-clients-automation/bl
3838
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>`.
3939

4040
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.
41+
42+
## Releasing manually
43+
44+
### Java
45+
46+
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.
47+
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).
48+
If you want to release manually, you need to copy some secrets to either:
49+
- `clients/algoliasearch-client-java-2/gradle.properties` /!\ make sure to remove them before committing !
50+
- `~/.gradle/gradle.properties` which is safer because it's not committed and can stay on your computer.
51+
52+
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):
53+
```bash
54+
signingInMemoryKey="$(vault read -field sub_private_key secret/algolia/api-clients-squad/maven-signing | awk 'NR == 1 { } 1' ORS='\\n')"
55+
signingInMemoryKeyId=$(vault read -field subkey_id secret/algolia/api-clients-squad/maven-signing)
56+
signingInMemoryKeyPassword=$(vault read -field password secret/algolia/api-clients-squad/maven-signing)
57+
58+
mavenCentralUsername=$(vault read -field user secret/algolia/api-clients-squad/sonatype)
59+
mavenCentralPassword=$(vault read -field password secret/algolia/api-clients-squad/sonatype)
60+
```
61+
62+
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:
63+
` ./gradle/gradlew -p clients/algoliasearch-client-java-2 --no-parallel publish`
64+
65+
And if it's not a snapshot, run:
66+
` ./gradle/gradlew -p clients/algoliasearch-client-java-2 closeAndReleaseRepository`
67+
68+
Once the package is published, it can be used in gradle file as:
69+
```gradle
70+
repositories {
71+
mavenCentral()
72+
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
73+
}
74+
75+
dependencies {
76+
implementation 'com.algolia:algoliasearch-core:0.0.1-SNAPSHOT'
77+
}
78+
```
79+
80+
If it's not a snapshot, you can ignore the sonatype repository.

0 commit comments

Comments
 (0)