From df3137f821784a3333b49168e218edefb8bb5b3b Mon Sep 17 00:00:00 2001 From: Petr Ilin Date: Sat, 4 Feb 2023 00:46:00 +0300 Subject: [PATCH] 1.0.3 release: ability to disable PNG recompression --- .github/workflows/build.yml | 57 ++++++++++++++----- .github/workflows/release.yml | 51 +++++++++++++++++ VERSION | 2 +- build.gradle | 2 +- .../java/net/elytrium/fastmotd/Settings.java | 3 +- .../fastmotd/utils/MOTDGenerator.java | 41 +++++++------ 6 files changed, 120 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d3b54f1..f02cd52 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,40 +1,67 @@ name: Java CI with Gradle -on: [ push, pull_request ] +on: + push: + branches: + - master + pull_request: + branches: + - master jobs: build: runs-on: ubuntu-latest - strategy: - matrix: - java: [ 11, 17 ] - fail-fast: true steps: - name: Checkout - uses: actions/checkout@v3.0.1 - - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v3.1.1 + uses: actions/checkout@v3.0.0 + - name: Set up JDK + uses: actions/setup-java@v3.0.0 with: distribution: adopt - java-version: ${{ matrix.java }} + java-version: 11 - name: Build FastMOTD run: ./gradlew build - name: Upload FastMOTD uses: actions/upload-artifact@v3.0.0 with: - name: FastMOTD Built On ${{ matrix.java }} JDK + name: FastMOTD path: "build/libs/FastMOTD*.jar" - uses: dev-drprasad/delete-tag-and-release@v0.2.0 + if: ${{ github.event_name == 'push' }} with: delete_release: true - tag_name: dev-build-jdk-${{ matrix.java }} + tag_name: dev-build env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Find git version + id: git-version + run: echo "id=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - name: Find correct JAR + if: ${{ github.event_name == 'push' }} + id: find-jar + run: | + output="$(find build/libs/ ! -name "*-javadoc.jar" ! -name "*-sources.jar" -type f -printf "%f\n")" + echo "::set-output name=jarname::$output" - name: Release the build - uses: ncipollo/release-action@v1.10.0 + if: ${{ github.event_name == 'push' }} + uses: ncipollo/release-action@v1 with: - artifacts: "build/libs/FastMOTD*.jar" + artifacts: build/libs/${{ steps.find-jar.outputs.jarname }} body: ${{ join(github.event.commits.*.message, '\n') }} prerelease: true - name: JDK ${{ matrix.java }} Dev-build - tag: dev-build-jdk-${{ matrix.java }} + name: Dev-build ${{ steps.git-version.outputs.id }} + tag: dev-build + - name: Upload to Modrinth + if: ${{ github.event_name == 'push' }} + uses: RubixDev/modrinth-upload@v1.0.0 + with: + token: ${{ secrets.MODRINTH_TOKEN }} + file_path: build/libs/${{ steps.find-jar.outputs.jarname }} + name: Dev-build ${{ steps.git-version.outputs.id }} + version: ${{ steps.git-version.outputs.id }} + changelog: ${{ join(github.event.commits.*.message, '\n') }} + game_versions: 1.7.2 + release_type: beta + loaders: velocity + featured: false + project_id: OfMfkdiO diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..54921ba --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,51 @@ +name: Java CI with Gradle + +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3.0.0 + - name: Set up JDK + uses: actions/setup-java@v3.0.0 + with: + distribution: adopt + java-version: 11 + - name: Build FastMOTD + run: ./gradlew build + - name: Upload FastMOTD + uses: actions/upload-artifact@v3.0.0 + with: + name: FastMOTD + path: "build/libs/FastMOTD*.jar" + - name: Find correct JAR + id: find-jar + run: | + output="$(find build/libs/ ! -name "*-javadoc.jar" ! -name "*-sources.jar" -type f -printf "%f\n")" + echo "::set-output name=jarname::$output" + - name: Upload to the GitHub release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: build/libs/${{ steps.find-jar.outputs.jarname }} + asset_name: ${{ steps.find-jar.outputs.jarname }} + asset_content_type: application/java-archive + - name: Upload to Modrinth + uses: RubixDev/modrinth-upload@v1.0.0 + with: + token: ${{ secrets.MODRINTH_TOKEN }} + file_path: build/libs/${{ steps.find-jar.outputs.jarname }} + name: Release ${{ github.event.release.tag_name }} + version: ${{ github.event.release.tag_name }} + changelog: ${{ github.event.release.body }} + game_versions: 1.7.2 + release_type: release + loaders: velocity + featured: false + project_id: OfMfkdiO diff --git a/VERSION b/VERSION index 6d7de6e..21e8796 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.2 +1.0.3 diff --git a/build.gradle b/build.gradle index 83cdf98..b6ec8bd 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { } setGroup("net.elytrium") -setVersion("1.0.2") +setVersion("1.0.3") java { setSourceCompatibility(JavaVersion.VERSION_11) diff --git a/src/main/java/net/elytrium/fastmotd/Settings.java b/src/main/java/net/elytrium/fastmotd/Settings.java index 9fd9834..8d3d192 100644 --- a/src/main/java/net/elytrium/fastmotd/Settings.java +++ b/src/main/java/net/elytrium/fastmotd/Settings.java @@ -61,7 +61,8 @@ public static class MAIN { public int FAKE_ONLINE_ADD_PERCENT = 20; @Comment({ "Accepted values: from 0.0 to 1.0.", - "Keep this value as low as possible" + "Keep this value as low as possible", + "Set -1 to disable PNG recompression" }) public double PNG_QUALITY = 0.0; public boolean LOG_PINGS = false; diff --git a/src/main/java/net/elytrium/fastmotd/utils/MOTDGenerator.java b/src/main/java/net/elytrium/fastmotd/utils/MOTDGenerator.java index cb0bbe8..d2e9d2f 100644 --- a/src/main/java/net/elytrium/fastmotd/utils/MOTDGenerator.java +++ b/src/main/java/net/elytrium/fastmotd/utils/MOTDGenerator.java @@ -91,28 +91,33 @@ private void generate(int i, String favicon) { } private String getFavicon(Path faviconLocation) throws IOException { - BufferedImage image = ImageIO.read(Files.newInputStream(faviconLocation)); - - ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); - try (ImageOutputStream out = ImageIO.createImageOutputStream(outBytes)) { - ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage(image); - ImageWriter writer = ImageIO.getImageWriters(type, "png").next(); - - ImageWriteParam param = writer.getDefaultWriteParam(); - if (param.canWriteCompressed()) { - param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); - param.setCompressionQuality((float) Settings.IMP.MAIN.PNG_QUALITY); + byte[] imageBytes; + + if (Settings.IMP.MAIN.PNG_QUALITY < 0) { + imageBytes = Files.readAllBytes(faviconLocation); + } else { + BufferedImage image = ImageIO.read(Files.newInputStream(faviconLocation)); + ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); + try (ImageOutputStream out = ImageIO.createImageOutputStream(outBytes)) { + ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage(image); + ImageWriter writer = ImageIO.getImageWriters(type, "png").next(); + + ImageWriteParam param = writer.getDefaultWriteParam(); + if (param.canWriteCompressed()) { + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + param.setCompressionQuality((float) Settings.IMP.MAIN.PNG_QUALITY); + } + + writer.setOutput(out); + writer.write(null, new IIOImage(image, null, null), param); + writer.dispose(); } - writer.setOutput(out); - writer.write(null, new IIOImage(image, null, null), param); - writer.dispose(); + imageBytes = outBytes.toByteArray(); + outBytes.close(); } - String favicon = "data:image/png;base64," + Base64.getEncoder().encodeToString(outBytes.toByteArray()); - outBytes.close(); - - return favicon; + return "data:image/png;base64," + Base64.getEncoder().encodeToString(imageBytes); } public void update(int max, int online) {