Skip to content

Commit 3d2456b

Browse files
committed
ci: java sdk management
1 parent 3e5f50d commit 3d2456b

File tree

6 files changed

+137
-10
lines changed

6 files changed

+137
-10
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright 2025 Alibaba Group Holding Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Publish Java SDKs
16+
17+
on:
18+
push:
19+
tags:
20+
- "java/sandbox/v*"
21+
- "java/code-interpreter/v*"
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
publish-sandbox:
28+
if: startsWith(github.ref, 'refs/tags/java/sandbox/v')
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Set up Java
35+
uses: actions/setup-java@v4
36+
with:
37+
distribution: temurin
38+
java-version: "17"
39+
40+
- name: Set up Gradle
41+
uses: gradle/actions/setup-gradle@v4
42+
43+
- name: Publish to Maven Central
44+
working-directory: sdks/sandbox/kotlin
45+
env:
46+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALUSERNAME }}
47+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALPASSWORD }}
48+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEY }}
49+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEYPASSWORD }}
50+
run: |
51+
./gradlew publishToMavenCentral
52+
53+
publish-code-interpreter:
54+
if: startsWith(github.ref, 'refs/tags/java/code-interpreter/v')
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Checkout code
58+
uses: actions/checkout@v4
59+
60+
- name: Set up Java
61+
uses: actions/setup-java@v4
62+
with:
63+
distribution: temurin
64+
java-version: "17"
65+
66+
- name: Set up Gradle
67+
uses: gradle/actions/setup-gradle@v4
68+
69+
- name: Publish to Maven Central
70+
working-directory: sdks/code-interpreter/kotlin
71+
env:
72+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALUSERNAME }}
73+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALPASSWORD }}
74+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEY }}
75+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEYPASSWORD }}
76+
run: |
77+
./gradlew publishToMavenCentral

sdks/code-interpreter/kotlin/build.gradle.kts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818

1919
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
2020

21+
fun Project.resolveVersionFromTag(expectedTagPrefix: String): String? {
22+
val refName = System.getenv("GITHUB_REF_NAME") ?: System.getenv("GITHUB_REF")?.removePrefix("refs/tags/")
23+
val fromEnv =
24+
refName
25+
?.trim()
26+
?.takeIf { it.startsWith(expectedTagPrefix) }
27+
?.removePrefix(expectedTagPrefix)
28+
?.trim()
29+
?.takeIf { it.isNotEmpty() }
30+
return fromEnv
31+
}
32+
2133
buildscript {
2234
repositories {
2335
mavenCentral()
@@ -37,9 +49,17 @@ plugins {
3749
alias(libs.plugins.mavenPublish) apply false
3850
}
3951

52+
val defaultProjectVersion = project.findProperty("project.version") as String
53+
val resolvedProjectVersion =
54+
project.resolveVersionFromTag(
55+
expectedTagPrefix = "java/code-interpreter/v",
56+
) ?: defaultProjectVersion
57+
58+
extra["project.version"] = resolvedProjectVersion
59+
4060
allprojects {
4161
group = project.findProperty("project.group") as String
42-
version = project.findProperty("project.version") as String
62+
version = resolvedProjectVersion
4363

4464
repositories {
4565
mavenCentral()

sdks/code-interpreter/kotlin/code-interpreter/build.gradle.kts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ repositories {
2020
}
2121
mavenCentral()
2222

23-
val sandboxVersion =
24-
(project.findProperty("sandbox.version") as String?) ?: project.version.toString()
23+
val sandboxVersion = libs.versions.sandbox.get()
2524
if (sandboxVersion.contains("SNAPSHOT", ignoreCase = true)) {
2625
maven {
2726
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
@@ -33,9 +32,8 @@ repositories {
3332
}
3433

3534
dependencies {
36-
val sandboxVersion = (project.findProperty("sandbox.version") as String)
37-
api("com.alibaba.opensandbox:sandbox:$sandboxVersion")
38-
implementation("com.alibaba.opensandbox:sandbox-api:$sandboxVersion")
35+
api(libs.sandbox)
36+
implementation(libs.sandbox.api)
3937

4038
api(libs.kotlin.stdlib)
4139
api(libs.slf4j.api)

sdks/code-interpreter/kotlin/gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ org.gradle.parallel=true
66
# Project metadata
77
project.group=com.alibaba.opensandbox
88
project.version=1.0.0-SNAPSHOT
9-
sandbox.version=1.0.0-SNAPSHOT
109
project.description=A Kotlin SDK for Code Interpreter

sdks/sandbox/kotlin/build.gradle.kts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818

1919
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
2020

21+
fun Project.resolveVersionFromTag(expectedTagPrefix: String): String? {
22+
val refName = System.getenv("GITHUB_REF_NAME") ?: System.getenv("GITHUB_REF")?.removePrefix("refs/tags/")
23+
val fromEnv =
24+
refName
25+
?.trim()
26+
?.takeIf { it.startsWith(expectedTagPrefix) }
27+
?.removePrefix(expectedTagPrefix)
28+
?.trim()
29+
?.takeIf { it.isNotEmpty() }
30+
return fromEnv
31+
}
32+
2133
buildscript {
2234
repositories {
2335
mavenCentral()
@@ -37,9 +49,17 @@ plugins {
3749
alias(libs.plugins.mavenPublish) apply false
3850
}
3951

52+
val defaultProjectVersion = project.findProperty("project.version") as String
53+
val resolvedProjectVersion =
54+
project.resolveVersionFromTag(
55+
expectedTagPrefix = "java/sandbox/v",
56+
) ?: defaultProjectVersion
57+
58+
extra["project.version"] = resolvedProjectVersion
59+
4060
allprojects {
4161
group = project.findProperty("project.group") as String
42-
version = project.findProperty("project.version") as String
62+
version = resolvedProjectVersion
4363

4464
repositories {
4565
mavenCentral()

tests/java/build.gradle.kts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,26 @@ java {
2929

3030
repositories {
3131
mavenLocal()
32+
exclusiveContent {
33+
forRepository {
34+
mavenLocal()
35+
}
36+
filter {
37+
includeGroup("com.alibaba.opensandbox")
38+
}
39+
}
3240
mavenCentral()
3341
}
3442

43+
configurations.configureEach {
44+
resolutionStrategy.cacheDynamicVersionsFor(0, "seconds")
45+
resolutionStrategy.cacheChangingModulesFor(0, "seconds")
46+
}
47+
3548
dependencies {
3649
// OpenSandbox Kotlin SDKs
37-
testImplementation("com.alibaba.opensandbox:sandbox:1.0.0-SNAPSHOT")
38-
testImplementation("com.alibaba.opensandbox:code-interpreter:1.0.0-SNAPSHOT")
50+
testImplementation("com.alibaba.opensandbox:sandbox:latest.integration")
51+
testImplementation("com.alibaba.opensandbox:code-interpreter:latest.integration")
3952

4053
// Test frameworks
4154
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")

0 commit comments

Comments
 (0)