diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..ccdadb2a5 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,31 @@ +name: Publish to Maven Repository + +on: + push: + branches: + - new_assets + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up JDK + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: '17' + + - name: Make Gradlew Executable + run: chmod +x ./gradlew + + - name: Build and Publish + run: | + ./gradlew publish + + env: + MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }} + MAVEN_REPO_PASSWORD: ${{ secrets.MAVEN_REPO_PASSWORD }} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4053f6afe..6b96168d9 100644 --- a/build.gradle +++ b/build.gradle @@ -21,13 +21,31 @@ subprojects { } } +def gitHash = { -> + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-parse', '--short', 'HEAD' + standardOutput = stdout + } + return stdout.toString().trim() +} + +def gitBranch() { + def branch = "" + def proc = "git rev-parse --abbrev-ref HEAD".execute() + proc.in.eachLine { line -> branch = line } + proc.err.eachLine { line -> println line } + proc.waitFor() + branch +} + allprojects { apply plugin: "java" apply plugin: "architectury-plugin" apply plugin: "maven-publish" archivesBaseName = rootProject.jar_name - version = "${rootProject.minecraft_version}-${rootProject.mod_version}" + version = "${rootProject.minecraft_version}-${rootProject.mod_version}-${gitHash()}-${gitBranch()}" group = rootProject.maven_group repositories { diff --git a/common/build.gradle b/common/build.gradle index 741b7eb39..aae879a79 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -23,13 +23,13 @@ architectury { publishing { publications { mavenCommon(MavenPublication) { - artifactId = rootProject.archives_base_name + artifactId = archives_base_name + "_" + project.name from components.java } } // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. repositories { - // Add repositories to publish to here. + } } \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle index 707f91978..e5c5f506d 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -152,13 +152,19 @@ components.java { publishing { publications { mavenFabric(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.name + artifactId = archives_base_name + "_" + project.name from components.java } } // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. repositories { - // Add repositories to publish to here. + maven { + url = project.findProperty("maven_repo_url") ?: "https://maven.craig.software/repository/whocraft/" + credentials { + username = project.findProperty("MAVEN_REPO_USERNAME") ?: System.getenv("MAVEN_REPO_USERNAME") ?: "" + password = project.findProperty("MAVEN_REPO_PASSWORD") ?: System.getenv("MAVEN_REPO_PASSWORD") ?: "" + } + } } } \ No newline at end of file diff --git a/forge/build.gradle b/forge/build.gradle index 809c5e062..08937c5b0 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -132,13 +132,19 @@ components.java { publishing { publications { mavenForge(MavenPublication) { - artifactId = archives_base_name + "-" + project.name + artifactId = archives_base_name + "_" + project.name from components.java } } // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. repositories { - // Add repositories to publish to here. + maven { + url = project.findProperty("maven_repo_url") ?: "https://maven.craig.software/repository/whocraft/" + credentials { + username = project.findProperty("MAVEN_REPO_USERNAME") ?: System.getenv("MAVEN_REPO_USERNAME") ?: "" + password = project.findProperty("MAVEN_REPO_PASSWORD") ?: System.getenv("MAVEN_REPO_PASSWORD") ?: "" + } + } } } \ No newline at end of file