Skip to content

Commit 34cd161

Browse files
authored
Merge pull request #24 from ninan-nn/ci/publish_java_sdk_workflow
ci: publish java sdk
2 parents 54e666e + 7c50dda commit 34cd161

11 files changed

Lines changed: 148 additions & 35 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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:
28+
name: Publish (${{ matrix.sdk.name }})
29+
if: startsWith(github.ref, format('refs/tags/java/{0}/v', matrix.sdk.tagPrefix))
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
sdk:
35+
- name: sandbox
36+
tagPrefix: sandbox
37+
workingDirectory: sdks/sandbox/kotlin
38+
- name: code-interpreter
39+
tagPrefix: code-interpreter
40+
workingDirectory: sdks/code-interpreter/kotlin
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Set up Java
46+
uses: actions/setup-java@v4
47+
with:
48+
distribution: temurin
49+
java-version: "17"
50+
51+
- name: Set up Gradle
52+
uses: gradle/actions/setup-gradle@v4
53+
54+
- name: Publish to Maven Central
55+
working-directory: ${{ matrix.sdk.workingDirectory }}
56+
env:
57+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALUSERNAME }}
58+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_MAVENCENTRALPASSWORD }}
59+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEY }}
60+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGINMEMORYKEYPASSWORD }}
61+
run: |
62+
./gradlew publishToMavenCentral

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,21 @@
1616

1717
@file:Suppress("UnstableApiUsage")
1818

19+
import org.gradle.api.GradleException
1920
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
2021

