Improve CI: now create a tag when publishing a new release
This commit is contained in:
parent
3d3851d032
commit
10edfe5ef6
@ -3,7 +3,7 @@
|
|||||||
# certain platforms or Java versions, and provides a first line of defence
|
# certain platforms or Java versions, and provides a first line of defence
|
||||||
# against bad commits.
|
# against bad commits.
|
||||||
|
|
||||||
name:
|
name: Test and Deploy
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master, dev ]
|
branches: [ master, dev ]
|
||||||
@ -39,9 +39,7 @@ jobs:
|
|||||||
chmod +x ./gradlew
|
chmod +x ./gradlew
|
||||||
touch local.properties
|
touch local.properties
|
||||||
- name: build
|
- name: build
|
||||||
run: ./gradlew build --no-daemon --max-workers 1
|
run: ./gradlew build # compile classes, testClasses, assemble in jar and javadocJar, and then test
|
||||||
#- name: test
|
|
||||||
# run: ./gradlew test --no-daemon
|
|
||||||
deploy:
|
deploy:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
@ -66,7 +64,9 @@ jobs:
|
|||||||
chmod +x ./gradlew
|
chmod +x ./gradlew
|
||||||
touch local.properties
|
touch local.properties
|
||||||
- name: deploy
|
- name: deploy
|
||||||
run: |
|
run: ./gradlew publish
|
||||||
./gradlew publish
|
- name: create tag
|
||||||
./gradlew reportToDiscord
|
run: ./gradlew createTag
|
||||||
|
- name: Report to Discord
|
||||||
|
run: ./gradlew reportToDiscord
|
||||||
|
|
15
build.gradle
15
build.gradle
@ -1,7 +1,8 @@
|
|||||||
|
import fr.altarik.CreateTag
|
||||||
import fr.altarik.ReportDiscord
|
import fr.altarik.ReportDiscord
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '1.2-SNAPSHOT' apply false
|
id 'fabric-loom' version '1.3-SNAPSHOT' apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
Properties local = new Properties()
|
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);
|
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 {
|
allprojects {
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
apply plugin: 'fabric-loom'
|
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.
|
// We'll use that if it's available, but otherwise we'll use the older option.
|
||||||
def targetVersion = 17
|
def targetVersion = 17
|
||||||
if (JavaVersion.current().isJava9Compatible()) {
|
if (JavaVersion.current().isJava9Compatible()) {
|
||||||
it.options.release = targetVersion
|
it.options.release.set(targetVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +130,11 @@ tasks.register("reportToDiscord", ReportDiscord) {
|
|||||||
config.set(reportConfig)
|
config.set(reportConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.register("createTag", CreateTag) {
|
||||||
|
config.set(releaseConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*jar {
|
/*jar {
|
||||||
dependsOn subprojects.jar
|
dependsOn subprojects.jar
|
||||||
subprojects.each { project ->
|
subprojects.each { project ->
|
||||||
|
48
buildSrc/src/main/java/fr/altarik/CreateTag.java
Normal file
48
buildSrc/src/main/java/fr/altarik/CreateTag.java
Normal file
@ -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<CreateReleaseData> 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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -4,8 +4,11 @@ fabric.loom.multiProjectOptimisation=true
|
|||||||
junit_version=5.9.0
|
junit_version=5.9.0
|
||||||
minecraft_version=1.19.3
|
minecraft_version=1.19.3
|
||||||
yarn_mappings=1.19.3+build.5
|
yarn_mappings=1.19.3+build.5
|
||||||
loader_version=0.14.14
|
loader_version=0.14.18
|
||||||
fabric_version=0.75.1+1.19.3
|
fabric_version=0.70.0+1.19.3
|
||||||
|
|
||||||
maven_group=fr.altarik.toolbox
|
maven_group=fr.altarik.toolbox
|
||||||
maven_version=4.3.2-SNAPSHOT
|
maven_version=4.3.2-SNAPSHOT
|
||||||
|
|
||||||
|
git_owner=quentinlegot
|
||||||
|
git_repo=Toolbox
|
Loading…
Reference in New Issue
Block a user