diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 207457b36f..93b736afd0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,8 +28,9 @@ jobs: token: ${{ secrets.github_token }} prefix: ${{ github.ref }} - - run: ./gradlew build javadocJar publish --stacktrace + - run: ./gradlew build javadocJar checkVersion publish --stacktrace env: MAVEN_URL: ${{ secrets.MAVEN_URL }} MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + VALIDATE_BRANCH: true diff --git a/build.gradle b/build.gradle index e68a33c897..c2b305d8f3 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ plugins { id 'java' // for jd gen id 'org.cadixdev.licenser' version '0.5.1' id 'net.fabricmc.filament' version '0.2.0' + id "org.ajoberstar.grgit" version "4.1.0" } def minecraft_version = "21w17a" @@ -35,6 +36,13 @@ def build_number = ENV.BUILD_NUMBER ?: "local" def yarnVersion = "${minecraft_version}+build.$build_number" version = yarnVersion +if (ENV.VALIDATE_BRANCH) { + def branch = grgit.branch.current().name + if (minecraft_version != branch) { + throw new IllegalStateException("Branch name (${branch}) does not match the mc version (${minecraft_version})") + } +} + repositories { mavenCentral() maven { @@ -1037,6 +1045,20 @@ publishing { } } +// A task to ensure that the version being released has not already been released. +task checkVersion { + doFirst { + def xml = new URL("https://maven.fabricmc.net/net/fabricmc/yarn/maven-metadata.xml").text + def metadata = new XmlSlurper().parseText(xml) + def versions = metadata.versioning.versions.version*.text(); + if (versions.contains(version)) { + throw new RuntimeException("${version} has already been released!") + } + } +} + +publish.mustRunAfter checkVersion + void mapJar(File output, File input, File mappings, File libraries, String from, String to, Action action = { }) { if (output.exists()) {