diff options
author | makamys <makamys@outlook.com> | 2022-06-04 09:31:42 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-04 09:33:13 +0200 |
commit | 24204cfdc91a9ecc5e0012d9f256a7e72f541d64 (patch) | |
tree | 233971dbe560cb416eaa0646c7bf38853daabc1b /publish | |
parent | b0f7f36a0b26f8ae0f6c238ae1a11f68d20efa1c (diff) | |
download | Neodymium-24204cfdc91a9ecc5e0012d9f256a7e72f541d64.tar.gz Neodymium-24204cfdc91a9ecc5e0012d9f256a7e72f541d64.tar.bz2 Neodymium-24204cfdc91a9ecc5e0012d9f256a7e72f541d64.zip |
Migrate to generic buildscript
Diffstat (limited to 'publish')
-rw-r--r-- | publish/.gitignore | 2 | ||||
-rw-r--r-- | publish/README.txt | 2 | ||||
-rw-r--r-- | publish/build.gradle | 158 | ||||
-rw-r--r-- | publish/build_and_release.sh | 43 | ||||
-rw-r--r-- | publish/curseforge_all.sh | 3 | ||||
-rw-r--r-- | publish/gameVersions.json | 3 | ||||
-rw-r--r-- | publish/gradle.properties | 10 | ||||
-rw-r--r-- | publish/gradle/wrapper/gradle-wrapper.jar | bin | 0 -> 52271 bytes | |||
-rw-r--r-- | publish/gradle/wrapper/gradle-wrapper.properties | 6 | ||||
-rw-r--r-- | publish/gradlew | 164 | ||||
-rw-r--r-- | publish/gradlew.bat | 90 | ||||
-rw-r--r-- | publish/modrinth_all.sh | 3 | ||||
-rw-r--r-- | publish/prepare_publish.py | 3 | ||||
-rw-r--r-- | publish/update_updatejson.py | 25 | ||||
-rw-r--r-- | publish/version.txt | 1 |
15 files changed, 513 insertions, 0 deletions
diff --git a/publish/.gitignore b/publish/.gitignore new file mode 100644 index 0000000..cfeecb5 --- /dev/null +++ b/publish/.gitignore @@ -0,0 +1,2 @@ +changelog.md +gameVersions.txt
\ No newline at end of file diff --git a/publish/README.txt b/publish/README.txt new file mode 100644 index 0000000..b429284 --- /dev/null +++ b/publish/README.txt @@ -0,0 +1,2 @@ +# How to publish +sh ./build_and_release.sh $GITHUB_TOKEN [$CURSEFORGE_TOKEN] [$MODRINTH_TOKEN]
\ No newline at end of file diff --git a/publish/build.gradle b/publish/build.gradle new file mode 100644 index 0000000..85425aa --- /dev/null +++ b/publish/build.gradle @@ -0,0 +1,158 @@ +plugins { + id "com.github.breadmoirai.github-release" version "2.2.12" + id "com.matthewprenger.cursegradle" version "1.4.0" + id "com.modrinth.minotaur" version "1.2.1" +} + +import com.modrinth.minotaur.TaskModrinthUpload +import groovy.json.JsonSlurper +import okhttp3.OkHttpClient +import java.util.concurrent.TimeUnit + +def buildVersion = new File("${projectDir}/version.txt").getText('UTF-8').trim() +def changeLog = new File("${projectDir}/changelog.md").getText('UTF-8') +def gameVersionsMap = new JsonSlurper().parseText(file("gameVersions.json").getText('UTF-8')) +ext.gameVersions = gameVersionsMap.keySet() + +def githubOK = project.hasProperty("githubToken") +def curseOK = project.hasProperty("curseToken") && project.hasProperty("gameVersion") +def modrinthOK = project.hasProperty("modrinthToken") && project.hasProperty("gameVersion") + +def debugPublish = project.hasProperty("debugPublish") && project.debugPublish.toBoolean() + +task build {} +task assemble {} + +if(githubOK){ + githubRelease { + token project.githubToken // This is your personal access token with Repo permissions + // You get this from your user settings > developer settings > Personal Access Tokens + owner project.githubOwner // default is the last part of your group. Eg group: "com.github.breadmoirai" => owner: "breadmoirai" + repo project.githubRepo // by default this is set to your project name + tagName "v${buildVersion}" // by default this is set to "v${project.version}" + targetCommitish "master" // by default this is set to "master" + releaseName "${project.releaseName} ${buildVersion}" + body changeLog // by default this is empty + draft false // by default this is false + prerelease false // by default this is false + releaseAssets getFiles() // this points to which files you want to upload as assets with your release + + overwrite false // by default false; if set to true, will delete an existing release with the same tag and name + dryRun debugPublish // by default false; you can use this to see what actions would be taken without making a release + apiEndpoint "https://api.github.com" // should only change for github enterprise users + client new OkHttpClient.Builder() + .writeTimeout(5, TimeUnit.MINUTES) + .readTimeout(5, TimeUnit.MINUTES) + .build() // Added because I kept getting SocketTimeoutExceptions + } +} else { + println("Not configuring GitHub publish because project arguments are missing.") +} + +if(project.hasProperty("gameVersion")){ + def gameVersion = project.gameVersion + def baseVersion = toBaseVersion(gameVersion) + def files = getFiles(baseVersion) + def shortest = null + files.each { + if(shortest == null || it.name.length() < shortest.name.length()){ + shortest = it + } + } + def additionalFiles = files - shortest + + if(curseOK) { + curseforge { + apiKey = project.curseToken + project { + id = project.curseID + changelogType = 'markdown' + changelog = changeLog + releaseType = 'release' + addGameVersion gameVersion + addGameVersion "Forge" + + mainArtifact(file(shortest)) { + displayName = "${releaseName} ${buildVersion} for Minecraft ${gameVersion}" + } + additionalFiles.each { addArtifact(it) } + } + options { + debug = debugPublish + javaIntegration = false + forgeGradleIntegration = false + javaVersionAutoDetect = false + } + } + } else { + println("Not configuring CurseForge publish because project arguments are missing.") + } + + if(modrinthOK) { + task publishModrinth (type: TaskModrinthUpload) { + token = project.modrinthToken + projectId = project.modrinthID + versionNumber = "$gameVersion-$buildVersion" + versionName = "$gameVersion-$buildVersion" // the doc says this defaults to the versionNumber, but it defaulted to the string "undefined" for me so i'm setting it + uploadFile = shortest + addGameVersion(gameVersion) + additionalFiles.each { addFile(it) } + addLoader('forge') + changelog = changeLog + detectLoaders = false + } + } else { + println("Not configuring Modrinth publish because project arguments are missing.") + } +} + +def toBaseVersion(ver){ + return String.join(".", ver.tokenize(".").subList(0, 2)) +} + +def getVersionProjectPath(ver){ + if(project.versionedProjectDirectories.toBoolean()){ + return "${projectDir}/../${ver}" + } else { + return "${projectDir}/.." + } +} + +def getFiles(ver) { + def files = [] + new File("${getVersionProjectPath(ver)}/build/libs").eachFile(groovy.io.FileType.FILES, { + if(!(it.name.endsWith("-sources.jar") || it.name.endsWith("-dev.jar"))){ + files << it + } + }) + return files +} + +def getFiles() { + def files = [] + project.gameVersions.collect({toBaseVersion(it)}).each { + files += getFiles(it) + } + return files +} + +// for debug +task listFiles { + doLast { + project.gameVersions.collect({toBaseVersion(it)}).each { + println("$it: ${getFiles(it)}") + } + } +} + +project.gameVersions.collect({toBaseVersion(it)}).each { ver -> + def dir = getVersionProjectPath(ver) + task ("cleanBuild-$ver", type: Exec) { + workingDir dir + commandLine 'sh', '-c', "rm -f build/libs/* && ./gradlew build" + } +} + +task cleanBuildAll(dependsOn: project.gameVersions.collect({"cleanBuild-${toBaseVersion(it)}"})) { + +}
\ No newline at end of file diff --git a/publish/build_and_release.sh b/publish/build_and_release.sh new file mode 100644 index 0000000..5ab7fe0 --- /dev/null +++ b/publish/build_and_release.sh @@ -0,0 +1,43 @@ +if [ ! -s changelog.md ]; then + echo "Changelog is empty, refusing to publish." + exit 3 +fi + +if [[ $(git diff --cached --stat) != '' ]] +then + echo "There are staged uncommitted changes, refusing to publish." + exit 2 +fi + +if [ "$#" -lt 1 ] || [ "$#" -gt 3 ] +then + echo "Usage: $0 GITHUB_TOKEN CURSEFORGE_TOKEN [MODRINTH_TOKEN]" + exit 1 +fi + +# exit when any command fails +set -e + +GITHUB_TOKEN=$1 +CURSEFORGE_TOKEN=$2 +MODRINTH_TOKEN=$3 + +# build the release +./gradlew cleanBuildAll + +# release +py prepare_publish.py +./gradlew githubRelease -PgithubToken=$GITHUB_TOKEN +py update_updatejson.py + +if [ -n "$CURSEFORGE_TOKEN" ] +then + ./curseforge_all.sh -PcurseToken=$CURSEFORGE_TOKEN +fi + +/dev/null > changelog.md + +if [ -n "$MODRINTH_TOKEN" ] +then + ./modrinth_all.sh -PmodrinthToken=$MODRINTH_TOKEN +fi
\ No newline at end of file diff --git a/publish/curseforge_all.sh b/publish/curseforge_all.sh new file mode 100644 index 0000000..280911d --- /dev/null +++ b/publish/curseforge_all.sh @@ -0,0 +1,3 @@ +for proj in `cat gameVersions.txt`; do + ./gradlew curseforge -PgameVersion=$proj $* +done
\ No newline at end of file diff --git a/publish/gameVersions.json b/publish/gameVersions.json new file mode 100644 index 0000000..39f71f6 --- /dev/null +++ b/publish/gameVersions.json @@ -0,0 +1,3 @@ +{ + "1.7.10": {} +}
\ No newline at end of file diff --git a/publish/gradle.properties b/publish/gradle.properties new file mode 100644 index 0000000..2f104f6 --- /dev/null +++ b/publish/gradle.properties @@ -0,0 +1,10 @@ +githubOwner= +githubRepo= + +curseID= +modrinthID= + +releaseName= + +versionedProjectDirectories=false +updateJsonFullVersionFormat=false
\ No newline at end of file diff --git a/publish/gradle/wrapper/gradle-wrapper.jar b/publish/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 0000000..30d399d --- /dev/null +++ b/publish/gradle/wrapper/gradle-wrapper.jar diff --git a/publish/gradle/wrapper/gradle-wrapper.properties b/publish/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..22ad9ab --- /dev/null +++ b/publish/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Sep 14 12:28:28 PDT 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip diff --git a/publish/gradlew b/publish/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/publish/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/publish/gradlew.bat b/publish/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/publish/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/publish/modrinth_all.sh b/publish/modrinth_all.sh new file mode 100644 index 0000000..80d68db --- /dev/null +++ b/publish/modrinth_all.sh @@ -0,0 +1,3 @@ +for proj in `cat gameVersions.txt`; do + ./gradlew publishModrinth -PgameVersion=$proj $* +done
\ No newline at end of file diff --git a/publish/prepare_publish.py b/publish/prepare_publish.py new file mode 100644 index 0000000..50e799c --- /dev/null +++ b/publish/prepare_publish.py @@ -0,0 +1,3 @@ +import json + +open("gameVersions.txt", "w").write(" ".join(json.load(open("gameVersions.json", "r")).keys()))
\ No newline at end of file diff --git a/publish/update_updatejson.py b/publish/update_updatejson.py new file mode 100644 index 0000000..8d751e5 --- /dev/null +++ b/publish/update_updatejson.py @@ -0,0 +1,25 @@ +import json +import subprocess + +jsonPath = "../updatejson/update.json" + +# lol +fullFormat = "updateJsonFullVersionFormat=true" in open("gradle.properties", "r", encoding="utf8").read() + +data = json.load(open(jsonPath, "r", encoding="utf8")) +ver = open("version.txt", "r").read().strip() + +for gameVer in json.load(open("gameVersions.json", "r")).keys(): + modVer = "{}".format(ver) if not fullFormat else "{}-{}".format(gameVer, ver) + + if gameVer not in data: + data[gameVer] = {} + + data[gameVer][modVer] = "" + data["promos"]["{}-latest".format(gameVer)] = modVer + +json.dump(data, open(jsonPath, "w", encoding="utf8"), indent=2) + +subprocess.run(["git", "add", jsonPath]) +subprocess.run(["git", "commit", "-m", "[skip ci] Update update json"]) +subprocess.run(["git", "push"])
\ No newline at end of file diff --git a/publish/version.txt b/publish/version.txt new file mode 100644 index 0000000..171538e --- /dev/null +++ b/publish/version.txt @@ -0,0 +1 @@ +0.0
\ No newline at end of file |