22+
fun Project.resolveVersionFromTag(expectedTagPrefix: String): String? {
23+
val refName = System.getenv("GITHUB_REF_NAME") ?: System.getenv("GITHUB_REF")?.removePrefix("refs/tags/")
24+
val fromEnv =
25+
refName
26+
?.trim()
27+
?.takeIf { it.startsWith(expectedTagPrefix) }
28+
?.removePrefix(expectedTagPrefix)
29+
?.trim()
30+
?.takeIf { it.isNotEmpty() }
31+
return fromEnv
32+
}
33+
2134
buildscript {
2235
repositories {
2336
mavenCentral()
@@ -37,9 +50,24 @@ plugins {
3750
alias(libs.plugins.mavenPublish) apply false
3851
}
3952

53+
val manualProjectVersion = project.findProperty("project.version") as String
54+
val tagVersion =
55+
project.resolveVersionFromTag(
56+
expectedTagPrefix = "java/code-interpreter/v",
57+
)
58+
59+
if (tagVersion != null && tagVersion != manualProjectVersion) {
60+
throw GradleException(
61+
"Ref/tag version mismatch: expected version '$manualProjectVersion' from gradle.properties, " +
62+
"but got '$tagVersion' from tag 'java/code-interpreter/v...'. Please align the tag and project.version.",
63+
)
64+
}
65+
66+
extra["project.version"] = manualProjectVersion
67+
4068
allprojects {
4169
group = project.findProperty("project.group") as String
42-
version = project.findProperty("project.version") as String
70+
version = manualProjectVersion
4371

4472
repositories {
4573
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/code-interpreter/src/main/kotlin/com/alibaba/opensandbox/codeinterpreter/domain/services/Codes.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ interface Codes {
4444
*/
4545
fun run(request: RunCodeRequest): Execution
4646

47-
4847
/**
4948
* Executes code within the specified context.
5049
*
@@ -53,11 +52,14 @@ interface Codes {
5352
* @param handlers execution events handlers
5453
* @return Execution with stdout, stderr, exit code, and execution metadata
5554
*/
56-
fun run(code: String, context: CodeContext, handlers: ExecutionHandlers): Execution {
55+
fun run(
56+
code: String,
57+
context: CodeContext,
58+
handlers: ExecutionHandlers,
59+
): Execution {
5760
return run(RunCodeRequest.builder().code(code).context(context).handlers(handlers).build())
5861
}
5962

60-
6163
/**
6264
* Interrupts a currently running code execution.
6365
*

sdks/code-interpreter/kotlin/gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ org.gradle.parallel=true
55

66
# Project metadata
77
project.group=com.alibaba.opensandbox
8-
project.version=1.0.0-SNAPSHOT
9-
sandbox.version=1.0.0-SNAPSHOT
8+
project.version=1.0.0
109
project.description=A Kotlin SDK for Code Interpreter

sdks/code-interpreter/kotlin/gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spotless = "6.23.3"
2323
maven-publish = "0.35.0"
2424
dokka = "1.9.10"
2525
jackson = "2.18.2"
26-
sandbox = "1.0.0-SNAPSHOT"
26+
sandbox = "1.0.0"
2727
junit-platform = "1.13.4"
2828

2929
[libraries]

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,3 @@ plugins {
2222

2323
include(":code-interpreter")
2424
include(":code-interpreter-bom")
25-
26-
// Development-time dependency substitution:
27-
// Allow developing this SDK against local sandbox sources without changing published dependencies.
28-
//
29-
// Usage:
30-
// - Enable: ./gradlew -PuseLocalSandbox=true ...
31-
// - Disable (default): do nothing, uses Maven coordinates declared in dependencies.
32-
val useLocalSandbox = providers.gradleProperty("useLocalSandbox").orNull?.toBoolean() == true
33-
if (useLocalSandbox) {
34-
includeBuild("../../sandbox/kotlin") {
35-
dependencySubstitution {
36-
substitute(module("com.alibaba.opensandbox:sandbox")).using(project(":sandbox"))
37-
substitute(module("com.alibaba.opensandbox:sandbox-api")).using(project(":sandbox-api"))
38-
substitute(module("com.alibaba.opensandbox:sandbox-bom")).using(project(":sandbox-bom"))
39-
}
40-
}
41-
}

sdks/sandbox/kotlin/build.gradle.kts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,21 @@
1616

1717
@file:Suppress("UnstableApiUsage")
1818

19+
import org.gradle.api.GradleException
1920
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
2021

22+
fun Project.resolveVersionFromTag(expectedTagPrefix: String): String? {
23+
val refName = System.getenv("GITHUB_REF_NAME") ?: System.getenv("GITHUB_REF")?.removePrefix("refs/tags/")
24+
val fromEnv =
25+
refName
26+
?.trim()
27+
?.takeIf { it.startsWith(expectedTagPrefix) }
28+
?.removePrefix(expectedTagPrefix)
29+
?.trim()
30+
?.takeIf { it.isNotEmpty() }
31+
return fromEnv
32+
}
33+
2134
buildscript {
2235
repositories {
2336
mavenCentral()
@@ -37,9 +50,24 @@ plugins {
3750
alias(libs.plugins.mavenPublish) apply false
3851
}
3952

53+
val manualProjectVersion = project.findProperty("project.version") as String
54+
val tagVersion =
55+
project.resolveVersionFromTag(
56+
expectedTagPrefix = "java/sandbox/v",
57+
)
58+
59+
if (tagVersion != null && tagVersion != manualProjectVersion) {
60+
throw GradleException(
61+
"Ref/tag version mismatch: expected version '$manualProjectVersion' from gradle.properties, " +
62+
"but got '$tagVersion' from tag 'java/sandbox/v...'. Please align the tag and project.version.",
63+
)
64+
}
65+
66+
extra["project.version"] = manualProjectVersion
67+
4068
allprojects {
4169
group = project.findProperty("project.group") as String
42-
version = project.findProperty("project.version") as String
70+
version = manualProjectVersion
4371

4472
repositories {
4573
mavenCentral()

sdks/sandbox/kotlin/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ org.gradle.parallel=true
55

66
# Project metadata
77
project.group=com.alibaba.opensandbox
8-
project.version=1.0.0-SNAPSHOT
8+
project.version=1.0.0
99
project.description=A Kotlin SDK for Open Sandbox API

sdks/sandbox/kotlin/sandbox/src/main/kotlin/com/alibaba/opensandbox/sandbox/config/ConnectionConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ConnectionConfig private constructor(
4949
private const val ENV_API_KEY = "OPEN_SANDBOX_API_KEY"
5050
private const val ENV_DOMAIN = "OPEN_SANDBOX_DOMAIN"
5151

52-
private const val DEFAULT_USER_AGENT = "OpenSandbox-Kotlin-SDK/1.0.0-SNAPSHOT"
52+
private const val DEFAULT_USER_AGENT = "OpenSandbox-Kotlin-SDK/1.0.0"
5353

5454
@JvmStatic
5555
fun builder(): Builder = Builder()

0 commit comments

Comments
 (0)