From 10edfe5ef61ef275029b5d94f43dbebea55af416 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 29 Aug 2023 22:44:06 +0200 Subject: [PATCH 1/7] Improve CI: now create a tag when publishing a new release --- .gitea/workflows/{test.yml => ci.yml} | 14 +++--- build.gradle | 15 +++++- .../src/main/java/fr/altarik/CreateTag.java | 48 +++++++++++++++++++ gradle.properties | 7 ++- 4 files changed, 73 insertions(+), 11 deletions(-) rename .gitea/workflows/{test.yml => ci.yml} (86%) create mode 100644 buildSrc/src/main/java/fr/altarik/CreateTag.java diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/ci.yml similarity index 86% rename from .gitea/workflows/test.yml rename to .gitea/workflows/ci.yml index 5b4c10e..713ffe2 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/ci.yml @@ -3,7 +3,7 @@ # certain platforms or Java versions, and provides a first line of defence # against bad commits. -name: +name: Test and Deploy on: push: branches: [ master, dev ] @@ -39,9 +39,7 @@ jobs: chmod +x ./gradlew touch local.properties - name: build - run: ./gradlew build --no-daemon --max-workers 1 - #- name: test - # run: ./gradlew test --no-daemon + run: ./gradlew build # compile classes, testClasses, assemble in jar and javadocJar, and then test deploy: strategy: matrix: @@ -66,7 +64,9 @@ jobs: chmod +x ./gradlew touch local.properties - name: deploy - run: | - ./gradlew publish - ./gradlew reportToDiscord + run: ./gradlew publish + - name: create tag + run: ./gradlew createTag + - name: Report to Discord + run: ./gradlew reportToDiscord diff --git a/build.gradle b/build.gradle index 047bbbe..473f0ea 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,8 @@ +import fr.altarik.CreateTag import fr.altarik.ReportDiscord plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' apply false + id 'fabric-loom' version '1.3-SNAPSHOT' apply false } Properties local = new Properties() @@ -18,6 +19,11 @@ String repoUrl = "https://repo.altarik.fr/#/" + (project.version.endsWith('SNAPS var reportConfig = new ReportDiscord.ReportData("https://discord.com/api/", webhookId, webhookToken, project.rootProject.name, "Update " + project.version + " has been published", repoUrl); +String giteaToken = getEnv("GITEA_TOKEN", local.getProperty("gitea_token")) + +var releaseConfig = new CreateTag.CreateReleaseData("https://git.altarik.fr", project.git_owner, project.git_repo, "v" + project.version as String, giteaToken); + + allprojects { apply plugin: 'maven-publish' apply plugin: 'fabric-loom' @@ -82,7 +88,7 @@ allprojects { // We'll use that if it's available, but otherwise we'll use the older option. def targetVersion = 17 if (JavaVersion.current().isJava9Compatible()) { - it.options.release = targetVersion + it.options.release.set(targetVersion) } } @@ -124,6 +130,11 @@ tasks.register("reportToDiscord", ReportDiscord) { config.set(reportConfig) } +tasks.register("createTag", CreateTag) { + config.set(releaseConfig) +} + + /*jar { dependsOn subprojects.jar subprojects.each { project -> diff --git a/buildSrc/src/main/java/fr/altarik/CreateTag.java b/buildSrc/src/main/java/fr/altarik/CreateTag.java new file mode 100644 index 0000000..33ad392 --- /dev/null +++ b/buildSrc/src/main/java/fr/altarik/CreateTag.java @@ -0,0 +1,48 @@ +package fr.altarik; + +import okhttp3.*; +import org.gradle.api.DefaultTask; +import org.gradle.api.GradleException; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.TaskAction; + +import java.io.IOException; + +public abstract class CreateTag extends DefaultTask { + + public static final MediaType JSON = MediaType.get("application/json; charset=utf-8"); + private final OkHttpClient client = new OkHttpClient(); + + @Input + public abstract Property getConfig(); + + + @TaskAction + public void create() throws IOException { + CreateReleaseData data = getConfig().get(); + String postUrl = data.baseUrl() + "/api/v1/repos/" + data.owner() + "/" + data.repoName() + "/tags"; + RequestBody body = RequestBody.create(""" + { + "tag_name": \"""" + data.tagName() + "\"" + """ + } + """, JSON); + Request request = new Request.Builder() + .url(postUrl) + .post(body) + .header("Authorization", "token " + data.giteaToken()) + .build(); + try(Response response = client.newCall(request).execute()) { + if(!response.isSuccessful()) { + if(response.code() != 409) + throw new GradleException("Cannot create tag, server answer with code " + response.code() + " and message : " + response.message()); + } + } + + } + + public record CreateReleaseData(String baseUrl, String owner, String repoName, String tagName, String giteaToken) { + } + + +} diff --git a/gradle.properties b/gradle.properties index eafac93..2b4ad00 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,11 @@ fabric.loom.multiProjectOptimisation=true junit_version=5.9.0 minecraft_version=1.19.3 yarn_mappings=1.19.3+build.5 -loader_version=0.14.14 -fabric_version=0.75.1+1.19.3 +loader_version=0.14.18 +fabric_version=0.70.0+1.19.3 maven_group=fr.altarik.toolbox maven_version=4.3.2-SNAPSHOT + +git_owner=quentinlegot +git_repo=Toolbox \ No newline at end of file -- 2.39.5 From 40768b2ec1b63984ab521d7b64b25a2816daf266 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 29 Aug 2023 22:50:21 +0200 Subject: [PATCH 2/7] Added Command and AbstractCommand --- .../toolbox/core/command/AbstractCommand.java | 15 +++++++++++++++ .../fr/altarik/toolbox/core/command/Command.java | 9 +++++++++ 2 files changed, 24 insertions(+) create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/command/AbstractCommand.java create mode 100644 Core/src/main/java/fr/altarik/toolbox/core/command/Command.java diff --git a/Core/src/main/java/fr/altarik/toolbox/core/command/AbstractCommand.java b/Core/src/main/java/fr/altarik/toolbox/core/command/AbstractCommand.java new file mode 100644 index 0000000..6ee5fc9 --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/command/AbstractCommand.java @@ -0,0 +1,15 @@ +package fr.altarik.toolbox.core.command; + +import com.mojang.brigadier.context.CommandContext; +import net.minecraft.server.command.ServerCommandSource; + +public abstract class AbstractCommand implements Command { + + protected final ServerCommandSource source; + protected final CommandContext context; + + protected AbstractCommand(CommandContext c) { + this.context = c; + this.source = c.getSource(); + } +} diff --git a/Core/src/main/java/fr/altarik/toolbox/core/command/Command.java b/Core/src/main/java/fr/altarik/toolbox/core/command/Command.java new file mode 100644 index 0000000..978cc79 --- /dev/null +++ b/Core/src/main/java/fr/altarik/toolbox/core/command/Command.java @@ -0,0 +1,9 @@ +package fr.altarik.toolbox.core.command; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +public interface Command { + + int run() throws CommandSyntaxException; + +} -- 2.39.5 From c09882007630325adfbb8b03f30d4e2431235b79 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 29 Aug 2023 22:50:56 +0200 Subject: [PATCH 3/7] Remove unnecessary semicolon --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 473f0ea..4272f1f 100644 --- a/build.gradle +++ b/build.gradle @@ -17,11 +17,11 @@ String webhookId = getEnv("DISCORD_PUB_ID", local.getProperty("discord_pub_id")) String webhookToken = getEnv("DISCORD_PUB_TOKEN", local.getProperty("discord_pub_token")) String repoUrl = "https://repo.altarik.fr/#/" + (project.version.endsWith('SNAPSHOT') ? 'snapshots/' : 'releases/') + project.group.replace(".", "/") + "/" + project.rootProject.name + "/" + project.version -var reportConfig = new ReportDiscord.ReportData("https://discord.com/api/", webhookId, webhookToken, project.rootProject.name, "Update " + project.version + " has been published", repoUrl); +var reportConfig = new ReportDiscord.ReportData("https://discord.com/api/", webhookId, webhookToken, project.rootProject.name, "Update " + project.version + " has been published", repoUrl) String giteaToken = getEnv("GITEA_TOKEN", local.getProperty("gitea_token")) -var releaseConfig = new CreateTag.CreateReleaseData("https://git.altarik.fr", project.git_owner, project.git_repo, "v" + project.version as String, giteaToken); +var releaseConfig = new CreateTag.CreateReleaseData("https://git.altarik.fr", project.git_owner, project.git_repo, "v" + project.version as String, giteaToken) allprojects { -- 2.39.5 From 59161400e8efcb4ee7832bf519da232639549955 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sat, 6 Jan 2024 21:42:25 +0100 Subject: [PATCH 4/7] Update to 1.20.2 --- Core/src/main/resources/fabric.mod.json | 4 +-- Database/src/main/resources/fabric.mod.json | 4 +-- Pagination/src/main/resources/fabric.mod.json | 4 +-- Tasks/src/main/resources/fabric.mod.json | 4 +-- build.gradle | 30 ++++++++----------- gradle.properties | 10 +++---- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/resources/fabric.mod.json | 4 +-- 8 files changed, 28 insertions(+), 34 deletions(-) diff --git a/Core/src/main/resources/fabric.mod.json b/Core/src/main/resources/fabric.mod.json index 2701d84..9b1c447 100644 --- a/Core/src/main/resources/fabric.mod.json +++ b/Core/src/main/resources/fabric.mod.json @@ -21,9 +21,9 @@ }, "mixins": [], "depends": { - "fabricloader": "^0.14.12", + "fabricloader": "^${loaderVersion}", "fabric-api": "*", - "minecraft": "1.19.3", + "minecraft": "${minecraftVersion}", "java": ">=17" } } diff --git a/Database/src/main/resources/fabric.mod.json b/Database/src/main/resources/fabric.mod.json index 586895e..3519334 100644 --- a/Database/src/main/resources/fabric.mod.json +++ b/Database/src/main/resources/fabric.mod.json @@ -21,9 +21,9 @@ }, "mixins": [], "depends": { - "fabricloader": "^0.14.12", + "fabricloader": "^${loaderVersion}", "fabric-api": "*", - "minecraft": "1.19.3", + "minecraft": "${minecraftVersion}", "java": ">=17", "toolbox-core": "${version}" } diff --git a/Pagination/src/main/resources/fabric.mod.json b/Pagination/src/main/resources/fabric.mod.json index 99cc965..9059bd5 100644 --- a/Pagination/src/main/resources/fabric.mod.json +++ b/Pagination/src/main/resources/fabric.mod.json @@ -25,9 +25,9 @@ "Pagination.mixins.json" ], "depends": { - "fabricloader": "^0.14.12", + "fabricloader": "^${loaderVersion}", "fabric-api": "*", - "minecraft": "1.19.3", + "minecraft": "${minecraftVersion}", "java": ">=17" } } diff --git a/Tasks/src/main/resources/fabric.mod.json b/Tasks/src/main/resources/fabric.mod.json index a03be36..588d0e3 100644 --- a/Tasks/src/main/resources/fabric.mod.json +++ b/Tasks/src/main/resources/fabric.mod.json @@ -25,9 +25,9 @@ "Task.mixins.json" ], "depends": { - "fabricloader": "^0.14.12", + "fabricloader": "^${loaderVersion}", "fabric-api": "*", - "minecraft": "1.19.3", + "minecraft": "${minecraftVersion}", "java": ">=17" } } diff --git a/build.gradle b/build.gradle index 047bbbe..da14354 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ import fr.altarik.ReportDiscord plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' apply false + id 'fabric-loom' version '1.4-SNAPSHOT' apply false } Properties local = new Properties() @@ -24,9 +24,6 @@ allprojects { group = project.maven_group version = project.maven_version - - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 repositories { maven { @@ -64,26 +61,17 @@ allprojects { processResources { inputs.property "version", project.version + inputs.property "minecraftVersion", project.minecraft_version + inputs.property "loaderVersion", project.loader_version filesMatching("fabric.mod.json") { - expand "version": project.version + expand inputs.properties } } tasks.withType(JavaCompile).configureEach { - // ensure that the encoding is set to UTF-8, no matter what the system default is - // this fixes some edge cases with special characters not displaying correctly - // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html - // If Javadoc is generated, this must be specified in that task too. it.options.encoding = "UTF-8" - - // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too - // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. - // We'll use that if it's available, but otherwise we'll use the older option. - def targetVersion = 17 - if (JavaVersion.current().isJava9Compatible()) { - it.options.release = targetVersion - } + it.options.release = 17 } dependencies { @@ -98,6 +86,9 @@ allprojects { java { withSourcesJar() withJavadocJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } test { @@ -107,8 +98,11 @@ allprojects { } dependencies { + implementation project(path: ":Core", configuration: "namedElements") + implementation project(path: ":Database", configuration: "namedElements") + implementation project(path: ":Pagination", configuration: "namedElements") + implementation project(path: ":Tasks", configuration: "namedElements") include subprojects.collect { project -> project } - implementation subprojects.collect { project -> project } } static def getEnv(String envName, String defaultValue) { diff --git a/gradle.properties b/gradle.properties index eafac93..1277719 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ -org.gradle.jvmargs=-Xmx3G +org.gradle.jvmargs=-Xmx1G fabric.loom.multiProjectOptimisation=true junit_version=5.9.0 -minecraft_version=1.19.3 -yarn_mappings=1.19.3+build.5 -loader_version=0.14.14 -fabric_version=0.75.1+1.19.3 +minecraft_version=1.20.2 +yarn_mappings=1.20.2+build.4 +loader_version=0.15.3 +fabric_version=0.91.3+1.20.2 maven_group=fr.altarik.toolbox maven_version=4.3.2-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 59bc51a..a595206 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ce07720..2d873b3 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -17,9 +17,9 @@ "icon": "assets/toolbox/icon.png", "environment": "*", "depends": { - "fabricloader": "^0.14.12", + "fabricloader": "^${loaderVersion}", "fabric-api": "*", - "minecraft": "1.19.3", + "minecraft": "${minecraftVersion}", "java": ">=17", "toolbox-core": "${version}", "toolbox-database": "${version}", -- 2.39.5 From 0c67018eda910b4b94c73017f61b64e77ce71827 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sat, 6 Jan 2024 21:44:15 +0100 Subject: [PATCH 5/7] Dump to 4.4.0 --- build.gradle | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index da14354..91290e9 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ String webhookId = getEnv("DISCORD_PUB_ID", local.getProperty("discord_pub_id")) String webhookToken = getEnv("DISCORD_PUB_TOKEN", local.getProperty("discord_pub_token")) String repoUrl = "https://repo.altarik.fr/#/" + (project.version.endsWith('SNAPSHOT') ? 'snapshots/' : 'releases/') + project.group.replace(".", "/") + "/" + project.rootProject.name + "/" + project.version -var reportConfig = new ReportDiscord.ReportData("https://discord.com/api/", webhookId, webhookToken, project.rootProject.name, "Update " + project.version + " has been published", repoUrl); +var reportConfig = new ReportDiscord.ReportData("https://discord.com/api/", webhookId, webhookToken, project.rootProject.name, "Update " + project.version + " has been published", repoUrl) allprojects { apply plugin: 'maven-publish' diff --git a/gradle.properties b/gradle.properties index 1277719..c206034 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,4 +8,4 @@ loader_version=0.15.3 fabric_version=0.91.3+1.20.2 maven_group=fr.altarik.toolbox -maven_version=4.3.2-SNAPSHOT +maven_version=4.4.0 -- 2.39.5 From 6276ba58d7399f934f798000319724aa05c871de Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sat, 6 Jan 2024 22:13:05 +0100 Subject: [PATCH 6/7] Update .gitea/workflows/ci.yml --- .gitea/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 713ffe2..6f69810 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: java: [ '17' ] os: [ ubuntu-latest ] runs-on: ${{ matrix.os }} - if: gitea.ref == 'refs/heads/master' + if: gitea.ref == 'refs/heads/master' && gitea.event_name == 'push' needs: build steps: - name: checkout repository -- 2.39.5 From 4731cc5698d420a0bd00063d059c3b3e6a48cfb0 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sat, 6 Jan 2024 22:28:57 +0100 Subject: [PATCH 7/7] Update .gitea/workflows/ci.yml --- .gitea/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 6f69810..8fd4b8e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: java: [ '17' ] os: [ ubuntu-latest ] runs-on: ${{ matrix.os }} - if: gitea.ref == 'refs/heads/master' && gitea.event_name == 'push' + if: ${{ gitea.ref == 'refs/heads/master' && gitea.event_name == 'push' }} needs: build steps: - name: checkout repository -- 2.39.5