Skip to content

Commit

Permalink
Merge pull request #62 from DrHenchman/add-paper-to-ci
Browse files Browse the repository at this point in the history
Add Paper variant to CI
  • Loading branch information
DrHenchman authored Dec 30, 2020
2 parents 232c7fa + b028251 commit 50e1a67
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 18 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ jobs:
with:
java-version: 1.8
# Run against supported Minecraft versions
- name: Build and test (Minecraft version = latest release)
- name: Build and test (Minecraft version = latest release, variant = vanilla)
run: bin/ci.sh --clean
- name: Build and test (Minecraft version = 1.15.2)
- name: Build and test (Minecraft version = latest release, variant = paper)
run: bin/ci.sh --clean --variant paper
- name: Build and test (Minecraft version = 1.15.2, variant = vanilla)
run: bin/ci.sh --clean --version 1.15.2
- name: Build and test (Minecraft version = 1.15.2, variant = paper)
run: bin/ci.sh --clean --version 1.15.2 --variant paper
81 changes: 65 additions & 16 deletions bin/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ readonly TARGET_DIR="target"
function main() {
local clean_target_dir=0
local version="release"
local variant="vanilla"
while [ $# -ne 0 ]; do
case "$1" in
--version)
version="$2"
shift
;;
--variant)
variant="$2"
shift
;;
--clean)
clean_target_dir=1
;;
Expand All @@ -37,12 +42,12 @@ function main() {
echo "Resolving version $version"
version="$(resolve_version "$version")"
echo "Resolved version $version"
download_version "$version"
download_version "$version" "$variant"

accept_eula "$version"
copy_datapack "$version"
start_server "$version"
wait_and_stop_server "$version"
start_server "$version" "$variant"
wait_and_stop_server "$version" "$variant"

assert_no_error_logs "$version"
echo "PASSED!"
Expand Down Expand Up @@ -110,6 +115,7 @@ function resolve_version() {

function download_version() {
local version="$1"
local variant="$2"
if [ ! -d "$TARGET_DIR/$version" ]; then
mkdir "$TARGET_DIR/$version"
fi
Expand All @@ -126,16 +132,26 @@ function download_version() {
curl "$version_url" > "$TARGET_DIR/$version/$version.json"
fi

local version_jar_url="$(jq .downloads.server.url --raw-output "$TARGET_DIR/$version/$version.json")"
local version_jar_sha1="$(jq .downloads.server.sha1 --raw-output "$TARGET_DIR/$version/$version.json")"
if [ -f "$TARGET_DIR/$version/$version.jar" ]; then
echo "Already downloaded $version.jar"
else
echo "Downloading $version.jar"
curl "$version_jar_url" > "$TARGET_DIR/$version/$version.jar"
fi
echo "Running checksum on $version.jar"
echo "$version_jar_sha1 $TARGET_DIR/$version/$version.jar" | shasum -a 1 -c
case "$variant" in
vanilla)
local version_jar_url="$(jq .downloads.server.url --raw-output "$TARGET_DIR/$version/$version.json")"
local version_jar_sha1="$(jq .downloads.server.sha1 --raw-output "$TARGET_DIR/$version/$version.json")"
if [ -f "$TARGET_DIR/$version/$version.jar" ]; then
echo "Already downloaded $version.jar"
else
echo "Downloading $version.jar"
curl "$version_jar_url" > "$TARGET_DIR/$version/$version.jar"
fi
echo "Running checksum on $version.jar"
echo "$version_jar_sha1 $TARGET_DIR/$version/$version.jar" | shasum -a 1 -c
;;
paper)
curl -L "https://papermc.io/api/v1/paper/$version/latest/download" > "$TARGET_DIR/$version/$version-paper.jar"
;;
*)
raise_error "Unable to download JAR. Unsupported variant '$variant'"
;;
esac
}

function accept_eula() {
Expand All @@ -154,21 +170,54 @@ function copy_datapack() {

function start_server() {
local version="$1"
local variant="$2"
local suffix=""

case "$variant" in
vanilla)
;;
paper)
suffix="-paper"
;;
*)
raise_error "Unable to start server. Unsupported variant '$variant'"
;;
esac

echo "Starting Minecraft version $version"
cd "$TARGET_DIR/$version"
java -jar "$version.jar" nogui &
java -jar "$version$suffix.jar" nogui &
echo $! > server.pid
cd "../../"
echo "PID = $(cat "$TARGET_DIR/$version/server.pid")"
}

function wait_and_stop_server() {
local version="$1"
local variant="$2"

local search_term=""
case "$variant-$version" in
vanilla-*)
search_term='Loaded [0-9]\+ advancements'
;;
paper-1.15*)
search_term='Loaded [0-9]\+ custom command functions'
;;
paper-*)
search_term='Loading properties'
;;
*)
raise_error "Unable to wait for datapack. Unsupported variant '$variant'"
;;
esac

local server_pid="$(cat "$TARGET_DIR/$version/server.pid")"

local retries=0
echo "Waiting for server to load datapack"
sleep 5
until grep -q 'Loaded [0-9]\+ advancements' "$TARGET_DIR/$version/logs/latest.log" || ! ps "$server_pid" || [ $retries -ge 60 ]; do
until grep -q "$search_term" "$TARGET_DIR/$version/logs/latest.log" || ! ps "$server_pid" || [ $retries -ge 60 ]; do
echo "Waiting for server to load datapack"
sleep 1
retries=$((retries + 1))
Expand All @@ -177,7 +226,7 @@ function wait_and_stop_server() {
echo "Killing PID = $server_pid"
kill -9 "$server_pid"
fi
if ! grep -q 'Loaded [0-9]\+ advancements' "$TARGET_DIR/$version/logs/latest.log"; then
if ! grep -q "$search_term" "$TARGET_DIR/$version/logs/latest.log"; then
raise_error "Minecraft server failed to start"
fi
if ! fgrep -q 'uhc-pack.zip' "$TARGET_DIR/$version/logs/latest.log"; then
Expand Down

0 comments on commit 50e1a67

Please sign in to comment.