Skip to content
Closed

Test #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/resources/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/resources/settings1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/resources/settings2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions .github/scripts/setup-test-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Sets up a Fabric server with Fabric API and PackTest for the given Minecraft version in the current directory.
# Exit code 3 means the tooling is not available for that version (yet), any other non-zero code is a real error.
set -euo pipefail

MC="$1"
UA="Moggla/Timber-Datapack CI"

# prints the download url of the newest release of a Modrinth project for $MC, or nothing if there is none
modrinth_url() {
curl -fsSL -A "$UA" -G "https://api.modrinth.com/v2/project/$1/version" \
--data-urlencode "game_versions=[\"$MC\"]" \
--data-urlencode 'loaders=["fabric"]' \
| jq -r '[.[] | select(.version_type == "release")][0].files[0].url // empty'
}

FABRIC_API=$(modrinth_url fabric-api)
PACKTEST=$(modrinth_url packtest)
LOADER=$(curl -fsSL https://meta.fabricmc.net/v2/versions/loader | jq -r '[.[] | select(.stable)][0].version')
INSTALLER=$(curl -fsSL https://meta.fabricmc.net/v2/versions/installer | jq -r '[.[] | select(.stable)][0].version')
# the meta api answers unknown versions with an error or an empty list
SERVER=$(curl -sSL "https://meta.fabricmc.net/v2/versions/loader/$MC" | jq -r 'if type == "array" and length > 0 then "yes" else empty end' 2>/dev/null || true)

MISSING=""
[ -n "$SERVER" ] || MISSING="$MISSING Fabric server,"
[ -n "$FABRIC_API" ] || MISSING="$MISSING Fabric API,"
[ -n "$PACKTEST" ] || MISSING="$MISSING PackTest,"
if [ -n "$MISSING" ]; then
echo "Not available for Minecraft $MC yet:${MISSING%,}" >&2
exit 3
fi

mkdir -p mods
curl -fsSL -o server.jar "https://meta.fabricmc.net/v2/versions/loader/$MC/$LOADER/$INSTALLER/server/jar"
curl -fsSL -o mods/fabric-api.jar "$FABRIC_API"
curl -fsSL -o mods/packtest.jar "$PACKTEST"
echo "eula=true" > eula.txt
109 changes: 109 additions & 0 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Latest Minecraft

# Checks whether the datapack works on a Minecraft release newer than the ones in the test matrix
# and opens an issue with the result, so that nobody has to look at the runs.
# Not a required check: Fabric, Fabric API and PackTest usually lag a few days behind a new release.
on:
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:

permissions:
contents: read
issues: write

jobs:
latest:
name: Latest Minecraft release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Find latest release
id: version
run: |
MANIFEST=$(curl -fsSL https://piston-meta.mojang.com/mc/game/version_manifest_v2.json)
MC=$(jq -r '.latest.release' <<< "$MANIFEST")
URL=$(jq -r --arg id "$MC" '.versions[] | select(.id == $id) | .url' <<< "$MANIFEST")
JAVA=$(curl -fsSL "$URL" | jq -r '.javaVersion.majorVersion')

# highest version that the test matrix already covers
SUPPORTED=$(sed -n 's/.*minecraft: "\([^"]*\)".*/\1/p' .github/workflows/test.yml | sort -V | tail -n 1)

echo "mc=$MC" >> "$GITHUB_OUTPUT"
echo "java=$JAVA" >> "$GITHUB_OUTPUT"
if [ "$MC" != "$SUPPORTED" ] && [ "$(printf '%s\n%s\n' "$SUPPORTED" "$MC" | sort -V | tail -n 1)" = "$MC" ]; then
echo "newer=true" >> "$GITHUB_OUTPUT"
echo "Latest Minecraft release $MC is newer than the supported $SUPPORTED (Java $JAVA)"
else
echo "newer=false" >> "$GITHUB_OUTPUT"
echo "Latest Minecraft release $MC is already covered by the test matrix (highest: $SUPPORTED)." | tee -a "$GITHUB_STEP_SUMMARY"
fi

- uses: actions/setup-java@v4
if: steps.version.outputs.newer == 'true'
with:
distribution: temurin
java-version: ${{ steps.version.outputs.java }}

- name: Set up Fabric server, Fabric API and PackTest
id: setup
if: steps.version.outputs.newer == 'true'
run: |
set +e
bash .github/scripts/setup-test-server.sh "${{ steps.version.outputs.mc }}"
CODE=$?
if [ $CODE -eq 3 ]; then
echo "ready=false" >> "$GITHUB_OUTPUT"
echo "Minecraft ${{ steps.version.outputs.mc }} can't be tested yet, the test tooling isn't available for it. Trying again next time." | tee -a "$GITHUB_STEP_SUMMARY"
exit 0
fi
[ $CODE -eq 0 ] || exit $CODE
echo "ready=true" >> "$GITHUB_OUTPUT"

- name: Install datapacks
if: steps.setup.outputs.ready == 'true'
run: |
mkdir -p world/datapacks/timber world/datapacks/timber_test
cp -r data pack.mcmeta 121 world/datapacks/timber/
cp -r tests/. world/datapacks/timber_test/

- name: Run tests
id: tests
if: steps.setup.outputs.ready == 'true'
continue-on-error: true
run: java -Xmx2G -Dpacktest.auto -Dpacktest.auto.annotations -jar server.jar nogui

- name: Open an issue with the result
if: steps.setup.outputs.ready == 'true'
env:
GH_TOKEN: ${{ github.token }}
MC: ${{ steps.version.outputs.mc }}
OUTCOME: ${{ steps.tests.outcome }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ "$OUTCOME" = "success" ]; then
TITLE="Minecraft $MC works with the datapack"
BODY="The tests pass on Minecraft $MC ([run]($RUN_URL)).

To support it:
- bump \`max_format\` in \`pack.mcmeta\`
- add \`$MC\` to the matrix in \`.github/workflows/test.yml\`
- release the update"
else
TITLE="Minecraft $MC breaks the datapack"
BODY="The tests fail on Minecraft $MC ([run]($RUN_URL)). See the annotations of the run for the failed tests."
fi

# closed issues count too, so a handled version doesn't get reported again
EXISTING=$(gh issue list --state all --search "\"$TITLE\" in:title" --json title --jq "[.[] | select(.title == \"$TITLE\")] | length")
if [ "$EXISTING" -gt 0 ]; then
echo "Issue \"$TITLE\" already exists." | tee -a "$GITHUB_STEP_SUMMARY"
else
gh issue create --title "$TITLE" --body "$BODY" --label "CI/CD"
echo "Opened issue \"$TITLE\"." | tee -a "$GITHUB_STEP_SUMMARY"
fi

- name: Fail if the tests failed
if: steps.tests.outcome == 'failure'
run: exit 1
48 changes: 48 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Test

on:
pull_request:
push:
branches: [main]

jobs:
test:
name: Minecraft ${{ matrix.minecraft }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- minecraft: "26.1.2"
java: "25"
- minecraft: "26.3"
java: "25"
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ matrix.java }}

- name: Set up Fabric server, Fabric API and PackTest
run: bash .github/scripts/setup-test-server.sh "${{ matrix.minecraft }}"

- name: Install datapacks
run: |
mkdir -p world/datapacks/timber world/datapacks/timber_test
cp -r data pack.mcmeta 121 world/datapacks/timber/
cp -r tests/. world/datapacks/timber_test/

- name: Run tests
run: java -Xmx2G -Dpacktest.auto -Dpacktest.auto.annotations -jar server.jar nogui

# single check to require in the branch ruleset, so changing the matrix doesn't need a ruleset update
test-result:
name: Test result
needs: test
if: always()
runs-on: ubuntu-latest
steps:
- name: Fail if any test job failed or was cancelled
run: test "${{ needs.test.result }}" = "success"
52 changes: 0 additions & 52 deletions 18-26/data/minecraft/loot_tables/blocks/mushroom_stem.json

This file was deleted.

17 changes: 0 additions & 17 deletions 18-26/data/timber/functions/autoplant/plant.mcfunction

This file was deleted.

38 changes: 0 additions & 38 deletions 18-26/data/timber/functions/init.mcfunction

This file was deleted.

46 changes: 0 additions & 46 deletions 18-26/data/timber/functions/run.mcfunction

This file was deleted.

25 changes: 0 additions & 25 deletions 18-26/data/timber/functions/slow_chop/destroy_loop.mcfunction

This file was deleted.

3 changes: 0 additions & 3 deletions 18-26/data/timber/functions/tool/wear_out.mcfunction

This file was deleted.

Loading
Loading