From d1664f4564f25f27babe3874daa9147eac2b5b66 Mon Sep 17 00:00:00 2001 From: Face o' Cat Date: Wed, 25 Nov 2026 14:19:25 +0200 Subject: [PATCH 1/4] Add the shared CI and a player changelog for the pottery now on main. --- .github/scripts/curseforge-version-ids.py | 51 ++++ .github/scripts/discord-merge-message.sh | 25 ++ .github/scripts/release-bump.sh | 43 +++ .github/scripts/release-changelog.sh | 105 ++++++++ .github/scripts/release-commit.sh | 33 +++ .github/scripts/release-publish.sh | 276 ++++++++++++++++++++ .github/scripts/release-version.sh | 107 ++++++++ .github/scripts/test_curseforge_versions.py | 142 ++++++++++ .github/scripts/test_release_changelog.py | 125 +++++++++ .github/scripts/test_release_commit.py | 101 +++++++ .github/workflows/ci.yml | 115 ++++++++ .github/workflows/discord-merge-notify.yml | 26 ++ .github/workflows/release-metadata.yml | 27 ++ .github/workflows/release.yml | 232 ++++++++++++++++ .github/workflows/retry-release.yml | 88 +++++++ CHANGELOG.md | 15 ++ 16 files changed, 1511 insertions(+) create mode 100644 .github/scripts/curseforge-version-ids.py create mode 100644 .github/scripts/discord-merge-message.sh create mode 100644 .github/scripts/release-bump.sh create mode 100644 .github/scripts/release-changelog.sh create mode 100644 .github/scripts/release-commit.sh create mode 100644 .github/scripts/release-publish.sh create mode 100644 .github/scripts/release-version.sh create mode 100644 .github/scripts/test_curseforge_versions.py create mode 100644 .github/scripts/test_release_changelog.py create mode 100644 .github/scripts/test_release_commit.py create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/discord-merge-notify.yml create mode 100644 .github/workflows/release-metadata.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/retry-release.yml create mode 100644 CHANGELOG.md diff --git a/.github/scripts/curseforge-version-ids.py b/.github/scripts/curseforge-version-ids.py new file mode 100644 index 0000000..d59e376 --- /dev/null +++ b/.github/scripts/curseforge-version-ids.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +"""Resolve CurseForge upload IDs by category and name, not name alone.""" +import json +from pathlib import Path +import sys + + +def entries(value): + if isinstance(value, dict): + value = value.get("data") + if not isinstance(value, list) or not value: + raise ValueError("CurseForge returned an empty or invalid catalog") + return value + + +def resolve(versions, types, game, loader, java): + versions, types = entries(versions), entries(types) + + def find(name, category, required=True): + type_ids = {row["id"] for row in types if row.get("slug") == category} + ids = { + row["id"] for row in versions + if row.get("name") == name and row.get("gameVersionTypeID") in type_ids + } + if len(type_ids) != 1 or len(ids) != 1: + message = f"CurseForge needs one {name!r} in category {category!r}; found {len(type_ids)} categories and {len(ids)} versions" + if required: + raise ValueError(message) + print(message + "; omitting optional Java metadata", file=sys.stderr) + return None + return ids.pop() + + # 1.20.6 belongs to minecraft-1-20; 1.21.1 belongs to minecraft-1-21; 26.3 belongs to minecraft-26-3. + category = "minecraft-" + "-".join(game.split(".")[:2]) + result = [find(game, category), find(loader, "modloader"), + find("Client", "environment"), find("Server", "environment")] + java_id = find(java, "java", required=False) + if java_id is not None: + result.append(java_id) + return result + + +if __name__ == "__main__": + if len(sys.argv) != 6: + sys.exit("Usage: curseforge-version-ids.py ") + try: + versions = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8")) + types = json.loads(Path(sys.argv[2]).read_text(encoding="utf-8")) + print(json.dumps(resolve(versions, types, *sys.argv[3:]))) + except (OSError, ValueError, KeyError, TypeError) as error: + sys.exit(str(error)) diff --git a/.github/scripts/discord-merge-message.sh b/.github/scripts/discord-merge-message.sh new file mode 100644 index 0000000..c084361 --- /dev/null +++ b/.github/scripts/discord-merge-message.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Prints the Discord webhook payload for a merged pull request: its title as a link, then the CHANGELOG.md bullets +# that this merge added. GitHub's own preview card is switched off (flags 4) and no one gets pinged. +# Usage: discord-merge-message.sh <url> +set -euo pipefail + +merge=$1 repo=$2 number=$3 title=$4 url=$5 +# Discord rejects messages over 2000 characters; leave room for the "more" line. +limit=1900 + +# The first parent is main before the merge, so this diff is exactly what the pull request changed. +bullets=$(git diff --unified=0 "$merge^1" "$merge" -- CHANGELOG.md | sed -n 's/^+\([[:space:]]*[-*] \)/\1/p') + +content="✅ **[${repo} #${number}: ${title}](${url})**" +if [ -n "$bullets" ]; then + while IFS= read -r line; do + if [ $(( ${#content} + ${#line} + 1 )) -gt "$limit" ]; then + content+=$'\n'"…and more in CHANGELOG.md" + break + fi + content+=$'\n'"$line" + done <<< "$bullets" +fi + +jq -n --arg content "$content" '{content: $content, flags: 4, allowed_mentions: {parse: []}}' diff --git a/.github/scripts/release-bump.sh b/.github/scripts/release-bump.sh new file mode 100644 index 0000000..78f98c5 --- /dev/null +++ b/.github/scripts/release-bump.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# Points main at the patch after a published tag. The published number itself is never +# committed: the tag's jars already used it, and this only writes the following version. +# Usage: release-bump.sh 0.2.0 0.2.1 CHANGELOG.md tag-changelog.md gradle.properties +# Prints a summary. Exits 1 when the change would move the version backwards. +set -euo pipefail + +die() { echo "$1" >&2; exit 1; } + +[[ $# -eq 5 ]] || die "Usage: release-bump.sh 0.2.0 0.2.1 CHANGELOG.md tag-changelog.md gradle.properties" +released=$1 +next=$2 +changelog=$3 +tagged=$4 +properties=$5 +here=$(dirname "$0") + +order=$(bash "$here/release-version.sh" cmp "$(bash "$here/release-version.sh" read "$properties")" "$next") +case "$order" in + gt) die "gradle.properties is already past ${next}, so this would move the version backwards" ;; + eq) version_note="\`gradle.properties\` is already \`${next}\`." ;; + lt) + bash "$here/release-version.sh" write "$properties" "$next" + version_note="\`gradle.properties\` now says \`${next}\`." + ;; +esac + +if grep -Fxq "## ${released}" "$changelog"; then + changelog_note="\`## ${released}\` is already in the changelog." +elif cmp -s \ + <(bash "$here/release-changelog.sh" extract "$changelog") \ + <(bash "$here/release-changelog.sh" extract "$tagged"); then + bash "$here/release-changelog.sh" bump "$changelog" "$released" + changelog_note="The new notes are under \`## ${released}\`, and \`## Unreleased\` is empty again. Earlier version sections stay in place." +else + changelog_note="\`## Unreleased\` on main does not match the notes that were published, so the heading was left as it is." +fi + +cat <<EOF +\`${released}\` is published. ${version_note} + +${changelog_note} +EOF diff --git a/.github/scripts/release-changelog.sh b/.github/scripts/release-changelog.sh new file mode 100644 index 0000000..e419489 --- /dev/null +++ b/.github/scripts/release-changelog.sh @@ -0,0 +1,105 @@ +#!/usr/bin/env bash +# Prereleases publish Unreleased only. Stable releases also include the prerelease +# sections since the previous stable heading. Bumping archives only Unreleased. +# Usage: +# release-changelog.sh extract CHANGELOG.md # may be empty; used to compare notes +# release-changelog.sh notes CHANGELOG.md 0.2.0 +# release-changelog.sh bump CHANGELOG.md 0.2.0 +set -euo pipefail + +die() { echo "$1" >&2; exit 1; } + +semver='^(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-alpha|-beta)?$' + +extract() { + local file=$1 body + body=$(awk ' + /^## Unreleased$/ { in_section = 1; found = 1; next } + /^## / && in_section { exit } + in_section { lines[++n] = $0 } + END { + if (!found) exit 1 + start = 1 + while (start <= n && lines[start] ~ /^[[:space:]]*$/) start++ + end = n + while (end >= start && lines[end] ~ /^[[:space:]]*$/) end-- + for (i = start; i <= end; i++) print lines[i] + } + ' "$file") || die "${file} has no ## Unreleased section" + printf '%s\n' "$body" +} + +notes() { + local file=$1 version=$2 body history + [[ "$version" =~ $semver ]] || die "Version ${version} has to look like 0.0.1 or 0.0.1-alpha" + body=$(extract "$file") + case "$version" in + *-alpha|*-beta) + printf '%s\n' "$body" | grep '^[[:space:]]*[-*] ' >/dev/null || die "${file} has no bullets under ## Unreleased" + ;; + *) + # Headings are newest first. A stable heading is the exclusive cutoff; beta + # headings are included just like alpha headings. Reject unknown headings. + history=$(awk -v semver="$semver" ' + /^## Unreleased$/ { found = 1; next } + /^## / && found { + version = substr($0, 4) + if (version !~ semver) exit 1 + if (version !~ /-(alpha|beta)$/) exit + in_history = 1 + } + in_history { lines[++n] = $0 } + END { + while (n > 0 && lines[n] ~ /^[[:space:]]*$/) n-- + for (i = 1; i <= n; i++) print lines[i] + } + ' "$file") || die "${file} has an invalid version heading" + if [[ -n "$body" ]]; then + body=$(printf '## %s\n\n%s' "$version" "$body") + fi + if [[ -n "$history" ]]; then + if [[ -n "$body" ]]; then + body=$(printf '%s\n\n%s' "$body" "$history") + else + body=$history + fi + fi + printf '%s\n' "$body" | grep '^[[:space:]]*[-*] ' >/dev/null || die "${file} has no changes since the previous stable release" + ;; + esac + printf '%s\n' "$body" +} + +bump() { + local file=$1 version=$2 tmp + [[ "$version" =~ $semver ]] || die "Version ${version} has to look like 0.0.1 or 0.0.1-alpha" + grep -Fxq "## ${version}" "$file" && die "${file} already has a ## ${version} section" + # A stable promotion can have an empty Unreleased section. Still insert its + # heading so it becomes the cutoff for the next stable release. + notes "$file" "$version" >/dev/null + tmp=$(mktemp) + awk -v version="$version" ' + /^## Unreleased$/ && !done { + print "## Unreleased" + print "" + print "## " version + done = 1 + next + } + { print } + END { if (!done) exit 1 } + ' "$file" > "$tmp" && mv "$tmp" "$file" || { + rm -f "$tmp" + die "Could not rename ## Unreleased in ${file}" + } +} + +[[ $# -ge 1 ]] || die "Usage: release-changelog.sh extract|notes|bump ..." +cmd=$1 +shift +case "$cmd" in + extract) [[ $# -eq 1 ]] || die "Usage: release-changelog.sh extract CHANGELOG.md"; extract "$1" ;; + notes) [[ $# -eq 2 ]] || die "Usage: release-changelog.sh notes CHANGELOG.md 0.2.0"; notes "$1" "$2" ;; + bump) [[ $# -eq 2 ]] || die "Usage: release-changelog.sh bump CHANGELOG.md 0.2.0"; bump "$1" "$2" ;; + *) die "Unknown command: ${cmd}" ;; +esac diff --git a/.github/scripts/release-commit.sh b/.github/scripts/release-commit.sh new file mode 100644 index 0000000..dd2f84c --- /dev/null +++ b/.github/scripts/release-commit.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Commit the post-release version and changelog directly to current main. +# Usage: release-commit.sh 0.0.1-alpha 0.0.2 0.0.1-alpha +set -euo pipefail + +die() { echo "$1" >&2; exit 1; } +[[ $# -eq 3 ]] || die "Usage: release-commit.sh <version> <next> <tag>" +version=$1 +next=$2 +tag=$3 +here=$(dirname "$0") + +[[ -z "$(git status --porcelain)" ]] || die "The release checkout must be clean" + +# Keep using the tagged scripts even if main has changed since the release build. +work=$(mktemp -d) +trap 'rm -f "$work/"*.sh "$work/tag-changelog.md"; rmdir "$work"' EXIT +cp "$here/release-version.sh" "$here/release-changelog.sh" "$here/release-bump.sh" "$work/" +git show "${tag}:CHANGELOG.md" > "$work/tag-changelog.md" +git fetch origin main +git checkout --detach origin/main +bash "$work/release-bump.sh" "$version" "$next" CHANGELOG.md "$work/tag-changelog.md" gradle.properties +git diff --stat -- gradle.properties CHANGELOG.md +if git diff --quiet -- gradle.properties CHANGELOG.md; then + echo "main already has the next version and changelog heading." + exit 0 +fi +git add gradle.properties CHANGELOG.md +git -c user.name='github-actions[bot]' -c user.email='41898282+github-actions[bot]@users.noreply.github.com' \ + commit -m "Set the development version to ${next} after publishing ${tag}." +# Never force-push: concurrent commits must survive. Rerunning the job fetches +# fresh main and computes the update again instead of replaying a stale edit. +git push origin HEAD:refs/heads/main || die "Could not update main. If main advanced, rerun this job; otherwise check the action's push permissions." diff --git a/.github/scripts/release-publish.sh b/.github/scripts/release-publish.sh new file mode 100644 index 0000000..fa016c2 --- /dev/null +++ b/.github/scripts/release-publish.sh @@ -0,0 +1,276 @@ +#!/usr/bin/env bash +# Publishes the four jars for one tag: NeoForge 1.20.6, NeoForge 1.21.1, Fabric 26.3, and NeoForge 26.3. +# Each loader gets its own Modrinth version and CurseForge file, so the download button +# is the jar for that loader. GitHub gets one release with all four attached. +# Usage: +# release-publish.sh check-env +# release-publish.sh classify <jars-dir> <version> +# release-publish.sh upload <version> <changelog-file> <jars-dir> +set -euo pipefail + +die() { echo "$1" >&2; exit 1; } + +user_agent='modcrafters/primal-pottery (release)' +# Fabric API on Modrinth. The loader itself is selected with the loaders field. +fabric_api='P7dR8mSH' +here=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) + +check_env() { + local missing=() + [[ -n "${MODRINTH_TOKEN:-}" ]] || missing+=(MODRINTH_TOKEN) + [[ -n "${CURSEFORGE_TOKEN:-}" ]] || missing+=(CURSEFORGE_TOKEN) + [[ -n "${MODRINTH_PROJECT_ID:-}" ]] || missing+=(MODRINTH_PROJECT_ID) + [[ -n "${CURSEFORGE_PROJECT_ID:-}" ]] || missing+=(CURSEFORGE_PROJECT_ID) + if [[ ${#missing[@]} -gt 0 ]]; then + die "Missing ${missing[*]}. Tokens are repository secrets. Project ids are repository variables." + fi + [[ "$MODRINTH_PROJECT_ID" =~ ^[A-Za-z0-9]+$ ]] || die "MODRINTH_PROJECT_ID should be the id from the Modrinth project page" + [[ "$CURSEFORGE_PROJECT_ID" =~ ^[0-9]+$ ]] || die "CURSEFORGE_PROJECT_ID should be the number from the CurseForge project page" +} + +# Sets neo_1206, neo_121, fabric_263, and neo_263. A sources jar, or a jar from another version, is ignored. +classify() { + local dir=$1 version=$2 jar base + neo_1206='' neo_121='' fabric_263='' neo_263='' + [[ -d "$dir" ]] || die "No jar directory at ${dir}" + while IFS= read -r jar; do + base=$(basename "$jar") + case "$base" in + "primalpottery-neoforge-1.20.6-${version}.jar") + [[ -z "$neo_1206" ]] || die "Two NeoForge 1.20.6 jars named ${base}" + neo_1206=$jar + ;; + "primalpottery-neoforge-1.21.1-${version}.jar") + [[ -z "$neo_121" ]] || die "Two NeoForge 1.21.1 jars named ${base}" + neo_121=$jar + ;; + "primalpottery-fabric-26.3-${version}.jar") + [[ -z "$fabric_263" ]] || die "Two Fabric 26.3 jars named ${base}" + fabric_263=$jar + ;; + "primalpottery-neoforge-26.3-${version}.jar") + [[ -z "$neo_263" ]] || die "Two NeoForge 26.3 jars named ${base}" + neo_263=$jar + ;; + esac + done < <(find "$dir" -type f -name '*.jar' | sort) + [[ -n "$neo_1206" ]] || die "Missing primalpottery-neoforge-1.20.6-${version}.jar" + [[ -n "$neo_121" ]] || die "Missing primalpottery-neoforge-1.21.1-${version}.jar" + [[ -n "$fabric_263" ]] || die "Missing primalpottery-fabric-26.3-${version}.jar" + [[ -n "$neo_263" ]] || die "Missing primalpottery-neoforge-26.3-${version}.jar" +} + +http_code() { + local out=$1 + shift + local code + code=$(curl -sS -o "$out" -w "%{http_code}" "$@") || die "The request did not complete" + printf '%s' "$code" +} + +curseforge_game_versions() { + python3 "$here/curseforge-version-ids.py" "$versions_file" "$types_file" "$@" +} + +modrinth_upload() { + local version_number=$1 name=$2 loader=$3 game=$4 jar=$5 + local encoded code deps + encoded=$(jq -nr --arg value "$version_number" '$value|@uri') + code=$(http_code "$work/exists.json" \ + -H "User-Agent: ${user_agent}" \ + -H "Authorization: ${MODRINTH_TOKEN}" \ + "https://api.modrinth.com/v2/project/${MODRINTH_PROJECT_ID}/version/${encoded}") + if [[ "$code" == 200 ]]; then + echo "Modrinth ${version_number} already exists" + return 0 + fi + [[ "$code" == 404 ]] || { + echo "Modrinth lookup for ${version_number} returned ${code}" >&2 + cat "$work/exists.json" >&2 + exit 1 + } + if [[ "$loader" == fabric ]]; then + deps="[{\"project_id\":\"${fabric_api}\",\"dependency_type\":\"required\"}]" + else + deps='[]' + fi + jq -n \ + --rawfile changelog "$notes" \ + --arg name "$name" \ + --arg version_number "$version_number" \ + --arg project_id "$MODRINTH_PROJECT_ID" \ + --arg version_type "$release_type" \ + --arg game "$game" \ + --arg loader "$loader" \ + --argjson dependencies "$deps" \ + '{ + name: $name, + version_number: $version_number, + changelog: $changelog, + dependencies: $dependencies, + game_versions: [$game], + version_type: $version_type, + loaders: [$loader], + featured: true, + project_id: $project_id, + file_parts: ["jar"], + primary_file: "jar", + status: "listed", + requested_status: "listed", + environment: "client_and_server" + }' > "$work/modrinth.json" + code=$(http_code "$work/created.json" \ + -H "User-Agent: ${user_agent}" \ + -H "Authorization: ${MODRINTH_TOKEN}" \ + -F "data=<${work}/modrinth.json;type=application/json" \ + -F "jar=@${jar};filename=$(basename "$jar")" \ + https://api.modrinth.com/v2/version) + [[ "$code" == 200 ]] || { + echo "Modrinth upload of ${version_number} returned ${code}" >&2 + cat "$work/created.json" >&2 + exit 1 + } + echo "Modrinth ${version_number} published ($(jq -r .id "$work/created.json"))" +} + +curseforge_listed() { + local file_name=$1 display=$2 + [[ "$files_listed" == yes ]] || return 1 + jq -e --arg file "$file_name" --arg display "$display" ' + def files: + if type == "array" then . + elif .data then .data + elif .files then .files + else [] end; + files | any(.[]; .fileName == $file or .displayName == $display) + ' "$work/files.json" >/dev/null +} + +curseforge_upload() { + local display=$1 loader=$2 jar=$3 game_versions=$4 + local code relations='null' + if curseforge_listed "$(basename "$jar")" "$display"; then + echo "CurseForge already has ${display}" + return 0 + fi + [[ "$loader" == Fabric ]] && relations='{"projects":[{"slug":"fabric-api","type":"requiredDependency"}]}' + jq -n \ + --rawfile changelog "$notes" \ + --arg display "$display" \ + --arg release_type "$release_type" \ + --argjson game_versions "$game_versions" \ + --argjson relations "$relations" \ + '{ + changelog: $changelog, + changelogType: "markdown", + displayName: $display, + gameVersions: $game_versions, + releaseType: $release_type + } + (if $relations == null then {} else {relations: $relations} end)' > "$work/curseforge.json" + code=$(http_code "$work/uploaded.json" \ + -H "X-Api-Token: ${CURSEFORGE_TOKEN}" \ + -F "metadata=<${work}/curseforge.json;type=application/json" \ + -F "file=@${jar};filename=$(basename "$jar")" \ + "https://minecraft.curseforge.com/api/projects/${CURSEFORGE_PROJECT_ID}/upload-file") + [[ "$code" == 200 ]] || { + echo "CurseForge upload of ${display} returned ${code}" >&2 + cat "$work/uploaded.json" >&2 + exit 1 + } + echo "CurseForge ${display} published ($(jq -r .id "$work/uploaded.json"))" +} + +github_release() { + local tag=$1 + shift + if gh release view "$tag" >/dev/null 2>&1; then + echo "GitHub release ${tag} already exists" + else + local -a args=(release create "$tag" --title "Feast Dominion ${tag#v}" --notes-file "$notes") + [[ "$release_type" == release ]] || args+=(--prerelease) + gh "${args[@]}" + fi + gh release upload "$tag" --clobber "$@" + echo "GitHub release ${tag} has the jars" +} + +upload() { + local version=$1 + notes=$2 + local jars=$3 code cf_neo_1206 cf_neo_121 cf_fabric_263 cf_neo_263 + check_env + [[ -f "$notes" ]] || die "No changelog at ${notes}" + [[ -n "${TAG:-}" ]] || die "TAG is missing" + case "${RELEASE_TYPE:-}" in + alpha|beta|release) release_type=$RELEASE_TYPE ;; + *) die "RELEASE_TYPE has to be alpha, beta, or release" ;; + esac + classify "$jars" "$version" + work=$(mktemp -d) + trap 'rm -f "$work/"*.json; rmdir "$work"' EXIT + + code=$(http_code "$work/versions.json" \ + -H "X-Api-Token: ${CURSEFORGE_TOKEN}" \ + https://minecraft.curseforge.com/api/game/versions) + [[ "$code" == 200 ]] || { + echo "CurseForge game versions returned ${code}" >&2 + cat "$work/versions.json" >&2 + exit 1 + } + versions_file=$work/versions.json + types_file=$work/types.json + code=$(http_code "$types_file" \ + -H "X-Api-Token: ${CURSEFORGE_TOKEN}" \ + https://minecraft.curseforge.com/api/game/version-types) + [[ "$code" == 200 ]] || { + echo "CurseForge game version types returned ${code}" >&2 + cat "$types_file" >&2 + exit 1 + } + + # Resolve every target before the first upload, so a catalog error cannot + # leave a release published only on Modrinth. + cf_neo_1206=$(curseforge_game_versions 1.20.6 NeoForge "Java 21") + cf_neo_121=$(curseforge_game_versions 1.21.1 NeoForge "Java 21") + cf_fabric_263=$(curseforge_game_versions 26.3 Fabric "Java 25") + cf_neo_263=$(curseforge_game_versions 26.3 NeoForge "Java 25") + + code=$(http_code "$work/files.json" \ + -H "X-Api-Token: ${CURSEFORGE_TOKEN}" \ + "https://minecraft.curseforge.com/api/projects/${CURSEFORGE_PROJECT_ID}/files") + if [[ "$code" == 200 ]]; then + files_listed=yes + else + files_listed=no + echo "CurseForge file list returned ${code}. A repeated run may upload the same jar again." >&2 + fi + + modrinth_upload "${version}+1.20.6" "Feast Dominion ${version} for NeoForge 1.20.6" neoforge 1.20.6 "$neo_1206" + modrinth_upload "${version}+1.21.1" "Feast Dominion ${version} for NeoForge 1.21.1" neoforge 1.21.1 "$neo_121" + modrinth_upload "${version}+26.3+fabric" "Feast Dominion ${version} for Fabric 26.3" fabric 26.3 "$fabric_263" + modrinth_upload "${version}+26.3+neoforge" "Feast Dominion ${version} for NeoForge 26.3" neoforge 26.3 "$neo_263" + + curseforge_upload "Feast Dominion ${version} for NeoForge 1.20.6" NeoForge "$neo_1206" "$cf_neo_1206" + curseforge_upload "Feast Dominion ${version} for NeoForge 1.21.1" NeoForge "$neo_121" "$cf_neo_121" + curseforge_upload "Feast Dominion ${version} for Fabric 26.3" Fabric "$fabric_263" "$cf_fabric_263" + curseforge_upload "Feast Dominion ${version} for NeoForge 26.3" NeoForge "$neo_263" "$cf_neo_263" + + github_release "$TAG" "$neo_1206" "$neo_121" "$fabric_263" "$neo_263" +} + +[[ $# -ge 1 ]] || die "Usage: release-publish.sh check-env|classify|upload ..." +cmd=$1 +shift +case "$cmd" in + check-env) check_env ;; + classify) + [[ $# -eq 2 ]] || die "Usage: release-publish.sh classify <jars-dir> <version>" + classify "$1" "$2" + printf '%s\n' "$neo_1206" "$neo_121" "$fabric_263" "$neo_263" + ;; + upload) + [[ $# -eq 3 ]] || die "Usage: release-publish.sh upload <version> <changelog> <jars-dir>" + upload "$1" "$2" "$3" + ;; + *) die "Unknown command: ${cmd}" ;; +esac diff --git a/.github/scripts/release-version.sh b/.github/scripts/release-version.sh new file mode 100644 index 0000000..70f9a45 --- /dev/null +++ b/.github/scripts/release-version.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# Reads and writes the mod version in gradle.properties. The tag is the version the jars +# are built with: 0.0.1 is a release, and 0.0.1-alpha or 0.0.1-beta is that channel. +# A leading v is accepted. The following development version is the next patch, with no channel. +# Usage: +# release-version.sh parse 0.0.1-alpha +# release-version.sh channel 0.0.1-alpha # prints alpha, beta, or release +# release-version.sh next 0.0.1-alpha # prints 0.0.2 +# release-version.sh read gradle.properties +# release-version.sh write gradle.properties 0.0.1-alpha +# release-version.sh cmp 0.0.1-alpha 0.0.1 # prints lt, eq, or gt +set -euo pipefail + +die() { echo "$1" >&2; exit 1; } + +part='(0|[1-9][0-9]*)' +ver_re="^${part}\\.${part}\\.${part}(-alpha|-beta)?$" +tag_re="^v?${part}\\.${part}\\.${part}(-alpha|-beta)?$" +version_line='^version=(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-alpha|-beta)?$' + +parse() { + local tag=$1 + [[ "$tag" =~ $tag_re ]] || die "Tag ${tag} has to look like 0.0.1 or 0.0.1-alpha" + echo "${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}${BASH_REMATCH[4]}" +} + +channel() { + local tag=$1 + [[ "$tag" =~ $tag_re ]] || die "Tag ${tag} has to look like 0.0.1 or 0.0.1-alpha" + case "${BASH_REMATCH[4]}" in + -alpha) echo alpha ;; + -beta) echo beta ;; + '') echo release ;; + *) die "Tag ${tag} has to look like 0.0.1 or 0.0.1-alpha" ;; + esac +} + +next_version() { + local version=$1 + [[ "$version" =~ $ver_re ]] || die "Version ${version} has to look like 0.0.1 or 0.0.1-alpha" + echo "${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$((BASH_REMATCH[3] + 1))" +} + +read_version() { + local file=$1 line count + line=$(grep -E "$version_line" "$file" || true) + [[ -n "$line" ]] || die "${file} has no version=MAJOR.MINOR.PATCH line" + count=$(printf '%s\n' "$line" | wc -l) + [[ "$count" -eq 1 ]] || die "${file} has more than one version line" + echo "${line#version=}" +} + +write_version() { + local file=$1 version=$2 tmp + [[ "$version" =~ $ver_re ]] || die "Version ${version} has to look like 0.0.1 or 0.0.1-alpha" + tmp=$(mktemp) + awk -v version="$version" ' + /^version=(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-alpha|-beta)?$/ { + if (seen++) exit 1 + print "version=" version + next + } + { print } + END { if (!seen) exit 1 } + ' "$file" > "$tmp" && mv "$tmp" "$file" || { + rm -f "$tmp" + die "Could not replace the version line in ${file}" + } +} + +channel_rank() { + case "$1" in + -alpha) echo 1 ;; + -beta) echo 2 ;; + '') echo 3 ;; + *) die "Version channel ${1} is not alpha, beta, or a release" ;; + esac +} + +cmp_version() { + local left=$1 right=$2 + [[ "$left" =~ $ver_re ]] || die "Version ${left} has to look like 0.0.1 or 0.0.1-alpha" + local l1=${BASH_REMATCH[1]} l2=${BASH_REMATCH[2]} l3=${BASH_REMATCH[3]} ls=${BASH_REMATCH[4]} + [[ "$right" =~ $ver_re ]] || die "Version ${right} has to look like 0.0.1 or 0.0.1-alpha" + local r1=${BASH_REMATCH[1]} r2=${BASH_REMATCH[2]} r3=${BASH_REMATCH[3]} rs=${BASH_REMATCH[4]} + local lr rr + if ((l1 != r1)); then ((l1 > r1)) && echo gt || echo lt; return; fi + if ((l2 != r2)); then ((l2 > r2)) && echo gt || echo lt; return; fi + if ((l3 != r3)); then ((l3 > r3)) && echo gt || echo lt; return; fi + lr=$(channel_rank "$ls") + rr=$(channel_rank "$rs") + if ((lr != rr)); then ((lr > rr)) && echo gt || echo lt; return; fi + echo eq +} + +[[ $# -ge 1 ]] || die "Usage: release-version.sh parse|channel|next|read|write|cmp ..." +cmd=$1 +shift +case "$cmd" in + parse) [[ $# -eq 1 ]] || die "Usage: release-version.sh parse 0.0.1-alpha"; parse "$1" ;; + channel) [[ $# -eq 1 ]] || die "Usage: release-version.sh channel 0.0.1-alpha"; channel "$1" ;; + next) [[ $# -eq 1 ]] || die "Usage: release-version.sh next 0.0.1-alpha"; next_version "$1" ;; + read) [[ $# -eq 1 ]] || die "Usage: release-version.sh read gradle.properties"; read_version "$1" ;; + write) [[ $# -eq 2 ]] || die "Usage: release-version.sh write gradle.properties 0.2.0"; write_version "$1" "$2" ;; + cmp) [[ $# -eq 2 ]] || die "Usage: release-version.sh cmp 0.2.0 0.2.1"; cmp_version "$1" "$2" ;; + *) die "Unknown command: ${cmd}" ;; +esac diff --git a/.github/scripts/test_curseforge_versions.py b/.github/scripts/test_curseforge_versions.py new file mode 100644 index 0000000..0d4e3e6 --- /dev/null +++ b/.github/scripts/test_curseforge_versions.py @@ -0,0 +1,142 @@ +"""Version catalog captured on 2026-11-02, with synthetic environment IDs.""" +import contextlib +import io +import json +import os +from pathlib import Path +import runpy +import subprocess +import sys +import tempfile +import unittest + + +resolve = runpy.run_path(str(Path(__file__).with_name("curseforge-version-ids.py")))["resolve"] + +TYPES = [ + {"id": 2, "slug": "java"}, + {"id": 615, "slug": "addons"}, + {"id": 75208, "slug": "environment"}, + {"id": 68441, "slug": "modloader"}, + {"id": 66006, "slug": "minecraft-1-20"}, + {"id": 77784, "slug": "minecraft-1-21"}, + {"id": 88556, "slug": "minecraft-26-3"}, +] +VERSIONS = [ + {"id": 99901, "gameVersionTypeID": 75208, "name": "Client"}, + {"id": 99902, "gameVersionTypeID": 75208, "name": "Server"}, + {"id": 7499, "gameVersionTypeID": 68441, "name": "Fabric"}, + {"id": 10150, "gameVersionTypeID": 68441, "name": "NeoForge"}, + {"id": 11135, "gameVersionTypeID": 2, "name": "Java 21"}, + {"id": 12060, "gameVersionTypeID": 66006, "name": "1.20.6"}, + {"id": 11779, "gameVersionTypeID": 77784, "name": "1.21.1"}, + {"id": 12735, "gameVersionTypeID": 1, "name": "1.21.1"}, + {"id": 14454, "gameVersionTypeID": 2, "name": "Java 25"}, + {"id": 16115, "gameVersionTypeID": 615, "name": "1.21.1"}, + {"id": 17045, "gameVersionTypeID": 88556, "name": "26.3"}, + {"id": 17046, "gameVersionTypeID": 1, "name": "26.3"}, +] + + +class CurseForgeVersionsTest(unittest.TestCase): + def test_actual_duplicate_names_resolve_for_every_jar(self): + for game, loader, java, expected in ( + ("1.20.6", "NeoForge", "Java 21", [12060, 10150, 99901, 99902, 11135]), + ("1.21.1", "NeoForge", "Java 21", [11779, 10150, 99901, 99902, 11135]), + ("26.3", "Fabric", "Java 25", [17045, 7499, 99901, 99902, 14454]), + ("26.3", "NeoForge", "Java 25", [17045, 10150, 99901, 99902, 14454]), + ): + with self.subTest(game=game, loader=loader): + self.assertEqual(resolve(VERSIONS, TYPES, game, loader, java), expected) + + def test_data_envelopes(self): + self.assertEqual(resolve({"data": VERSIONS}, {"data": TYPES}, "26.3", "Fabric", "Java 25"), [17045, 7499, 99901, 99902, 14454]) + + def test_wrong_categories_are_not_used_as_fallback(self): + versions = [row for row in VERSIONS if row["id"] != 11779] + with self.assertRaisesRegex(ValueError, "minecraft-1-21"): + resolve(versions, TYPES, "1.21.1", "NeoForge", "Java 21") + + def test_ambiguous_id_within_correct_category_fails(self): + versions = VERSIONS + [{"id": 99999, "gameVersionTypeID": 77784, "name": "1.21.1"}] + with self.assertRaisesRegex(ValueError, "2 versions"): + resolve(versions, TYPES, "1.21.1", "NeoForge", "Java 21") + + def test_missing_or_ambiguous_category_fails(self): + for types in ( + [row for row in TYPES if row["slug"] != "modloader"], + TYPES + [{"id": 99999, "slug": "modloader"}], + ): + with self.assertRaisesRegex(ValueError, "modloader"): + resolve(VERSIONS, types, "26.3", "Fabric", "Java 25") + + def test_optional_java_can_be_absent(self): + with contextlib.redirect_stderr(io.StringIO()) as warning: + self.assertEqual(resolve(VERSIONS, TYPES, "26.3", "Fabric", "Java 99"), [17045, 7499, 99901, 99902]) + self.assertIn("omitting optional Java", warning.getvalue()) + + def test_empty_catalog_fails(self): + with self.assertRaisesRegex(ValueError, "empty or invalid"): + resolve([], TYPES, "26.3", "Fabric", "Java 25") + + def test_required_environment_is_not_silently_omitted(self): + versions = [row for row in VERSIONS if row["name"] != "Server"] + with self.assertRaisesRegex(ValueError, "environment"): + resolve(versions, TYPES, "26.3", "Fabric", "Java 25") + + def test_publisher_preflight_and_resolved_upload_metadata(self): + for valid in (False, True): + with self.subTest(valid=valid), tempfile.TemporaryDirectory(prefix="curseforge-test-") as folder: + root = Path(folder) + versions = VERSIONS if valid else [row for row in VERSIONS if row["id"] != 17045] + (root / "versions.json").write_text(json.dumps(versions), encoding="utf-8") + (root / "types.json").write_text(json.dumps(TYPES), encoding="utf-8") + (root / "notes.md").write_text("- Release notes.\n", encoding="utf-8") + for target in ("neoforge-1.20.6", "neoforge-1.21.1", "fabric-26.3", "neoforge-26.3"): + (root / f"primalpottery-{target}-0.0.2-alpha.jar").touch() + trace = root / "uploads.txt" + env = dict(os.environ, MODRINTH_TOKEN="test", CURSEFORGE_TOKEN="test", + MODRINTH_PROJECT_ID="test", CURSEFORGE_PROJECT_ID="123", + TAG="0.0.2-alpha", RELEASE_TYPE="alpha", TEST_DIR=root.as_posix(), + TEST_PYTHON=Path(sys.executable).as_posix()) + # Mock network and uploads; keep the actual publisher orchestration + # and Python category resolver. No credentials or services are used. + harness = r''' +source "$1" check-env +python3() { "$TEST_PYTHON" "$@"; } +http_code() { + case "${!#}" in + */game/versions) cp "$TEST_DIR/versions.json" "$1"; printf 200 ;; + */game/version-types) cp "$TEST_DIR/types.json" "$1"; printf 200 ;; + */files) printf '{}' > "$1"; printf 403 ;; + *) echo "Unexpected network request" >&2; exit 1 ;; + esac +} +modrinth_upload() { echo "Modrinth $1" >> "$TEST_DIR/uploads.txt"; } +curseforge_upload() { echo "CurseForge $4" >> "$TEST_DIR/uploads.txt"; } +github_release() { echo "GitHub $1" >> "$TEST_DIR/uploads.txt"; } +upload 0.0.2-alpha "$TEST_DIR/notes.md" "$TEST_DIR" +''' + result = subprocess.run( + [os.environ.get("BASH_EXECUTABLE", "bash"), "-c", harness, "test", + Path(__file__).with_name("release-publish.sh").resolve().as_posix()], + env=env, capture_output=True, text=True, + ) + if valid: + self.assertEqual(result.returncode, 0, result.stderr) + uploads = trace.read_text().splitlines() + self.assertEqual(len(uploads), 9) + self.assertEqual(uploads[4:8], [ + "CurseForge [12060, 10150, 99901, 99902, 11135]", + "CurseForge [11779, 10150, 99901, 99902, 11135]", + "CurseForge [17045, 7499, 99901, 99902, 14454]", + "CurseForge [17045, 10150, 99901, 99902, 14454]", + ]) + else: + self.assertNotEqual(result.returncode, 0) + self.assertIn("minecraft-26-3", result.stderr) + self.assertFalse(trace.exists(), "No upload should run when a required target is missing") + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/scripts/test_release_changelog.py b/.github/scripts/test_release_changelog.py new file mode 100644 index 0000000..a3b5369 --- /dev/null +++ b/.github/scripts/test_release_changelog.py @@ -0,0 +1,125 @@ +"""Release-note and archival checks; run with Python 3 and Bash, without uploads.""" +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + + +SCRIPTS = Path(__file__).resolve().parent +BASH = os.environ.get("BASH_EXECUTABLE", "bash") +HISTORY = """## 0.0.3-beta + +- Beta fixes. + +## 0.0.2-alpha + +- Alpha additions. +""" +OLDER = """ +## 0.0.1 + +- Previous stable changes. + +## 0.0.1-alpha + +- Older alpha changes. +""" + + +class ReleaseChangelogTest(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory(prefix="release-notes-test-") + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + self.changelog = self.root / "CHANGELOG.md" + + def write_changelog(self, new="- New changes.\n", history=HISTORY + OLDER): + self.changelog.write_text( + "# Changelog\n\nIntroduction.\n\n## Unreleased\n\n" + new + "\n" + history, + encoding="utf-8", + ) + + def run_script(self, script, *args, success=True): + result = subprocess.run( + [BASH, (SCRIPTS / script).as_posix(), *[ + arg.as_posix() if isinstance(arg, Path) else arg for arg in args + ]], capture_output=True, text=True, + ) + if success: + self.assertEqual(result.returncode, 0, result.stderr) + else: + self.assertNotEqual(result.returncode, 0) + return result.stdout + + def notes(self, version, success=True): + return self.run_script("release-changelog.sh", "notes", self.changelog, version, success=success) + + def test_prereleases_only_include_unreleased(self): + self.write_changelog() + for version in ("0.0.4-alpha", "0.0.4-beta"): + with self.subTest(version=version): + self.assertEqual(self.notes(version), "- New changes.\n") + + def test_first_stable_includes_all_prereleases_by_version(self): + self.write_changelog(history=HISTORY) + self.assertEqual(self.notes("0.0.4"), "## 0.0.4\n\n- New changes.\n\n" + HISTORY) + + def test_stable_stops_before_previous_stable(self): + self.write_changelog() + self.assertEqual(self.notes("0.0.4"), "## 0.0.4\n\n- New changes.\n\n" + HISTORY) + + def test_stable_without_prereleases(self): + self.write_changelog(history=OLDER.lstrip()) + self.assertEqual(self.notes("0.0.4"), "## 0.0.4\n\n- New changes.\n") + + def test_stable_without_any_history(self): + self.write_changelog(history="") + self.assertEqual(self.notes("0.0.1"), "## 0.0.1\n\n- New changes.\n") + + def test_promotion_archives_empty_stable_cutoff(self): + self.write_changelog(new="") + self.assertEqual(self.notes("0.0.4"), HISTORY) + tagged = self.root / "tagged.md" + tagged.write_bytes(self.changelog.read_bytes()) + properties = self.root / "gradle.properties" + properties.write_text("version=0.0.4\n", encoding="utf-8") + self.run_script("release-bump.sh", "0.0.4", "0.0.5", self.changelog, tagged, properties) + self.assertEqual(properties.read_text(), "version=0.0.5\n") + archived = self.changelog.read_text() + self.assertIn("## Unreleased\n\n## 0.0.4\n", archived) + self.assertEqual(archived.count("- Beta fixes."), 1) + self.assertEqual(archived.count("- Alpha additions."), 1) + self.changelog.write_text(archived.replace("## Unreleased\n", "## Unreleased\n\n- Next cycle.\n"), encoding="utf-8") + self.assertEqual(self.notes("0.0.5"), "## 0.0.5\n\n- Next cycle.\n") + + def test_stable_bump_only_archives_new_notes(self): + self.write_changelog() + self.run_script("release-changelog.sh", "bump", self.changelog, "0.0.4") + archived = self.changelog.read_text() + self.assertIn("## 0.0.4\n\n- New changes.\n\n## 0.0.3-beta", archived) + self.assertEqual(archived.count("- Beta fixes."), 1) + + def test_empty_prereleases_and_empty_stable_cycle_fail(self): + self.write_changelog(new="") + for version in ("0.0.4-alpha", "0.0.4-beta"): + self.notes(version, success=False) + self.write_changelog(new="", history=OLDER.lstrip()) + self.notes("0.0.4", success=False) + + def test_invalid_changelog_or_version_fails(self): + for heading in ("Typo", "0x0x3-alpha"): + self.write_changelog(history=f"## {heading}\n\n- Changes.\n") + self.notes("0.0.4", success=False) + self.notes("invalid", success=False) + self.changelog.write_text("# No Unreleased section\n", encoding="utf-8") + self.notes("0.0.4", success=False) + + def test_large_accumulated_history(self): + history = "## 0.0.3-beta\n\n" + "- An earlier change.\n" * 10000 + self.write_changelog(history=history + OLDER) + self.assertEqual(self.notes("0.0.4"), "## 0.0.4\n\n- New changes.\n\n" + history) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/scripts/test_release_commit.py b/.github/scripts/test_release_commit.py new file mode 100644 index 0000000..859b598 --- /dev/null +++ b/.github/scripts/test_release_commit.py @@ -0,0 +1,101 @@ +"""Exercise direct release commits against temporary local Git repositories.""" +import os +from pathlib import Path +import shlex +import shutil +import subprocess +import tempfile +import unittest + + +SCRIPTS = Path(__file__).resolve().parent +BASH = os.environ.get("BASH_EXECUTABLE", "bash") + + +class ReleaseCommitTest(unittest.TestCase): + def git(self, directory, *args): + result = subprocess.run(["git", "-C", str(directory), *args], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr) + return result.stdout.strip() + + def setUp(self): + self.temp = tempfile.TemporaryDirectory(prefix="release-commit-test-") + self.addCleanup(self.temp.cleanup) + root = Path(self.temp.name) + self.remote = root / "remote.git" + self.writer = root / "writer" + self.runner = root / "runner" + self.git(root, "init", "--bare", str(self.remote)) + self.git(root, "init", "--initial-branch=main", str(self.writer)) + self.git(self.writer, "config", "user.name", "Release test") + self.git(self.writer, "config", "user.email", "release-test@example.invalid") + self.git(self.writer, "config", "core.autocrlf", "false") + scripts = self.writer / ".github/scripts" + scripts.mkdir(parents=True) + for source in SCRIPTS.glob("release-*.sh"): + shutil.copyfile(source, scripts / source.name) + (self.writer / "gradle.properties").write_text("version=0.0.1\n", encoding="utf-8") + (self.writer / "CHANGELOG.md").write_text("# Changelog\n\n## Unreleased\n\n- First changes.\n", encoding="utf-8") + self.git(self.writer, "add", ".") + self.git(self.writer, "commit", "-m", "Initial release") + self.git(self.writer, "tag", "0.0.1-alpha") + self.git(self.writer, "remote", "add", "origin", str(self.remote)) + self.git(self.writer, "push", "origin", "main", "0.0.1-alpha") + self.git(root, "clone", "--branch", "main", str(self.remote), str(self.runner)) + self.git(self.runner, "checkout", "--detach", "0.0.1-alpha") + + def bump(self, success=True): + result = subprocess.run( + [BASH, ".github/scripts/release-commit.sh", "0.0.1-alpha", "0.0.2", "0.0.1-alpha"], + cwd=self.runner, capture_output=True, text=True, + ) + if success: + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + else: + self.assertNotEqual(result.returncode, 0) + return result + + def test_direct_commit_and_idempotent_rerun(self): + tagged = self.git(self.remote, "rev-parse", "0.0.1-alpha") + self.bump() + committed = self.git(self.remote, "rev-parse", "main") + self.assertNotEqual(committed, tagged) + self.assertEqual(self.git(self.remote, "show", "main:gradle.properties"), "version=0.0.2") + self.assertIn("## Unreleased\n\n## 0.0.1-alpha", self.git(self.remote, "show", "main:CHANGELOG.md")) + self.assertEqual(self.git(self.remote, "rev-parse", "0.0.1-alpha"), tagged) + self.assertEqual(self.git(self.remote, "for-each-ref", "--format=%(refname)", "refs/heads"), "refs/heads/main") + self.bump() + self.assertEqual(self.git(self.remote, "rev-parse", "main"), committed) + + def test_newer_main_notes_are_preserved(self): + changelog = self.writer / "CHANGELOG.md" + changelog.write_text(changelog.read_text().replace("## Unreleased\n", "## Unreleased\n\n- Added during build.\n"), encoding="utf-8") + self.git(self.writer, "add", "CHANGELOG.md") + self.git(self.writer, "commit", "-m", "Concurrent changes") + self.git(self.writer, "push", "origin", "main") + self.bump() + self.assertEqual(self.git(self.remote, "show", "main:CHANGELOG.md"), changelog.read_text().strip()) + self.assertEqual(self.git(self.remote, "show", "main:gradle.properties"), "version=0.0.2") + + def test_push_race_is_rejected_and_rerun_preserves_concurrent_commit(self): + (self.writer / "concurrent.txt").write_text("Keep this change.\n", encoding="utf-8") + self.git(self.writer, "add", "concurrent.txt") + self.git(self.writer, "commit", "-m", "Concurrent commit") + concurrent = self.git(self.writer, "rev-parse", "HEAD") + # Advance remote main after the release script fetches, just before its push. + hook = self.runner / ".git/hooks/pre-push" + hook.write_text( + "#!/usr/bin/env bash\nset -eu\n" + + "env -u GIT_DIR -u GIT_WORK_TREE git -C " + shlex.quote(self.writer.as_posix()) + + ' push origin main\nrm -- "$0"\n', encoding="utf-8", + ) + hook.chmod(0o755) + self.bump(success=False) + self.assertEqual(self.git(self.remote, "rev-parse", "main"), concurrent) + self.bump() + self.assertEqual(self.git(self.remote, "rev-parse", "main^"), concurrent) + self.assertEqual(self.git(self.remote, "show", "main:concurrent.txt"), "Keep this change.") + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..269d38b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,115 @@ +name: CI + +# Every pull request must build and pass on every Minecraft version before it can merge. +# `all-versions` requires every version job and the release-script checks, so it is the one check for a ruleset on main to require. +on: + pull_request: + push: + branches: [main] + +jobs: + release-scripts: + name: Release script checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - run: python3 .github/scripts/test_release_changelog.py + - run: python3 .github/scripts/test_release_commit.py + - run: python3 .github/scripts/test_curseforge_versions.py + + mc-26-3: + name: Minecraft 26.3 (Fabric + NeoForge) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: | + 21 + 25 + - uses: gradle/actions/setup-gradle@v6 + + # Git must hold the sources in their 26.3 state; Stonecutter rewrites them when another version is active. + - name: Check the sources are committed with 26.3 active + run: | + ./gradlew "Reset active project" + git diff --exit-code + + # Every version comment and replacement in stonecutter.gradle.kts has to turn back exactly, or switching the + # IDE to another version and back would rewrite code. The build itself never switches, so check it here. + - name: Check switching to 1.21.1 and back changes nothing + run: | + ./gradlew "Set active project to 1.21.1" + ./gradlew "Reset active project" + git diff --exit-code + + - name: Check switching to 1.20.6 and back changes nothing + run: | + ./gradlew "Set active project to 1.20.6" + ./gradlew "Reset active project" + git diff --exit-code + + - name: Unit tests, jars and server game test + run: ./gradlew :26.3:test :fabric:26.3:build :neoforge:26.3:build :neoforge:26.3:runGameTestServer + + - name: Collect jars + run: ./gradlew collectJars + + - uses: actions/upload-artifact@v7 + with: + name: jars-26.3 + path: build/libs/*/*.jar + + mc-1-20-6: + name: Minecraft 1.20.6 (NeoForge) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: | + 21 + 25 + - uses: gradle/actions/setup-gradle@v6 + + - name: Unit tests and jar + run: ./gradlew :1.20.6:test :neoforge:1.20.6:build + + - uses: actions/upload-artifact@v7 + with: + name: jars-1.20.6 + path: neoforge/versions/1.20.6/build/libs/primalpottery-neoforge-1.20.6-*.jar + + mc-1-21-1: + name: Minecraft 1.21.1 (NeoForge) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: | + 21 + 25 + - uses: gradle/actions/setup-gradle@v6 + + - name: Unit tests and jar + run: ./gradlew :1.21.1:test :neoforge:1.21.1:build + + - uses: actions/upload-artifact@v7 + with: + name: jars-1.21.1 + path: neoforge/versions/1.21.1/build/libs/primalpottery-neoforge-1.21.1-*.jar + + all-versions: + name: all-versions + if: always() + needs: [mc-26-3, mc-1-20-6, mc-1-21-1, release-scripts] + runs-on: ubuntu-latest + steps: + - name: Every check passed + run: | + echo '${{ toJSON(needs) }}' + [ "${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}" = "false" ] diff --git a/.github/workflows/discord-merge-notify.yml b/.github/workflows/discord-merge-notify.yml new file mode 100644 index 0000000..41af3ad --- /dev/null +++ b/.github/workflows/discord-merge-notify.yml @@ -0,0 +1,26 @@ +name: Discord merge notify +on: + pull_request: + types: [closed] +jobs: + notify: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + # The merge commit and its first parent, so the script can see which changelog bullets the merge added. + - uses: actions/checkout@v7 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + fetch-depth: 2 + + - name: Post the title and new changelog bullets + env: + WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + MERGE: ${{ github.event.pull_request.merge_commit_sha }} + REPO: ${{ github.event.repository.name }} + NUMBER: ${{ github.event.pull_request.number }} + TITLE: ${{ github.event.pull_request.title }} + URL: ${{ github.event.pull_request.html_url }} + run: | + bash .github/scripts/discord-merge-message.sh "$MERGE" "$REPO" "$NUMBER" "$TITLE" "$URL" \ + | curl -sf -H "Content-Type: application/json" -d @- "$WEBHOOK" diff --git a/.github/workflows/release-metadata.yml b/.github/workflows/release-metadata.yml new file mode 100644 index 0000000..8fc75a6 --- /dev/null +++ b/.github/workflows/release-metadata.yml @@ -0,0 +1,27 @@ +name: Inspect release metadata + +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + curseforge: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - name: Validate target game versions without uploading + env: + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + run: | + set -euo pipefail + curl --fail-with-body -sS -H "X-Api-Token: ${CURSEFORGE_TOKEN}" \ + https://minecraft.curseforge.com/api/game/versions > versions.json + curl --fail-with-body -sS -H "X-Api-Token: ${CURSEFORGE_TOKEN}" \ + https://minecraft.curseforge.com/api/game/version-types > types.json + jq --slurpfile types types.json '[$types[0][] | select(.slug == "environment") | .id] as $ids | [.[] | select(.gameVersionTypeID as $id | $ids | index($id))]' versions.json + python3 .github/scripts/curseforge-version-ids.py versions.json types.json 1.20.6 NeoForge "Java 21" + python3 .github/scripts/curseforge-version-ids.py versions.json types.json 1.21.1 NeoForge "Java 21" + python3 .github/scripts/curseforge-version-ids.py versions.json types.json 26.3 Fabric "Java 25" + python3 .github/scripts/curseforge-version-ids.py versions.json types.json 26.3 NeoForge "Java 25" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ee13050 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,232 @@ +name: Release + +# Tag 0.0.1 to publish a release, or 0.0.1-alpha / 0.0.1-beta for that channel. A leading v +# is also accepted. The version edit is made in the build checkout only, so the tag stays +# on the commit you tagged. After the upload, the action commits the next patch to main +# and moves the published notes under that version. +# +# Repository secrets: MODRINTH_TOKEN, CURSEFORGE_TOKEN. +# Repository variables: MODRINTH_PROJECT_ID, CURSEFORGE_PROJECT_ID. +# Tag a commit that is already on main. This file, on that commit, is what runs. +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+-alpha" + - "[0-9]+.[0-9]+.[0-9]+-beta" + - "v[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+-alpha" + - "v[0-9]+.[0-9]+.[0-9]+-beta" + +permissions: + contents: read + +concurrency: + group: release + cancel-in-progress: false + +jobs: + notes: + name: Check the tag + runs-on: ubuntu-latest + outputs: + version: ${{ steps.meta.outputs.version }} + next: ${{ steps.meta.outputs.next }} + channel: ${{ steps.meta.outputs.channel }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: The tag is on main + run: | + set -euo pipefail + git fetch origin main + git merge-base --is-ancestor "$GITHUB_SHA" origin/main || { + echo "The tag is not on main. Tag a commit that is already on main." + exit 1 + } + + - name: Secrets and the changelog + id: meta + env: + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + MODRINTH_PROJECT_ID: ${{ vars.MODRINTH_PROJECT_ID }} + CURSEFORGE_PROJECT_ID: ${{ vars.CURSEFORGE_PROJECT_ID }} + run: | + set -euo pipefail + bash .github/scripts/release-publish.sh check-env + version=$(bash .github/scripts/release-version.sh parse "$GITHUB_REF_NAME") + channel=$(bash .github/scripts/release-version.sh channel "$GITHUB_REF_NAME") + next=$(bash .github/scripts/release-version.sh next "$version") + echo "version=${version}" >> "$GITHUB_OUTPUT" + echo "channel=${channel}" >> "$GITHUB_OUTPUT" + echo "next=${next}" >> "$GITHUB_OUTPUT" + bash .github/scripts/release-changelog.sh notes CHANGELOG.md "$version" > release-notes.md + + - uses: actions/upload-artifact@v7 + with: + name: release-notes + path: release-notes.md + + mc-26-3: + name: Minecraft 26.3 (Fabric + NeoForge) + needs: notes + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: | + 21 + 25 + - uses: gradle/actions/setup-gradle@v6 + + - name: Check the sources are committed with 26.3 active + run: | + ./gradlew "Reset active project" + git diff --exit-code + + - name: Check switching to 1.21.1 and back changes nothing + run: | + ./gradlew "Set active project to 1.21.1" + ./gradlew "Reset active project" + git diff --exit-code + + - name: Check switching to 1.20.6 and back changes nothing + run: | + ./gradlew "Set active project to 1.20.6" + ./gradlew "Reset active project" + git diff --exit-code + + - name: Set the published version + run: bash .github/scripts/release-version.sh write gradle.properties "${{ needs.notes.outputs.version }}" + + - name: Unit tests and jars + run: ./gradlew :26.3:test :fabric:26.3:build :neoforge:26.3:build + + - name: Collect jars + run: ./gradlew collectJars + + - uses: actions/upload-artifact@v7 + with: + name: jars-26.3 + if-no-files-found: error + path: | + build/libs/*/primalpottery-fabric-26.3-*.jar + build/libs/*/primalpottery-neoforge-26.3-*.jar + !**/*-sources.jar + !**/*-javadoc.jar + !**/*-dev.jar + + mc-1-20-6: + name: Minecraft 1.20.6 (NeoForge) + needs: notes + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: | + 21 + 25 + - uses: gradle/actions/setup-gradle@v6 + + - name: Set the published version + run: bash .github/scripts/release-version.sh write gradle.properties "${{ needs.notes.outputs.version }}" + + - name: Unit tests and jar + run: ./gradlew :1.20.6:test :neoforge:1.20.6:build + + - uses: actions/upload-artifact@v7 + with: + name: jars-1.20.6 + if-no-files-found: error + path: | + neoforge/versions/1.20.6/build/libs/primalpottery-neoforge-1.20.6-*.jar + !**/*-sources.jar + !**/*-javadoc.jar + !**/*-dev.jar + + mc-1-21-1: + name: Minecraft 1.21.1 (NeoForge) + needs: notes + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: | + 21 + 25 + - uses: gradle/actions/setup-gradle@v6 + + - name: Set the published version + run: bash .github/scripts/release-version.sh write gradle.properties "${{ needs.notes.outputs.version }}" + + - name: Unit tests and jar + run: ./gradlew :1.21.1:test :neoforge:1.21.1:build + + - uses: actions/upload-artifact@v7 + with: + name: jars-1.21.1 + if-no-files-found: error + path: | + neoforge/versions/1.21.1/build/libs/primalpottery-neoforge-1.21.1-*.jar + !**/*-sources.jar + !**/*-javadoc.jar + !**/*-dev.jar + + publish: + name: Publish + needs: [notes, mc-26-3, mc-1-20-6, mc-1-21-1] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v7 + + - uses: actions/download-artifact@v7 + with: + name: release-notes + path: notes + + - uses: actions/download-artifact@v7 + with: + pattern: jars-* + path: jars + + - name: Upload the release + env: + GH_TOKEN: ${{ github.token }} + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + MODRINTH_PROJECT_ID: ${{ vars.MODRINTH_PROJECT_ID }} + CURSEFORGE_PROJECT_ID: ${{ vars.CURSEFORGE_PROJECT_ID }} + RELEASE_TYPE: ${{ needs.notes.outputs.channel }} + TAG: ${{ github.ref_name }} + run: bash .github/scripts/release-publish.sh upload "${{ needs.notes.outputs.version }}" notes/release-notes.md jars + + bump: + name: Next version + needs: [notes, publish] + if: needs.publish.result == 'success' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Commit the next version to main + env: + VERSION: ${{ needs.notes.outputs.version }} + NEXT: ${{ needs.notes.outputs.next }} + TAG: ${{ github.ref_name }} + run: bash .github/scripts/release-commit.sh "$VERSION" "$NEXT" "$TAG" diff --git a/.github/workflows/retry-release.yml b/.github/workflows/retry-release.yml new file mode 100644 index 0000000..9b58027 --- /dev/null +++ b/.github/workflows/retry-release.yml @@ -0,0 +1,88 @@ +name: Retry release publication + +# Uses the original tag's built jars and notes, with the publishing scripts on +# main. This repairs a partial publication without moving a tag or rebuilding. +on: + workflow_dispatch: + inputs: + tag: + description: Existing release tag + required: true + type: string + run_id: + description: Failed Release run containing the original artifacts + required: true + type: string + +permissions: + contents: write + actions: read + +concurrency: + group: release + cancel-in-progress: false + +jobs: + retry: + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Validate the tag and original build + id: meta + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ inputs.tag }} + RUN_ID: ${{ inputs.run_id }} + run: | + set -euo pipefail + [[ "$RUN_ID" =~ ^[0-9]+$ ]] + version=$(bash .github/scripts/release-version.sh parse "$TAG") + sha=$(git rev-parse "refs/tags/${TAG}^{commit}") + git merge-base --is-ancestor "$sha" origin/main + gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}" > "$RUNNER_TEMP/release-run.json" + jq -e --arg tag "$TAG" --arg sha "$sha" ' + .head_branch == $tag and .head_sha == $sha and .event == "push" + and .path == ".github/workflows/release.yml" + and .status == "completed" and .conclusion == "failure" + ' "$RUNNER_TEMP/release-run.json" >/dev/null + echo "version=${version}" >> "$GITHUB_OUTPUT" + echo "channel=$(bash .github/scripts/release-version.sh channel "$TAG")" >> "$GITHUB_OUTPUT" + echo "next=$(bash .github/scripts/release-version.sh next "$version")" >> "$GITHUB_OUTPUT" + + - uses: actions/download-artifact@v7 + with: + name: release-notes + path: ${{ runner.temp }}/release-notes + run-id: ${{ inputs.run_id }} + github-token: ${{ github.token }} + + - uses: actions/download-artifact@v7 + with: + pattern: jars-* + path: ${{ runner.temp }}/release-jars + run-id: ${{ inputs.run_id }} + github-token: ${{ github.token }} + + - name: Complete publication + env: + GH_TOKEN: ${{ github.token }} + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + MODRINTH_PROJECT_ID: ${{ vars.MODRINTH_PROJECT_ID }} + CURSEFORGE_PROJECT_ID: ${{ vars.CURSEFORGE_PROJECT_ID }} + TAG: ${{ inputs.tag }} + VERSION: ${{ steps.meta.outputs.version }} + RELEASE_TYPE: ${{ steps.meta.outputs.channel }} + run: bash .github/scripts/release-publish.sh upload "$VERSION" "$RUNNER_TEMP/release-notes/release-notes.md" "$RUNNER_TEMP/release-jars" + + - name: Commit the next version to main + env: + TAG: ${{ inputs.tag }} + VERSION: ${{ steps.meta.outputs.version }} + NEXT: ${{ steps.meta.outputs.next }} + run: bash .github/scripts/release-commit.sh "$VERSION" "$NEXT" "$TAG" diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1c8e0e9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + +Each pull request adds its own bullets at the top of **Unreleased**, written for players. When a merge lands, the Discord message shows only the bullets that pull request added. + +Push a version tag to publish. Alpha and beta releases use only **Unreleased**. Stable releases include those new notes under the tagged version, followed by every alpha/beta section since the previous stable release, newest first. The first stable release includes all earlier alpha/beta sections. The same notes go to CurseForge, Modrinth, and GitHub. + +After publishing, the action commits the next development version and changelog update directly to **main**. It renames **Unreleased** to the tagged version and starts a new empty **Unreleased** above it; earlier sections stay in place without duplication. If the unpublished notes on main changed during the release, they are left untouched for manual reconciliation. A stable release with no new changes can publish the accumulated alpha/beta notes; its empty version heading still marks the cutoff for the next stable release. Concurrent pushes are never overwritten; rerun a rejected update after main advances. The action needs permission to push to main. + +## Unreleased + +- NeoForge runs on Minecraft 1.20.6, 1.21.1, and 26.3. Fabric runs on 26.3. +- A pottery wheel spins when you use it with an empty hand. Use a clay ball on it and the clay forms toward the blueprint installed on the wheel. Take the piece off when you want it. The clay ball stays in your hand. +- Edit a raw pottery template. The left mouse button sets the outer radius and the right sets the inner. Saving turns it into a pottery blueprint. A blueprint can be edited again, set on the wheel, or crafted by itself back into a blank raw template. +- A sealed shape is a pot, a jar, or a jug from how wide the mouth is next to the widest point. Wider than nine tenths is a pot, under half is a jug, and between those is a jar. The tooltip names the type and how many millilitres it holds. A shape that is not a vessel says Lump. +- Finished pottery can sit in four places in one block. Pick a piece back up. From 736ab67749a3a3e5cc31da5e730062c11fd848be Mon Sep 17 00:00:00 2001 From: Face o' Cat <face@modcrafters.net> Date: Wed, 25 Nov 2026 14:22:18 +0200 Subject: [PATCH 2/4] Make gradlew executable so Linux CI can run it. --- gradlew | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From 8c919839b2514d92c4e4389e9065e554e010c4ca Mon Sep 17 00:00:00 2001 From: Face o' Cat <face@modcrafters.net> Date: Wed, 25 Nov 2026 14:28:12 +0200 Subject: [PATCH 3/4] Keep the Fabric access widener out of the sources Stonecutter rewrites. --- fabric/build.gradle | 4 +++- .../src}/main/resources/primalpottery.accesswidener | 0 2 files changed, 3 insertions(+), 1 deletion(-) rename {src => fabric/src}/main/resources/primalpottery.accesswidener (100%) diff --git a/fabric/build.gradle b/fabric/build.gradle index df1f52a..1601f26 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -10,7 +10,9 @@ dependencies { } loom { - def aw = rootProject.file("src/main/resources/${mod_id}.accesswidener") + // Keep this next to the Fabric mod metadata. Shared src is an output of the common stonecutterMerge, + // and validateAccessWidener fails if it reads that tree without depending on the merge. + def aw = file("src/main/resources/${mod_id}.accesswidener") if (aw.exists()) { accessWidenerPath.set(aw) } diff --git a/src/main/resources/primalpottery.accesswidener b/fabric/src/main/resources/primalpottery.accesswidener similarity index 100% rename from src/main/resources/primalpottery.accesswidener rename to fabric/src/main/resources/primalpottery.accesswidener From 8cba3920c9774e73701ce8cd1e05fe1575760811 Mon Sep 17 00:00:00 2001 From: Face o' Cat <face@modcrafters.net> Date: Wed, 25 Nov 2026 14:44:16 +0200 Subject: [PATCH 4/4] Aim the wheel game test at the disc that spins. --- .../neoforge/PotteryGameTests.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/neoforge/versions/26.3/src/main/java/net/modcrafters/minecraft/primalpottery/neoforge/PotteryGameTests.java b/neoforge/versions/26.3/src/main/java/net/modcrafters/minecraft/primalpottery/neoforge/PotteryGameTests.java index 6241879..a7c9881 100644 --- a/neoforge/versions/26.3/src/main/java/net/modcrafters/minecraft/primalpottery/neoforge/PotteryGameTests.java +++ b/neoforge/versions/26.3/src/main/java/net/modcrafters/minecraft/primalpottery/neoforge/PotteryGameTests.java @@ -61,14 +61,14 @@ private static void wheel(GameTestHelper helper) { checkTemplateCycle(helper, player); - look(helper, player, 1.5, 2.2, -0.2, 1.5, 2.2, 1.5); + aim(player, partCenter(helper, wheelPos, PotteryWheelBlockEntity.BIG_WHEEL)); player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); helper.useBlock(wheelPos, player); helper.assertValueEqual(wheel.spinTicks(), 24, "spin ticks"); ItemStack clay = new ItemStack(Items.CLAY_BALL); player.setItemInHand(InteractionHand.MAIN_HAND, clay); - look(helper, player, 1.5, 4.0, 1.5, 1.5, 2.84, 1.5); + aim(player, partCenter(helper, wheelPos, PotteryWheelBlockEntity.SMALL_WHEEL)); helper.useBlock(wheelPos, player); helper.assertTrue(wheel.hasClay(), "clay did not start"); helper.assertTrue(clay.is(Items.CLAY_BALL), "clay ball was consumed"); @@ -102,7 +102,7 @@ private static void wheel(GameTestHelper helper) { helper.assertTrue(pots.get(0) != null, "pot was not placed"); player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); - look(helper, player, 3.25, 4.0, 1.25, 3.25, 2.2, 1.25); + aim(player, PotteryBlockEntity.BOXES.getFirst().move(helper.absolutePos(floor.above())).getCenter()); helper.useBlock(floor.above(), player); helper.assertBlockNotPresent(ModBlocks.POTTERY, floor.above()); potteryItem(helper); @@ -146,10 +146,20 @@ private static ItemStack potteryItem(GameTestHelper helper) { return items.getFirst().getItem(); } - private static void look(GameTestHelper helper, Player player, double x, double y, double z, double lookX, double lookY, double lookZ) { - Vec3 eye = helper.absoluteVec(new Vec3(x, y, z)); - player.setPos(eye.x, eye.y - player.getEyeHeight(), eye.z); - player.lookAt(net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.EYES, helper.absoluteVec(new Vec3(lookX, lookY, lookZ))); + private static Vec3 partCenter(GameTestHelper helper, BlockPos relative, int part) { + return PotteryWheelBlockEntity.BOXES.get(part).move(helper.absolutePos(relative)).getCenter(); + } + + private static void aim(Player player, Vec3 at) { + // useBlock ignores the crosshair and hits the block center. The wheel and pottery + // still choose a part from the eye ray, so the eyes have to sit on a ray through that part. + placeEyes(player, at.add(0, 0, -1)); + player.lookAt(net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.EYES, at); + } + + private static void placeEyes(Player player, Vec3 eye) { + Vec3 actual = player.getEyePosition(); + player.setPos(player.getX() + eye.x - actual.x, player.getY() + eye.y - actual.y, player.getZ() + eye.z - actual.z); } private static final class Wheel extends GameTestInstance {