chore(ci): publish an openapi json artifact with nightly releases (#999)
This commit is contained in:
@@ -47,7 +47,7 @@ just api check
|
||||
|
||||
## Running Locally
|
||||
|
||||
The backend expects a MariaDB instance and a local `application-dev.yml` with your database and
|
||||
The backend expects a MariaDB instance plus environment or local configuration for your database and
|
||||
storage paths. The common backend loop is:
|
||||
|
||||
```bash
|
||||
@@ -80,10 +80,14 @@ backend-only development and test runs, frontend resources are optional.
|
||||
|
||||
- `application.yaml` binds `app.api-docs.enabled` to `API_DOCS_ENABLED` (default `false`).
|
||||
- `application.yaml` binds `springdoc.api-docs.enabled` to `app.api-docs.enabled`.
|
||||
- `application-dev.yml` enables docs for local dev profile runs by default.
|
||||
- For runtime or container profiles, set `API_DOCS_ENABLED=true` to expose:
|
||||
- `/api/openapi.json`
|
||||
- `/api/docs`
|
||||
- To export a release-ready spec without running the full container stack, use:
|
||||
|
||||
```bash
|
||||
just openapi-export
|
||||
```
|
||||
|
||||
## Packaging Notes
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ run profile='dev':
|
||||
build:
|
||||
{{ gradle }} build --no-daemon --parallel --build-cache
|
||||
|
||||
# Build the backend jar and export build/openapi/grimmory-openapi.json.
|
||||
openapi-export:
|
||||
{{ gradle }} buildOpenApiArtifacts --no-daemon --parallel --build-cache
|
||||
|
||||
# Run the backend test suite.
|
||||
test:
|
||||
{{ gradle }} test --no-daemon --parallel --build-cache
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.api.tasks.SourceSetContainer
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.testing.jacoco.tasks.JacocoReport
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootJar
|
||||
@@ -31,6 +32,11 @@ tasks.withType<JavaCompile>().configureEach {
|
||||
}
|
||||
|
||||
val useLocalLibs = providers.gradleProperty("useLocalLibs").isPresent
|
||||
val mainSourceSet = the<SourceSetContainer>()["main"]
|
||||
val openApiOutputDir = layout.buildDirectory.dir("openapi")
|
||||
val openApiOutputFile = openApiOutputDir.map { it.file("grimmory-openapi.json") }
|
||||
val openApiLogFile = openApiOutputDir.map { it.file("export-openapi.log") }
|
||||
val openApiExportScript = layout.projectDirectory.file("scripts/export-openapi.sh")
|
||||
|
||||
repositories {
|
||||
if (useLocalLibs) mavenLocal()
|
||||
@@ -90,6 +96,8 @@ configurations {
|
||||
}
|
||||
}
|
||||
|
||||
val openApiExportRuntimeOnly by configurations.creating
|
||||
|
||||
dependencies {
|
||||
// --- Spring Boot ---
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||
@@ -182,6 +190,7 @@ dependencies {
|
||||
testImplementation("org.assertj:assertj-core:3.27.7")
|
||||
testImplementation("org.mockito:mockito-inline:5.2.0")
|
||||
testRuntimeOnly("com.h2database:h2")
|
||||
add(openApiExportRuntimeOnly.name, "com.h2database:h2")
|
||||
|
||||
// PDFBox for test PDF creation only (production code uses PDFium4j)
|
||||
testImplementation("org.apache.pdfbox:pdfbox:3.0.7")
|
||||
@@ -234,3 +243,43 @@ tasks.named<BootRun>("bootRun") {
|
||||
tasks.named<BootJar>("bootJar") {
|
||||
mainClass.set("org.booklore.BookloreApplication")
|
||||
}
|
||||
|
||||
tasks.register("exportOpenApi") {
|
||||
group = "documentation"
|
||||
description = "Boot the backend with the openapi-export profile and write build/openapi/grimmory-openapi.json."
|
||||
dependsOn(tasks.named("classes"))
|
||||
inputs.files(mainSourceSet.runtimeClasspath, openApiExportRuntimeOnly, openApiExportScript)
|
||||
outputs.file(openApiOutputFile)
|
||||
|
||||
doLast {
|
||||
val outputFile = openApiOutputFile.get().asFile
|
||||
val logFile = openApiLogFile.get().asFile
|
||||
val classpath = files(mainSourceSet.runtimeClasspath, openApiExportRuntimeOnly).asPath
|
||||
val javaExecutable = javaToolchains.launcherFor {
|
||||
languageVersion.set(JavaLanguageVersion.of(25))
|
||||
}.get().executablePath.asFile.absolutePath
|
||||
|
||||
val result = ProcessBuilder(
|
||||
"bash",
|
||||
openApiExportScript.asFile.absolutePath,
|
||||
javaExecutable,
|
||||
classpath,
|
||||
outputFile.absolutePath
|
||||
)
|
||||
.directory(project.projectDir)
|
||||
.inheritIO()
|
||||
.apply {
|
||||
environment()["OPENAPI_EXPORT_LOG_FILE"] = logFile.absolutePath
|
||||
}
|
||||
.start()
|
||||
|
||||
val exitCode = result.waitFor()
|
||||
check(exitCode == 0) { "OpenAPI export script failed with exit code $exitCode. See ${logFile.absolutePath}." }
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("buildOpenApiArtifacts") {
|
||||
group = "build"
|
||||
description = "Build the backend jar and export build/openapi/grimmory-openapi.json from the openapi-export profile."
|
||||
dependsOn(tasks.named("bootJar"), tasks.named("exportOpenApi"))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -ne 3 ]]; then
|
||||
echo "Usage: $0 <java-executable> <classpath> <output-file>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
java_executable="$1"
|
||||
classpath="$2"
|
||||
output_file="$3"
|
||||
output_dir="$(dirname "$output_file")"
|
||||
log_file="${OPENAPI_EXPORT_LOG_FILE:-$output_dir/export-openapi.log}"
|
||||
|
||||
mkdir -p "$output_dir"
|
||||
: > "$log_file"
|
||||
|
||||
port="$(
|
||||
python3 - <<'PY'
|
||||
import socket
|
||||
s = socket.socket()
|
||||
s.bind(("127.0.0.1", 0))
|
||||
print(s.getsockname()[1])
|
||||
s.close()
|
||||
PY
|
||||
)"
|
||||
|
||||
endpoint="http://127.0.0.1:${port}/api/openapi.json"
|
||||
|
||||
"$java_executable" \
|
||||
--enable-native-access=ALL-UNNAMED \
|
||||
--enable-preview \
|
||||
-Dspring.profiles.active=openapi-export \
|
||||
-Dserver.port="$port" \
|
||||
-cp "$classpath" \
|
||||
org.booklore.BookloreApplication \
|
||||
>>"$log_file" 2>&1 &
|
||||
app_pid=$!
|
||||
|
||||
cleanup() {
|
||||
if kill -0 "$app_pid" 2>/dev/null; then
|
||||
kill "$app_pid" 2>/dev/null || true
|
||||
wait "$app_pid" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
for _ in $(seq 1 60); do
|
||||
if ! kill -0 "$app_pid" 2>/dev/null; then
|
||||
echo "OpenAPI export application exited before serving ${endpoint}. See ${log_file}." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if curl --silent --show-error --fail --max-time 5 "$endpoint" -o "$output_file"; then
|
||||
if grep -q '"openapi"' "$output_file"; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Timed out waiting for ${endpoint}. See ${log_file}." >&2
|
||||
exit 1
|
||||
@@ -0,0 +1,39 @@
|
||||
app:
|
||||
api-docs:
|
||||
enabled: true
|
||||
path-config: ${OPENAPI_EXPORT_APP_PATH:${java.io.tmpdir}/grimmory-openapi-export/data}
|
||||
bookdrop-folder: ${OPENAPI_EXPORT_BOOKDROP:${java.io.tmpdir}/grimmory-openapi-export/bookdrop}
|
||||
cors:
|
||||
allowed-origins: http://127.0.0.1
|
||||
|
||||
server:
|
||||
port: ${OPENAPI_EXPORT_PORT:9091}
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:h2:mem:openapi-export;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=TRUE;NON_KEYWORDS=VALUE
|
||||
driver-class-name: org.h2.Driver
|
||||
username: sa
|
||||
password:
|
||||
flyway:
|
||||
enabled: false
|
||||
jpa:
|
||||
properties:
|
||||
hibernate:
|
||||
connection:
|
||||
provider_disables_autocommit: false
|
||||
task:
|
||||
scheduling:
|
||||
enabled: false
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: WARN
|
||||
org.booklore: WARN
|
||||
org.hibernate.orm.deprecation: ERROR
|
||||
com.github.gotson.nightcompress.Archive: ERROR
|
||||
io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics: ERROR
|
||||
org.booklore.config.WebSocketConfig: ERROR
|
||||
org.booklore.config.security.SecurityConfig: ERROR
|
||||
org.booklore.service.monitoring.LibraryWatchService: ERROR
|
||||
org.booklore.service.watcher.LibraryFileEventProcessor: ERROR
|
||||
Reference in New Issue
Block a user