diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..f8cee6e --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,38 @@ +name: deploy +description: Deploy artifact to maven repo +on: + push: + branches: [ master ] +env: + REPO_USERNAME: Altarik + REPO_PASSWORD: ${{ secrets.REPO_PASSWORD }} + DISCORD_PUB_ID: ${{ secrets.DISCORD_PUB_ID }} + DISCORD_PUB_TOKEN: ${{ secrets.DISCORD_PUB_TOKEN }} + +jobs: + deploy: + runs-on: ubuntu-latest + # if: gitea.ref == 'refs/heads/main' + steps: + - name: checkout repository + uses: actions/checkout@v3 + - name: validate gradle wrapper + uses: https://github.com/gradle/wrapper-validation-action@v1 + - name: setup jdk + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'oracle' + - name: make gradle wrapper executable + if: ${{ runner.os != 'Windows' }} + run: | + chmod +x ./gradlew + touch local.properties + - name: deploy + run: ./gradlew publish + - name: create tag + run: ./gradlew createTag + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + - name: report to discord + run: ./gradlew reportToDiscord \ No newline at end of file diff --git a/.github/workflows/AAAAAHHHHHHHHHHH!!!!!!!!.yml b/.github/workflows/AAAAAHHHHHHHHHHH!!!!!!!!.yml deleted file mode 100644 index bf43bad..0000000 --- a/.github/workflows/AAAAAHHHHHHHHHHH!!!!!!!!.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: AAAAHHHHHHHHHHHH!!!!!!!!!! - -on: [push, pull_request, workflow_dispatch] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '17' - - - uses: gradle/wrapper-validation-action@v1 - - - uses: gradle/gradle-build-action@v2.4.2 - with: - arguments: clean build - - - uses: actions/upload-artifact@v3 - with: - name: AHHHHHHHHHHH!!!!!!!!!! - path: build/libs \ No newline at end of file diff --git a/.gitignore b/.gitignore index 39db14c..54a7985 100755 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Compiled nonsense that does not belong in *source* control /build /bin -/.gradle +.gradle /minecraft /out /run @@ -32,5 +32,4 @@ local.properties *.png~ *-autosave.kra *.kra~ -/gradle/ /src/generated/ diff --git a/build.gradle b/build.gradle index 15c5468..37b1448 100755 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,33 @@ +import fr.altarik.ReportDiscord +import fr.altarik.CreateTag + + plugins { id 'fabric-loom' version '1.5-SNAPSHOT' id 'maven-publish' } + +Properties local = new Properties() +try { + local.load(new FileInputStream(rootProject.file("local.properties"))) +} catch (IOException ignored) {} + version = project.mod_version group = project.maven_group + +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) + +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) + + base { archivesName = project.archives_base_name } @@ -36,6 +58,16 @@ loom { } repositories { + maven { + name 'altarik-snapshots' + url 'https://repo.altarik.fr/snapshots/' + } + maven { + name 'altarik-releases' + url 'https://repo.altarik.fr/releases/' + } + mavenCentral() + // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. @@ -58,13 +90,11 @@ processResources { inputs.property "version", project.version inputs.property "minecraft_version", project.minecraft_version inputs.property "loader_version", project.loader_version + inputs.property "mod_id", project.mod_id filteringCharset "UTF-8" filesMatching("fabric.mod.json") { - expand "version": project.version, - "mod_id": mod_id, - "minecraft_version": project.minecraft_version, - "loader_version": project.loader_version + expand inputs.properties } } @@ -81,6 +111,9 @@ tasks.withType(JavaCompile).configureEach { } java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + def javaVersion = JavaVersion.toVersion(targetJavaVersion) if (JavaVersion.current() < javaVersion) { toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) @@ -111,5 +144,32 @@ publishing { // Notice: This block does NOT have the same function as the block in the top level. // The repositories here will be used for publishing your artifact, not for // retrieving dependencies. + maven { + name 'altarik' + url 'https://repo.altarik.fr/'.concat(project.version.endsWith('SNAPSHOT') ? 'snapshots/' : 'releases/') + credentials { + username = getEnv("REPO_USERNAME", local.getProperty("repo_username")) + password = getEnv("REPO_PASSWORD", local.getProperty("repo_password")) + } + } + } } + +tasks.register("reportToDiscord", ReportDiscord) { + config.set(reportConfig) +} + +tasks.register("createTag", CreateTag) { + config.set(releaseConfig) +} + +static def getEnv(String envName, String defaultValue) { + String r = System.getenv(envName) + if(r != null) { + return r + } else { + return defaultValue + } +} + diff --git a/buildSrc/.gitignore b/buildSrc/.gitignore new file mode 100644 index 0000000..f8b92c3 --- /dev/null +++ b/buildSrc/.gitignore @@ -0,0 +1,2 @@ +.gradle +build diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000..3a31fad --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,11 @@ +plugins { + id 'java' +} + +dependencies { + implementation "com.squareup.okhttp3:okhttp:${project.okhttp_version}" +} + +repositories { + mavenCentral() +} \ No newline at end of file diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties new file mode 100644 index 0000000..11df63b --- /dev/null +++ b/buildSrc/gradle.properties @@ -0,0 +1 @@ +okhttp_version=4.12.0 \ No newline at end of file diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle new file mode 100644 index 0000000..bc2d8d1 --- /dev/null +++ b/buildSrc/settings.gradle @@ -0,0 +1,7 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } +} +rootProject.name = "buildSrc" \ No newline at end of file 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..58cc66a --- /dev/null +++ b/buildSrc/src/main/java/fr/altarik/CreateTag.java @@ -0,0 +1,47 @@ +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/buildSrc/src/main/java/fr/altarik/ReportDiscord.java b/buildSrc/src/main/java/fr/altarik/ReportDiscord.java new file mode 100644 index 0000000..3879bbb --- /dev/null +++ b/buildSrc/src/main/java/fr/altarik/ReportDiscord.java @@ -0,0 +1,56 @@ +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 ReportDiscord extends DefaultTask { + + public static final MediaType JSON = MediaType.get("application/json; charset=utf-8"); + + @Input + public abstract Property getConfig(); + + private final OkHttpClient client = new OkHttpClient(); + + @TaskAction + public void report() throws IOException { + ReportData data = getConfig().get(); + String message = data.message(); + RequestBody body = RequestBody.create(""" + { + "embeds": [ + { + "title": "A new update of\s""" + data.projectName() + """ + is available", + "description":\s""" + "\"" + message + "\"" + """ + , + "url":\s""" + "\"" + data.url() + "\"" + """ + } + ] + } + """, JSON); + + String url = data.baseUrl() + "/webhooks/" + data.webhookId + "/" + data.webhookToken; + Request request = new Request.Builder() + .url(url) + .post(body) + .build(); + try(Response response = client.newCall(request).execute()) { + getLogger().info("report sent"); + if(!response.isSuccessful()) { + throw new GradleException("Discord returned a " + response.code() + " code: " + response.message()); + } + } + } + + public record ReportData(String baseUrl, String webhookId, String webhookToken, String projectName, String message, String url) { + + } + +} diff --git a/gradle.properties b/gradle.properties index 0009bf7..374e46b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,7 @@ mod_id = reframed # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.95.4+1.20.4 \ No newline at end of file +fabric_version=0.95.4+1.20.4 + +git_owner=Altarik +git_repo=ReFramed diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7f93135 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a80b22c --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 397963f..6f73f88 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,8 +26,8 @@ "reframed.mixins.json" ], "depends": { - "minecraft": ">=${minecraft_version}", - "fabricloader": "${loader_version}", + "minecraft": "${minecraft_version}", + "fabricloader": "^${loader_version}", "fabric-api": "*" } } \ No newline at end of file