Skip to content

Commit 0459532

Browse files
authored
Implement GTNH daily build support (#4190)
Co-authored-by: SgtMate <SgtMate@users.noreply.github.com>
1 parent 99d4481 commit 0459532

2 files changed

Lines changed: 100 additions & 29 deletions

File tree

‎docs/types-and-platforms/mod-platforms/gtnh.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Configuration options with defaults:
1212

1313
## Set Modpack version
1414

15-
As GTNH is a Minecraft 1.7.10 modpack, when using it your minecraft version is set to 1.7.10 by default. The [modpack version](https://www.gtnewhorizons.com/downloads/) can be selected by setting `GTNH_PACK_VERSION` to `latest`, `latest-dev` or any specific version number. `latest` will automatically select the latest full release version available and deploy the server with it (Note: this will also automatically update the server on startup). `latest-dev` does the same but selects the latest version marked as beta or RC (it won't select a full release version even if a newer exist). The third (and recommended) option is setting the server to a specific version like `2.8.1` to manage updates manually.
15+
As GTNH is a Minecraft 1.7.10 modpack, when using it your minecraft version is set to 1.7.10 by default. The [modpack version](https://www.gtnewhorizons.com/downloads/) can be selected by setting `GTNH_PACK_VERSION` to `latest`, `latest-beta` (formerly `latest-dev`) or any specific version number. `latest` will automatically select the latest full release version available and deploy the server with it (Note: this will also automatically update the server on startup). `latest-beta` does the same but selects the latest version marked as beta or RC (it won't select a full release version even if a newer exist). The third (and recommended) option is setting the server to a specific version like `2.8.1` to manage updates manually.
1616

1717
> To actively prevent an update from happening you can set the environment variable `SKIP_GTNH_UPDATE_CHECK` to true this will prevent any update check from running, but will also prevent the server install from running, so just set it after the initial setup.
1818
@@ -52,3 +52,11 @@ To deliver the intended GTNH by default, when running a GTNH server, the followi
5252
With java 17+ the server starts with `-Dfml.readTimeout=180 @java9args.txt -jar lwjgl3ify-forgePatches.jar`.
5353

5454
With java 8 the server stars with `-XX:+UseStringDeduplication -XX:+UseCompressedOops -XX:+UseCodeCacheFlushing -Dfml.readTimeout=180 -jar forge-1.7.10-10.13.4.1614-1.7.10-universal.jar`
55+
56+
## Developer Versions
57+
58+
To run the nightly developer builds of GTNH, set the environment variable `GTNH_USE_DAILY_BUILD` to true and set `GTNH_PACK_VERSION` either to `latest` or a specific run ID of the build workflow. The run ID can be found in the [GTNH GitHub Actions](https://github.com/GTNewHorizons/DreamAssemblerXXL/actions) page of the DreamAssemblerXXL repository. The run ID is the number in the URL of the workflow run, for example `123456789`.
59+
60+
Since downloads require authentication, you will also need to set the environment variable `GH_TOKEN` to a valid GitHub Personal Access Token with `public_repo` scope. You can create a token in your [GitHub settings](https://github.com/settings/tokens) page. Be sure to keep your token secret and do not share it with anyone. The token is only used to download the developer builds and is not stored anywhere in the server (except in the environment variables).
61+
62+
Keep in mind that developer builds are not stable and may contain bugs or incomplete features. Use them at your own risk. It is recommended to use the latest stable release for production servers!

‎scripts/start-deployGTNH‎

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
function getGTNHdownloadPath(){
88
gtnh_download_path=""
99
local release_object=""
10-
local current_java_version=""
11-
current_java_version=$(mc-image-helper java-release)
1210

1311
# Select release JSON object
14-
if [ "$GTNH_PACK_VERSION" == "latest-dev" ]; then
12+
# latest-dev will be removed in the future, but is still supported for now.
13+
if [ "$GTNH_PACK_VERSION" == "latest-dev" ] || [ "$GTNH_PACK_VERSION" == "latest-beta" ]; then
14+
if [ "$GTNH_PACK_VERSION" == "latest-dev" ]; then
15+
logWarning "GTNH_PACK_VERSION=latest-dev is deprecated and will be removed in the future."
16+
fi
1517
if ! release_object="$(
1618
curl -fsSL "https://downloads.gtnewhorizons.com/versions.json" \
1719
| jq -r '(.versions // .)|to_entries|sort_by(.value.releaseDate)|map(select(.value.title=="Beta release"))|.[-1]'
@@ -46,23 +48,18 @@ function getGTNHdownloadPath(){
4648
fi
4749

4850
# Select compatible server files for java version
49-
if (( current_java_version == 8 )); then
51+
if (( java_version == 8 )); then
5052
gtnh_download_path=$(jq -r '.value.server.java8Url' <<< "$release_object")
5153
log "Use GTNH Server Java 8 release."
5254

53-
elif (( current_java_version >= 17 )); then
54-
if (( current_java_version > $(jq '.value.maxJavaVersion' <<< "$release_object") )); then
55-
logError "Container Java version $current_java_version is not supported by GTNH. Try an older release."
55+
elif (( java_version >= 17 )); then
56+
if (( java_version > $(jq '.value.maxJavaVersion' <<< "$release_object") )); then
57+
logError "Container Java version $java_version is not supported by GTNH. Try an older release."
5658
exit 1
5759
fi
5860

5961
gtnh_download_path=$(jq -r '.value.server.java17_2XUrl' <<< "$release_object")
6062
log "Use GTNH Server Java 17+ release."
61-
62-
else
63-
logError "Container Java version $current_java_version is not supported by GTNH."
64-
exit 1
65-
6663
fi
6764

6865
if [[ -z $gtnh_download_path ]]; then
@@ -73,6 +70,56 @@ function getGTNHdownloadPath(){
7370

7471
}
7572

73+
function getGTNHdownloadOptions(){
74+
# Used for GTNH daily build downloads, to pass additional options to the download command.
75+
gtnh_download_options=()
76+
# Used for dryrun check
77+
gtnh_download_path=""
78+
79+
# Check if GH_TOKEN is set for daily builds
80+
if [ -z "$GH_TOKEN" ]; then
81+
logError "GH_TOKEN environment variable must be set to use daily builds."
82+
exit 1
83+
fi
84+
85+
gtnh_download_options+=( --output-filename )
86+
87+
# prepare download options as an array to safely append patterns
88+
if [ "$GTNH_PACK_VERSION" == "latest" ] || [ "$GTNH_PACK_VERSION" == "latest-dev" ]; then
89+
if [ "$GTNH_PACK_VERSION" == "latest-dev" ]; then
90+
logWarning "GTNH_PACK_VERSION=latest-dev is deprecated and will be removed in the future."
91+
fi
92+
gtnh_download_options+=( --workflow=daily-modpack-build.yml )
93+
log "Using latest daily build for GTNH server files."
94+
elif [ "$GTNH_PACK_VERSION" == "latest-beta" ]; then
95+
gtnh_download_options+=( --workflow=daily-modpack-build.yml )
96+
logWarning "Using daily build instead of latest beta release for GTNH server files. If this is not intended, set GTNH_USE_DAILY_BUILD=false to use the latest beta release instead."
97+
else
98+
gtnh_download_options+=( --run-id="$GTNH_PACK_VERSION" )
99+
log "Using specific daily build run ID $GTNH_PACK_VERSION for GTNH server files."
100+
fi
101+
102+
# Select compatible server files for java version
103+
if (( java_version == 8 )); then
104+
log "Use GTNH Server Java 8 release."
105+
gtnh_download_options+=( --artifact-pattern='GTNH-daily-\d{4}-\d{2}-\d{2}\+\d+-server-java8\.zip' )
106+
107+
elif (( java_version >= 17 )); then
108+
log "Use GTNH Server Java 17+ release."
109+
gtnh_download_options+=( --artifact-pattern='GTNH-daily-\d{4}-\d{2}-\d{2}\+\d+-server-java17-\d{2}\.zip' )
110+
fi
111+
112+
debug "GTNH daily build download options: ${gtnh_download_options[*]}"
113+
114+
if ! gtnh_download_path=$(mc-image-helper github download-artifact --no-download "${gtnh_download_options[@]}" GTNewHorizons/DreamAssemblerXXL); then
115+
logError "Failed to find a matching daily build for GTNH server files with the specified options."
116+
exit 1
117+
fi
118+
119+
debug "GTNH daily build download path: $gtnh_download_path"
120+
121+
}
122+
76123
function deleteGTNHbackup(){
77124
log "Start deleting all config backups"
78125
if ! find . -maxdepth 1 -type d -name 'gtnh-upgrade-*' -exec rm -rf {} + ; then
@@ -81,24 +128,33 @@ function deleteGTNHbackup(){
81128
}
82129

83130
function downloadGTNH(){
84-
local gtnh_download=""
131+
gtnh_download=""
85132
base_dir=/data/.tmp/gtnh_base
86133

87134
debug "Creating temporary /data/.tmp/packs folder for GTNH download"
88135
mkdir -p /data/.tmp/packs
89136
trap 'rm -rf /data/.tmp' EXIT
137+
mkdir -p "${base_dir}"
90138

91-
log "Downloading $gtnh_download_path."
92-
if ! gtnh_download=$(mc-image-helper get -o /data/.tmp/packs --output-filename --skip-up-to-date "$gtnh_download_path"); then
93-
logError "Failed to download $gtnh_download_path"
94-
exit 1
95-
fi
96-
debug "Downloaded GTNH server files to $gtnh_download"
139+
if isTrue "$GTNH_USE_DAILY_BUILD"; then
140+
log "Downloading Daily Build for GTNH server files."
141+
# gtnh_download_options is injecting download parameters -> (--workflow or --run-id) and --artifact-pattern
142+
if ! gtnh_download=$(mc-image-helper github download-artifact -o=$base_dir --unzip "${gtnh_download_options[@]}" GTNewHorizons/DreamAssemblerXXL); then
143+
logError "Failed to download Daily Build for GTNH server files."
144+
exit 1
145+
fi
146+
else
147+
log "Downloading $gtnh_download_path."
148+
if ! gtnh_download=$(mc-image-helper get -o /data/.tmp/packs --output-filename --skip-up-to-date "$gtnh_download_path"); then
149+
logError "Failed to download $gtnh_download_path"
150+
exit 1
151+
fi
152+
debug "Downloaded GTNH server files to $gtnh_download"
97153

98-
# Unpacking Server files into temporary directory
99-
log "Unpacking Server Files into $base_dir"
100-
mkdir -p "${base_dir}"
101-
extract "${gtnh_download}" "${base_dir}"
154+
# Unpacking Server files into temporary directory
155+
log "Unpacking Server Files into $base_dir"
156+
extract "${gtnh_download}" "${base_dir}"
157+
fi
102158

103159
# Remove any eula file since container manages it
104160
debug "Removing eula.txt from $base_dir"
@@ -209,16 +265,23 @@ function handleGTNH() {
209265
: "${GTNH_PACK_VERSION:=latest}"
210266
: "${GTNH_DELETE_BACKUPS:=false}"
211267
: "${SKIP_GTNH_UPDATE_CHECK:=false}"
212-
debug "GTNH VAR CHECK: GTNH_DELETE_BACKUPS=$GTNH_DELETE_BACKUPS, GTNH_PACK_VERSION=$GTNH_PACK_VERSION, TYPE=$TYPE, SKIP_GTNH_UPDATE_CHECK=$SKIP_GTNH_UPDATE_CHECK"
268+
: "${GTNH_USE_DAILY_BUILD:=false}"
269+
270+
debug "GTNH VAR CHECK: GTNH_DELETE_BACKUPS=$GTNH_DELETE_BACKUPS, GTNH_PACK_VERSION=$GTNH_PACK_VERSION, TYPE=$TYPE, SKIP_GTNH_UPDATE_CHECK=$SKIP_GTNH_UPDATE_CHECK, GTNH_USE_DAILY_BUILD=$GTNH_USE_DAILY_BUILD"
213271

214272
if isTrue "$GTNH_DELETE_BACKUPS"; then
215273
deleteGTNHbackup
216274
fi
217275

218-
if [[ -n "$GTNH_PACK_VERSION" ]] && isFalse "$SKIP_GTNH_UPDATE_CHECK" ; then
276+
if [[ -n "$GTNH_PACK_VERSION" ]] && isFalse "$SKIP_GTNH_UPDATE_CHECK"; then
219277

220-
getGTNHdownloadPath
221-
log "Server files located! Will proceed update $gtnh_download_path."
278+
if isFalse "$GTNH_USE_DAILY_BUILD"; then
279+
getGTNHdownloadPath
280+
log "Server files located! Will proceed update $gtnh_download_path."
281+
else
282+
getGTNHdownloadOptions
283+
log "Will proceed update with daily build options: ${gtnh_download_options[*]}."
284+
fi
222285

223286

224287
# Decide if update or install is needed or not.
@@ -239,7 +302,7 @@ function handleGTNH() {
239302
fi
240303

241304
# Update .gtnh-version
242-
basename "$gtnh_download_path" > /data/.gtnh-version
305+
basename "$gtnh_download" > /data/.gtnh-version
243306

244307
# Cleaning up temporary files
245308
rm -rf /data/.tmp

0 commit comments

Comments
 (0)