Skip to content

Commit 0d17328

Browse files
committed
feat(client): add OpenAPI generator configuration and push Dart client to repository
1 parent 621e053 commit 0d17328

File tree

5 files changed

+2170
-47
lines changed

5 files changed

+2170
-47
lines changed

.github/workflows/sematic-releases.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ jobs:
4747
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4848
ONELITEFEATHER_MAVEN_USERNAME: ${{ secrets.ONELITEFEATHER_MAVEN_USERNAME }}
4949
ONELITEFEATHER_MAVEN_PASSWORD: ${{ secrets.ONELITEFEATHER_MAVEN_PASSWORD }}
50-
run: npx semantic-release
50+
# Token with permissions to push to the client repository
51+
CLIENT_REPO_TOKEN: ${{ secrets.CLIENT_REPO_TOKEN }}
52+
run: npx semantic-release

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Vulpes Backend
2+
3+
A backend server for OneLiteFeather's Vulpes project, providing a REST API and database access.
4+
5+
## Features
6+
7+
- REST API for managing custom attributes, fonts, items, and notifications
8+
- OpenAPI documentation
9+
- Automatic Dart Dio client generation
10+
11+
## OpenAPI and Dart Client Generation
12+
13+
This project automatically generates a Dart Dio client from the OpenAPI specification during the build process. The client is then pushed to a separate Git repository with the project version as a tag.
14+
15+
### How it works
16+
17+
1. The OpenAPI specification is generated during the build process using Micronaut's OpenAPI support.
18+
2. The OpenAPI Generator Gradle plugin is used to generate a Dart Dio client from the specification.
19+
3. The generated client is pushed to the [vulpes-client](https://github.com/OneLiteFeatherNET/vulpes-client) repository with the project version as a tag.
20+
21+
### Configuration
22+
23+
The OpenAPI Generator is configured in the `build.gradle.kts` file:
24+
25+
```kotlin
26+
openApiGenerate {
27+
generatorName.set("dart-dio")
28+
inputSpec.set("$buildDir/tmp/kapt3/classes/main/META-INF/swagger/vulpes-backend-1.0.yml")
29+
outputDir.set("$buildDir/generated/dart-client")
30+
apiPackage.set("net.onelitefeather.vulpes.client.api")
31+
invokerPackage.set("net.onelitefeather.vulpes.client.invoker")
32+
modelPackage.set("net.onelitefeather.vulpes.client.model")
33+
configOptions.set(mapOf(
34+
"pubName" to "vulpes_client",
35+
"pubVersion" to (project.version as String),
36+
"pubDescription" to "Vulpes API Client",
37+
"pubAuthor" to "OneLiteFeather",
38+
"pubAuthorEmail" to "[email protected]",
39+
"pubHomepage" to "https://github.com/OneLiteFeatherNET/vulpes-client",
40+
"pubRepository" to "https://github.com/OneLiteFeatherNET/vulpes-client",
41+
"dateLibrary" to "core",
42+
"enumUnknownDefaultCase" to "true"
43+
))
44+
}
45+
```
46+
47+
### GitHub Actions
48+
49+
The GitHub Actions workflow is configured to run the client generation and repository pushing during the release process. The workflow uses a custom secret called `CLIENT_REPO_TOKEN` for authenticating with GitHub when pushing to the client repository.
50+
51+
To set up the `CLIENT_REPO_TOKEN`:
52+
53+
1. Create a personal access token with the `repo` scope.
54+
2. Add the token as a secret in the repository settings with the name `CLIENT_REPO_TOKEN`.
55+
56+
## Development
57+
58+
### Prerequisites
59+
60+
- Java 21
61+
- Gradle
62+
- Node.js (for semantic-release)
63+
64+
### Building
65+
66+
```bash
67+
./gradlew build
68+
```
69+
70+
### Running
71+
72+
```bash
73+
./gradlew run
74+
```
75+
76+
### Testing
77+
78+
```bash
79+
./gradlew test
80+
```
81+
82+
## License
83+
84+
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.

build.gradle.kts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
alias(libs.plugins.micronaut.aot)
44
jacoco
55
`maven-publish`
6+
id("org.openapi.generator") version "7.14.0"
67
}
78

89
java {
@@ -91,6 +92,89 @@ tasks {
9192
csv.required.set(false)
9293
}
9394
}
95+
this.openApiGenerate {
96+
dependsOn("compileJava")
97+
}
98+
register("pushDartClient") {
99+
dependsOn("openApiGenerate")
100+
doLast {
101+
val clientDir = file("$buildDir/generated/dart-client")
102+
val version = project.version as String
103+
104+
// Get GitHub credentials from environment variables
105+
val githubToken = System.getenv("CLIENT_REPO_TOKEN") ?: System.getenv("GITHUB_TOKEN") ?: throw GradleException("CLIENT_REPO_TOKEN or GITHUB_TOKEN environment variable is required")
106+
107+
// Create a temporary directory for the Git repository
108+
val tempDir = file("$buildDir/temp/vulpes-client")
109+
tempDir.mkdirs()
110+
111+
// Configure Git user
112+
exec {
113+
commandLine("git", "config", "--global", "user.name", "GitHub Actions")
114+
}
115+
116+
exec {
117+
commandLine("git", "config", "--global", "user.email", "[email protected]")
118+
}
119+
120+
// Clone the repository using token authentication
121+
exec {
122+
workingDir = tempDir
123+
commandLine("git", "clone", "https://${githubToken}@github.com/OneLiteFeatherNET/vulpes-backend-client-dart.git", ".")
124+
}
125+
126+
// Copy the generated client to the repository
127+
copy {
128+
from(clientDir)
129+
into(tempDir)
130+
}
131+
132+
// Commit and push the changes
133+
exec {
134+
workingDir = tempDir
135+
commandLine("git", "add", ".")
136+
}
137+
138+
exec {
139+
workingDir = tempDir
140+
commandLine("git", "commit", "-m", "Update client to version $version")
141+
}
142+
143+
exec {
144+
workingDir = tempDir
145+
commandLine("git", "tag", "-a", "v$version", "-m", "Version $version")
146+
}
147+
148+
exec {
149+
workingDir = tempDir
150+
commandLine("git", "push", "origin", "main", "--tags")
151+
}
152+
}
153+
}
154+
named("publish") {
155+
dependsOn("pushDartClient")
156+
}
157+
}
158+
159+
// OpenAPI Generator configuration
160+
openApiGenerate {
161+
generatorName.set("dart-dio")
162+
inputSpec.set("$projectDir/build/classes/java/main/META-INF/swagger/vulpes-backend-1.0.yml")
163+
outputDir.set("$projectDir/build/generated/dart-client")
164+
apiPackage.set("net.onelitefeather.vulpes.client.api")
165+
invokerPackage.set("net.onelitefeather.vulpes.client.invoker")
166+
modelPackage.set("net.onelitefeather.vulpes.client.model")
167+
configOptions.set(mapOf(
168+
"pubName" to "vulpes_client",
169+
"pubVersion" to (project.version as String),
170+
"pubDescription" to "Vulpes API Client",
171+
"pubAuthor" to "OneLiteFeather",
172+
"pubAuthorEmail" to "[email protected]",
173+
"pubHomepage" to "https://github.com/OneLiteFeatherNET/vulpes-backend-client-dart",
174+
"pubRepository" to "https://github.com/OneLiteFeatherNET/vulpes-backend-client-dart",
175+
"dateLibrary" to "core",
176+
"enumUnknownDefaultCase" to "true"
177+
))
94178
}
95179

96180
publishing {

0 commit comments

Comments
 (0)