diff --git a/src/.bin/open-runelite.sh b/src/.bin/open-runelite.sh new file mode 100755 index 0000000..d55d301 --- /dev/null +++ b/src/.bin/open-runelite.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash + +### +### Quick-start build-and-run script for RuneLite, merging dev branches for a +### custom build. +### + +# OPTIONS +RUNELITE_REPO_DIR="$HOME/Documents/git/runelite" +BRANCHES_TO_MERGE=( + add-tablecomponent-to-overlay-ui + # dev-update-opponent-info-table-bounty-target + lookup-players-that-despawn + #differentiate-gauntlet-loots # conflicts with discord sub-regions + charlie-texts + discord-sub-regions + toa-consumables + multi-step-cryptic-spade + quest-speedrunning-widget-overlays +) +MAX_AGE_BEFORE_REBUILD="$(( 24 * 60 * 60 ))" # 1 day +UPSTREAM_REMOTE='upstream' +UPSTREAM_BRANCH='master' +for branch in "${BRANCHES_TO_MERGE[@]}"; do + if grep -qE '^internal' <<< "$branch"; then + UPSTREAM_REMOTE='internal-upstream' + UPSTREAM_BRANCH='internal' + break + fi +done + +# Show exit output on script completion +# On script error, wait for user input to close +function orl_exit { + exit_code=$? + if [ "$exit_code" -eq 0 ]; then + echo 'Running runelite!' + sleep 3 + else + echo 'An error occurred while running command' + echo " ${BASH_COMMAND}" + echo 'Press any key to exit...' + read -n1 -r + fi +} +trap orl_exit EXIT + +RUNELITE_TARGET_COMMIT_FILENAME='runelite-client/target/commit' +function build_client { + # Update local dev branch and build + git checkout dev || git checkout -b dev upstream/master + git reset --hard upstream/master + git merge --no-gpg-sign --no-edit "${BRANCHES_TO_MERGE[@]}" || exit 1 + mvn clean package -DskipTests -U || exit 1 + git checkout - + echo "$UPSTREAM_MASTER_COMMIT" > "$RUNELITE_TARGET_COMMIT_FILENAME" +} + +set -e + +# go to repo +cd "$RUNELITE_REPO_DIR" + +# check if jar is up-to-date with latest upstream tag +git fetch -q "$UPSTREAM_REMOTE" +UPSTREAM_MASTER_COMMIT="$(git rev-parse "$UPSTREAM_REMOTE"/"$UPSTREAM_BRANCH")" +# TODO: use `git describe [--abbrev=0]` ? (may not work due to point releases) +# TODO: add --exclude to ^ to avoid describing point releases (TODO: don't do that--we need point release for latest hub plugins) +PREVIOUS_TAG="$(git tag -l | grep -v 'internal' | sort -rV | head -n 1 | sed -r -e 's/.*-(.+)/\1/')" +MAJOR_VERSION="$(cut -d '.' -f 1 <<< "$PREVIOUS_TAG")" +MINOR_VERSION="$(cut -d '.' -f 2 <<< "$PREVIOUS_TAG")" +PATCH_VERSION="$(cut -d '.' -f 3 <<< "$PREVIOUS_TAG")" +NEXT_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.$((PATCH_VERSION + 1))" +SHADED_JAR=runelite-client/target/client-"${NEXT_VERSION}"-SNAPSHOT-shaded.jar + +# build a new client if one doesn't already exist or if the current shaded jar +# is older than the max rebuild age and is behind upstream master's commit +if ! [ -f "$SHADED_JAR" ]; then + echo "No build exists for current snapshot; rebuilding" + build_client +else + SHADED_JAR_MTIME="$(stat -c %Y "$SHADED_JAR")" + CURRENT_MTIME="$(date +%s)" + if [ "$(( "$CURRENT_MTIME" - "$SHADED_JAR_MTIME" ))" -gt "$MAX_AGE_BEFORE_REBUILD" ]; then + if ! [ -f "$RUNELITE_TARGET_COMMIT_FILENAME" ] \ + || [ "$UPSTREAM_MASTER_COMMIT" != "$(cat "$RUNELITE_TARGET_COMMIT_FILENAME")" ]; then + echo "Current built client is old enough for rebuild and master has new commits; rebuilding" + build_client + else + echo "Current built client is old enough for rebuild, but there no new commits to build; skipping rebuild" + fi + else + echo "Current built client is not beyond max age before rebuild; skipping rebuild" + fi +fi + +# run the dev client +nohup java -ea -Drunelite.pluginhub.version="${PREVIOUS_TAG}" -jar runelite-client/target/client-"${NEXT_VERSION}"-SNAPSHOT-shaded.jar --developer-mode --debug /dev/null 2>&1 & diff --git a/src/.bin/runelite-blog.sh b/src/.bin/runelite-blog.sh new file mode 100755 index 0000000..ea881b3 --- /dev/null +++ b/src/.bin/runelite-blog.sh @@ -0,0 +1,175 @@ +#!/usr/bin/env bash + +### +### Helper script for quickly setting up a git branch and directory/file +### structure for creating a new release post for runelite.net +### + +set -e + +description() { + echo 'Creates a new branch and file structure for the weekly release blog post in the runelite.net repository' +} +helpdoc() { + echo + echo "usage: $(basename "$0") []" + echo + echo 'options:' + echo ' -a first name to use, defaults to `git config user.name'"'" + echo ' -f version number to generate shortlog from, defaults to previous' + echo ' major release' + echo ' -n version number to increment to, defaults to a patch version' + echo ' bump' + echo ' -p path of runelite repository relative to runelite.net repo,' + echo ' defaults to `../runelite'"'" + echo ' -t mark the blog post for today'"'"'s date, not tomorrow'"'"'s date' +} + +# process args +while getopts ':a:f:n:p:th' arg; do + case "$arg" in + a) + blog_author="$OPTARG" + ;; + f) + previous_version="$OPTARG" + ;; + h) + description + helpdoc + exit 0 + ;; + n) + version="$OPTARG" + ;; + p) + runelite_repo_path="$OPTARG" + ;; + t) + blog_date='today' + ;; + \?) + echo "Invalid option: ${OPTARG}" >&2 + helpdoc + exit 1 + ;; + :) + echo "Option -${OPTARG} requires an argument." >&2 + helpdoc + exit 1 + ;; + esac +done + +# remove args processed with getopts +shift $(( OPTIND-1 )) + +# ensure shell is in runelite.net repo, navigate to root dir if necessary, fetch upstream +if ! (git remote -v | grep -q -E 'upstream[[:space:]]+git@github.com:runelite/runelite.net.git'); then + echo 'You do not appear to be in a clone of the runelite.net repository!' >&2 + exit 1 +fi +cd "$(git rev-parse --show-toplevel)" +git fetch -q upstream + +# ensure runelite repo path is correct, fetch upstream in runelite repo +default_path='../runelite' +repo_path="${runelite_repo_path:-$default_path}" + +if ! (git -C "$repo_path" remote -v | grep -q -E 'upstream[[:space:]]+git@github.com:runelite/runelite.git'); then + echo "The repo path '${repo_path}' does not appear to be a clone of the runelite repository!" >&2 + exit 1 +fi +(git -C "$repo_path" git fetch -q upstream) >/dev/null + +# validate versions +latest_tag="$(git -C "$repo_path" tag -l | grep -v 'internal' | sort -rV | head -n 1 | sed -r -e 's/(.*-)([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+).*/\1\2/')" +LATEST_TAG_VERSION="${latest_tag##*-}" +if [ -z "$previous_version" ]; then + : # no-op +elif ! [[ "$previous_version" =~ ^[1-9][[:digit:]]*\.([[:digit:]]|[1-9][[:digit:]]*)\.([[:digit:]]|[1-9][[:digit:]]*)(\.([[:digit:]]|[1-9][[:digit:]]*))?$ ]]; then + echo "Invalid previous version number: '$previous_version'" >&2 + helpdoc + exit 1 +else + latest_tag="runelite-parent-${previous_version}" +fi + +if [ -z "$version" ]; then + patch_number="${LATEST_TAG_VERSION##*.}" + version="${LATEST_TAG_VERSION%.*}.$((patch_number + 1))" +elif ! [[ "$version" =~ ^[1-9][[:digit:]]*\.[1-9][[:digit:]]*\.[1-9][[:digit:]]*$ ]]; then + echo "Invalid version number: '$version'" >&2 + helpdoc + exit 1 +fi + +NEW_VERSION="$version" + +# get data, define vars +git_username_trimmed="$(git config user.name | cut -d ' ' -f '1')" +default_date='+1 day' +BLOG_DATE="${blog_date:-$default_date}" +BLOG_AUTHOR="${blog_author:-$git_username_trimmed}" +git_shortlog_options=(--no-merges --perl-regexp '--author=^((?!Runelite auto updater|RuneLite Cache-Code Autoupdater).*)$' "${latest_tag}"..upstream/master) +SHORTLOG_SINCE_LAST_TAG="$(git -C "$repo_path" --no-pager shortlog "${git_shortlog_options[@]}")" +NUMBER_OF_CONTRIBUTORS="$(git -C "$repo_path" --no-pager shortlog -s "${git_shortlog_options[@]}" | wc -l)" +BLOG_POST_DATE="$(date -d "${BLOG_DATE} 10:00am" +'%Y-%m-%d-%H-%M')" + +# create new branch, deleting branch of same name if it exists +git checkout master >/dev/null 2>&1 +if git branch | grep -q "$NEW_VERSION"; then + git branch -D "$NEW_VERSION" >/dev/null 2>&1 +fi +(git pull --ff-only && git checkout -b "$NEW_VERSION") >/dev/null 2>&1 + +# create dirs and files +relative_img_path="img/blog/${NEW_VERSION}-Release" +img_name="placeholder.png" +IMAGE_DIR="public/${relative_img_path}/${img_name}" +PLACEHOLDER_IMAGE_PATH="${relative_img_path}/${img_name}" +BLOG_FILE_PATH="src/_posts/${BLOG_POST_DATE}-${NEW_VERSION}-Release.md" + +install -Dv /dev/null "${IMAGE_DIR}" >/dev/null +tee "${BLOG_FILE_PATH}" >/dev/null 2>&1 <