From 02583238e7bfb7c40cb732e1d2f81920b9289a13 Mon Sep 17 00:00:00 2001 From: Robothy Date: Wed, 11 Oct 2023 15:15:37 +0800 Subject: [PATCH 1/3] configure CI --- .github/workflows/build.yml | 44 +++++++ .github/workflows/pr.yml | 42 +++++++ .github/workflows/release.yml | 81 +++++++++++++ build.gradle | 108 +++++++++++++++++- .../sdk/models/options/Txt2ImageOptions.java | 6 +- .../models/options/Txt2ImageOptionsTest.java | 66 +++++++++++ 6 files changed, 344 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/release.yml create mode 100644 src/test/java/io/github/robothy/sdwebui/sdk/models/options/Txt2ImageOptionsTest.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3d9c346 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,44 @@ +name: Main Branch Build +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Java 17 for Gradle + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Gradle Cache + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + key: ${{runner.os}}-build-gradle-${{hashFiles('**/gradle-wrapper.properties')}} + + - name: Prepare parameters + run: | + git log --pretty=format:"%H - %an, %aI : %s" -5 + mkdir -p ~/.gradle + echo "GITHUB_TOKEN=${{secrets.PACKAGES_TOKEN}}" > ~/.gradle/gradle.properties + echo "GITHUB_USERNAME=Robothy" >> ~/.gradle/gradle.properties + chmod +x gradlew + pwd + ls -l + + - name: Build + run: ./gradlew mergeReports + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + files: ./build/reports/jacoco/mergeReports/mergeReports.xml \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..69bff65 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,42 @@ +name: PR Build +on: + pull_request + +jobs: + pr-build: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Java 17 for Gradle + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Gradle Cache + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + key: ${{runner.os}}-build-gradle-${{hashFiles('**/gradle-wrapper.properties')}} + + - name: Prepare parameters + run: | + git log --pretty=format:"%H - %an, %aI : %s" -5 + mkdir -p ~/.gradle + echo "GITHUB_TOKEN=${{secrets.PACKAGES_TOKEN}}" > ~/.gradle/gradle.properties + echo "GITHUB_USERNAME=Robothy" >> ~/.gradle/gradle.properties + chmod +x gradlew + pwd + ls -l + + - name: Build + run: ./gradlew mergeReports + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + files: ./build/reports/jacoco/mergeReports/mergeReports.xml \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..441e2af --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Publish +on: + workflow_dispatch: + inputs: + gradleLogLevel: + description: 'Gradle logging level.' + required: false + default: None + type: choice + options: + - None + - Info + - Warn + - Debug + - Stacktrace + +jobs: + release: + runs-on: ubuntu-20.04 + env: + GITHUB_USERNAME: Robothy + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Java 17 for Gradle + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Gradle Cache + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + key: ${{runner.os}}-build-gradle-${{hashFiles('**/gradle-wrapper.properties')}} + + - name: Prepare parameters + run: | + git log --pretty=format:"%H - %an, %aI : %s" -5 + mkdir -p ~/.gradle + echo "GITHUB_TOKEN=${{secrets.PACKAGES_TOKEN}}" > ~/.gradle/gradle.properties + echo "GITHUB_USERNAME=Robothy" >> ~/.gradle/gradle.properties + echo "signing.secretKey=${{ secrets.SING_SECRET_KEY }}" >> ~/.gradle/gradle.properties + echo "signing.password=${{ secrets.SING_PASSWORD }}" >> ~/.gradle/gradle.properties + echo "OSSRH_USERNAME=${{ secrets.OSSRH_USERNAME }}" >> ~/.gradle/gradle.properties + echo "OSSRH_PASSWORD=${{ secrets.OSSRH_PASSWORD }}" >> ~/.gradle/gradle.properties + chmod +x gradlew + pwd + ls -l + + - name: Update release version + run: | + ./gradlew releaseVersion + + - name: Publish + if: ${{inputs.gradleLogLevel == 'None'}} + run: | + ./gradlew check release + + - name: Publish(Info) + if: ${{inputs.gradleLogLevel == 'Info'}} + run: .| + ./gradlew check release --info + + - name: Publish(Warn) + if: ${{inputs.gradleLogLevel == 'Warn'}} + run: .| + ./gradlew check release --warn + + - name: Publish(Debug) + if: ${{inputs.gradleLogLevel == 'Debug'}} + run: | + ./gradlew check release --debug + + - name: Publish(Stacktrace) + if: ${{inputs.gradleLogLevel == 'Stacktrace'}} + run: | + ./gradlew check release --stacktrace \ No newline at end of file diff --git a/build.gradle b/build.gradle index e6b1f7f..62ca8e4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,14 @@ +import io.franzbecker.gradle.lombok.task.DelombokTask + +import java.nio.file.Files + + plugins { - id 'maven-publish' id 'java-library' + id 'jacoco' + id 'maven-publish' + id 'io.franzbecker.gradle-lombok' version '5.0.0' + id 'signing' id 'com.robothy.cn-repo' version '1.8' } @@ -35,6 +43,104 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter' } +java { + withSourcesJar() + withJavadocJar() +} + test { useJUnitPlatform() +} + + +publishing { + + publications { + maven(MavenPublication) { + groupId = group + artifactId = project.name + from components.java + + pom { + name = "sdwebui-java-sdk" + description = 'Stable Diffusion Web UI Java SDK' + url = 'https://github.com/Robothy/sdwebui-java-sdk' + + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + + developers { + developer { + id = 'robothy' + name = "Fuxiang Luo" + email = "robothyluo@gmail.com" + } + } + + scm { + url = "https://github.com/Robothy/sdwebui-java-sdk.git" + } + + } + } + } + + repositories { + mavenLocal() + + repositories { + mavenLocal() + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/Robothy/sdwebui-java-sdk") + credentials { + username = project.findProperty("GITHUB_USERNAME") ?: System.getenv("GITHUB_USERNAME") + password = project.findProperty("GITHUB_TOKEN") ?: System.getenv("GITHUB_TOKEN") + } + } + + maven { + name = "MavenCentral" + url = uri('https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/') + credentials { + username = findProperty("OSSRH_USERNAME") + password = findProperty("OSSRH_PASSWORD") + } + } + + } + } +} + + + +task delombok(type: DelombokTask, dependsOn: compileJava) { + ext.outputDir = file("$buildDir/delombok") + outputs.dir(outputDir) + sourceSets.main.java.srcDirs.each { + inputs.dir(it) + args(it, "-d", outputDir) + } +} + +javadoc { + dependsOn delombok + source = delombok.outputDir + //failOnError = false +} + +signing { + def signingKey + if (findProperty("signingKeyRingFile") != null) { + signingKey = Files.readString(file(findProperty("signing.secretKeyRingFile")).toPath()) + } else { + signingKey = findProperty("signing.secretKey") + } + def signingPassword = findProperty("signing.password") + useInMemoryPgpKeys(signingKey, signingPassword) + sign publishing.publications.maven } \ No newline at end of file diff --git a/src/main/java/io/github/robothy/sdwebui/sdk/models/options/Txt2ImageOptions.java b/src/main/java/io/github/robothy/sdwebui/sdk/models/options/Txt2ImageOptions.java index 76590a6..6759c69 100644 --- a/src/main/java/io/github/robothy/sdwebui/sdk/models/options/Txt2ImageOptions.java +++ b/src/main/java/io/github/robothy/sdwebui/sdk/models/options/Txt2ImageOptions.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import io.github.robothy.sdwebui.sdk.enums.HiResUpscaler; +import java.util.ArrayList; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -62,7 +64,7 @@ public class Txt2ImageOptions { @Builder.Default @JsonProperty("styles") - private String[] styles = new String[]{}; + private List styles = new ArrayList<>(); @Builder.Default @JsonProperty("seed") @@ -162,7 +164,7 @@ public class Txt2ImageOptions { @Builder.Default @JsonProperty("script_args") - private String[] scriptArgs = new String[]{}; + private List scriptArgs = new ArrayList<>(); @Builder.Default @JsonProperty("script_name") diff --git a/src/test/java/io/github/robothy/sdwebui/sdk/models/options/Txt2ImageOptionsTest.java b/src/test/java/io/github/robothy/sdwebui/sdk/models/options/Txt2ImageOptionsTest.java new file mode 100644 index 0000000..17485d6 --- /dev/null +++ b/src/test/java/io/github/robothy/sdwebui/sdk/models/options/Txt2ImageOptionsTest.java @@ -0,0 +1,66 @@ +package io.github.robothy.sdwebui.sdk.models.options; + +import static org.junit.jupiter.api.Assertions.*; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.robothy.sdwebui.sdk.enums.HiResUpscaler; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; + +class Txt2ImageOptionsTest { + + @Test + void testSerialization() throws JsonProcessingException { + Txt2ImageOptions txt2ImageOptions = Txt2ImageOptions.builder() + .alwaysonScripts(Map.of("s1", "v1")) + .batchSize(2) + .eta(0.1) + .denoisingStrength(0.2) + .firstphaseHeight(3) + .firstphaseWidth(4) + .hrResizeX(5) + .hrResizeY(6) + .hrScale(7) + .hrSecondPassSteps(8) + .hrUpscaler(HiResUpscaler.Latent) + .height(9) + .width(10) + .doNotSaveGrid(true) + .enableHr(true) + .prompt("prompt") + .nIter(11) + .doNotSaveSamples(true) + .negativePrompt("negativePrompt") + .saveImages(true) + .overrideSettings(Map.of("s1", "v1")) + .cfgScale(12) + .sChurn(13) + .samplerName("samplerName") + .samplerIndex("14") + .sendImages(true) + .scriptName("scriptName") + .scriptArgs(List.of("arg1", "arg2")) + .seed(15) + .seedResizeFromH(16) + .seedResizeFromW(17) + .steps(18) + .sTmax(19) + .sNoise(20) + .sTmin(10) + .subseed(21) + .styles(List.of("style1", "style2")) + .restoreFaces(true) + .tiling(true) + .subseedStrength(0.3) + .useDeprecatedControlnet(true) + .overrideSettingsRestoreAfterwards(true) + .build(); + + ObjectMapper objectMapper = new ObjectMapper(); + Txt2ImageOptions deserializedTxt2ImageOptions = + objectMapper.readValue(objectMapper.writeValueAsString(txt2ImageOptions), Txt2ImageOptions.class); + assertEquals(txt2ImageOptions, deserializedTxt2ImageOptions); + } + +} \ No newline at end of file From 7c5c63c2ae9c3264311217e6b129624da71acb97 Mon Sep 17 00:00:00 2001 From: Robothy Date: Wed, 11 Oct 2023 15:20:30 +0800 Subject: [PATCH 2/3] configure jacoco --- build.gradle | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/build.gradle b/build.gradle index 62ca8e4..3a94d6f 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,7 @@ plugins { id 'jacoco' id 'maven-publish' id 'io.franzbecker.gradle-lombok' version '5.0.0' + id 'com.robothy.github-repository-release-plugin' version '1.1' id 'signing' id 'com.robothy.cn-repo' version '1.8' } @@ -52,6 +53,22 @@ test { useJUnitPlatform() } +task mergeReports(type: JacocoReport) { + executionData.from(project.fileTree(dir: '.', include: '**/build/jacoco/test.exec')) + sourceDirectories.from(project.fileTree(dir: '.', include: '**/src/main/java/**')) + classDirectories.from(project.fileTree(dir: '.', include: '**/build/classes/java/main/**')) + reports { + xml.required.set(true) + html.required.set(true) + //csv.required.set(true) + } +} + +project.subprojects.each { + it.afterEvaluate { + mergeReports.dependsOn(it.tasks['test']) + } +} publishing { From d19eb900d1cdbb9ca4f55fd2c85bb7bfae431abd Mon Sep 17 00:00:00 2001 From: Robothy Date: Wed, 11 Oct 2023 15:35:13 +0800 Subject: [PATCH 3/3] add codecov token --- .github/workflows/build.yml | 4 +++- .github/workflows/pr.yml | 4 +++- build.gradle | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3d9c346..00559b5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,4 +41,6 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: - files: ./build/reports/jacoco/mergeReports/mergeReports.xml \ No newline at end of file + files: ./build/reports/jacoco/mergeReports/mergeReports.xml + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 69bff65..daf8c2a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -39,4 +39,6 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: - files: ./build/reports/jacoco/mergeReports/mergeReports.xml \ No newline at end of file + files: ./build/reports/jacoco/mergeReports/mergeReports.xml + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3a94d6f..d2ca1ab 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,7 @@ test { useJUnitPlatform() } -task mergeReports(type: JacocoReport) { +task mergeReports(type: JacocoReport, group: 'verification') { executionData.from(project.fileTree(dir: '.', include: '**/build/jacoco/test.exec')) sourceDirectories.from(project.fileTree(dir: '.', include: '**/src/main/java/**')) classDirectories.from(project.fileTree(dir: '.', include: '**/build/classes/java/main/**'))