diff --git a/.github/dependencies.sha256 b/.github/dependencies.sha256 new file mode 100644 index 0000000..335a46a --- /dev/null +++ b/.github/dependencies.sha256 @@ -0,0 +1,7 @@ +b7156eab567772f9fdac0bf696b209111790c3f69149ab9a742e3dd030ec4b10 libs/spigot-api.jar +64ea06ea92bf22785e6d541dd1b5f550edcdc4610d7a9748a91d715876ac079d libs/advancedcrafting-1.2.1.jar +db5beb70f316d0d5980981d79d9572a8538aa331e8bd7960a8115c483dc98afa libs/gunsandgadgets-1.0.6.jar +d328aa3bb5f4e8996d028a539a69a2b07f194b5f5e7fe3ad88598a221b521c52 libs/magic-0.1.0.jar +0116d714822b6f0cfebfe833a5df2e4754797b637d0fe709afb762c56da463a3 libs/ItemsAdder_3.5.0-r2.jar +c84700df5942fd969d3e8c2f1ad2c3ebeb17987ef88b426408d1306e49c4aada libs/MMOItems-6.10.jar +660ff2a6ec86bc8d7779948cf65c1637e271a16e1ef812d6a273f4a5c5eec73c libs/MythicLib-1.7.jar diff --git a/.github/scripts/prepare-release.sh b/.github/scripts/prepare-release.sh new file mode 100644 index 0000000..96a0ef6 --- /dev/null +++ b/.github/scripts/prepare-release.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail +: "${GH_TOKEN:?Set DEPS_TOKEN with Contents read access to TF-Minecraft/ServerAssets}" +ref=883970ddc256f0e4c3bcaee87e6cf33171b9d4a4 +mkdir -p libs +curl --fail --location --silent --show-error --retry 3 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github.raw+json" "https://api.github.com/repos/TF-Minecraft/ServerAssets/contents/jars/b7156eab5677/spigot-api.jar?ref=$ref" > "libs/spigot-api.jar" +curl --fail --location --silent --show-error --retry 3 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github.raw+json" "https://api.github.com/repos/TF-Minecraft/ServerAssets/contents/jars/64ea06ea92bf/advancedcrafting-1.2.1.jar?ref=$ref" > "libs/advancedcrafting-1.2.1.jar" +curl --fail --location --silent --show-error --retry 3 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github.raw+json" "https://api.github.com/repos/TF-Minecraft/ServerAssets/contents/jars/db5beb70f316/gunsandgadgets-1.0.6.jar?ref=$ref" > "libs/gunsandgadgets-1.0.6.jar" +curl --fail --location --silent --show-error --retry 3 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github.raw+json" "https://api.github.com/repos/TF-Minecraft/ServerAssets/contents/jars/d328aa3bb5f4/magic-0.1.0.jar?ref=$ref" > "libs/magic-0.1.0.jar" +curl --fail --location --silent --show-error --retry 3 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github.raw+json" "https://api.github.com/repos/TF-Minecraft/ServerAssets/contents/jars/0116d714822b/ItemsAdder_3.5.0-r2.jar?ref=$ref" > "libs/ItemsAdder_3.5.0-r2.jar" +curl --fail --location --silent --show-error --retry 3 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github.raw+json" "https://api.github.com/repos/TF-Minecraft/ServerAssets/contents/jars/c84700df5942/MMOItems-6.10.jar?ref=$ref" > "libs/MMOItems-6.10.jar" +curl --fail --location --silent --show-error --retry 3 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github.raw+json" "https://api.github.com/repos/TF-Minecraft/ServerAssets/contents/jars/660ff2a6ec86/MythicLib-1.7.jar?ref=$ref" > "libs/MythicLib-1.7.jar" +sha256sum --check .github/dependencies.sha256 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a2de30e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,60 @@ +name: Build + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-24.04 + timeout-minutes: 20 + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: '25' + - name: Install pinned TLibs in Maven + uses: TF-Minecraft/TLibs/.github/actions/setup@905a196217471252b96be5ecf8eeb16c9e85e41d + with: + token: ${{ secrets.DEPS_TOKEN }} + + - name: Prepare pinned dependencies + env: + GH_TOKEN: ${{ secrets.DEPS_TOKEN }} + run: bash .github/scripts/prepare-release.sh + - name: Set dated development version + id: dev + shell: bash + run: | + dev_version="DEV-$(date -u +%Y%m%d-%H%M)" + mvn -B --no-transfer-progress org.codehaus.mojo:versions-maven-plugin:2.22.0:set \ + -DnewVersion="$dev_version" -DgenerateBackupPoms=false + mvn -B --no-transfer-progress help:evaluate \ + -Dexpression=project.build.finalName -Doutput="$RUNNER_TEMP/final-name" + final_name=$(cat "$RUNNER_TEMP/final-name") + echo "name=$final_name" >> "$GITHUB_OUTPUT" + echo "jar=target/$final_name.jar" >> "$GITHUB_OUTPUT" + + - name: Run unit tests and build + run: mvn -B --no-transfer-progress clean verify -DskipTests=false -Dmaven.test.skip=false + - uses: actions/upload-artifact@v7 + with: + name: ${{ steps.dev.outputs.name }}-${{ github.run_id }}-${{ github.run_attempt }} + path: ${{ steps.dev.outputs.jar }} + if-no-files-found: error + + - name: Upload unit test reports + if: ${{ !cancelled() && hashFiles('target/surefire-reports/*.xml') != '' }} + uses: actions/upload-artifact@v7 + with: + name: unit-test-reports-${{ github.run_id }}-${{ github.run_attempt }} + path: target/surefire-reports/ + if-no-files-found: error diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml new file mode 100644 index 0000000..b72587b --- /dev/null +++ b/.github/workflows/maven-release.yml @@ -0,0 +1,140 @@ +name: Maven plugin release + +on: + workflow_call: + inputs: + java-version: + required: true + type: string + artifact-path: + description: Exact deployable JAR path, with optional {version} placeholder + required: true + type: string + secrets: + DEPS_TOKEN: + required: false + +permissions: + contents: read + +concurrency: + group: plugin-release-${{ github.repository }}-${{ github.ref }} + cancel-in-progress: false + +defaults: + run: + shell: bash + +jobs: + build: + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-24.04 + timeout-minutes: 20 + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: ${{ inputs.java-version }} + + - name: Validate release version + env: + TAG: ${{ github.ref_name }} + run: | + [[ "$TAG" =~ ^v[0-9]+\.[0-9]+(\.[0-9]+)?(-[0-9A-Za-z]+([.-][0-9A-Za-z]+)*)?$ ]] || { + echo '::error::Expected vMAJOR.MINOR or vMAJOR.MINOR.PATCH, with an optional prerelease suffix.' + exit 1 + } + [[ "${TAG^^}" != *SNAPSHOT* ]] || exit 1 + + - name: Install pinned TLibs in Maven + uses: TF-Minecraft/TLibs/.github/actions/setup@905a196217471252b96be5ecf8eeb16c9e85e41d + with: + token: ${{ secrets.DEPS_TOKEN }} + + - name: Prepare pinned dependencies + env: + GH_TOKEN: ${{ secrets.DEPS_TOKEN }} + run: | + if [[ -f .github/scripts/prepare-release.sh ]]; then + bash .github/scripts/prepare-release.sh + fi + + - name: Check Maven version and build + env: + TAG: ${{ github.ref_name }} + run: | + version_file="$RUNNER_TEMP/maven-release-version" + mvn -B --no-transfer-progress -P'!deploy-live' help:evaluate \ + -Dexpression=project.version -Doutput="$version_file" + [[ "$(cat "$version_file")" == "${TAG#v}" ]] || { + echo '::error::The tag must match project.version exactly.' + exit 1 + } + mvn -B --no-transfer-progress -P'!deploy-live' clean verify + + - name: Stage only the release JAR + env: + ARTIFACT_PATH: ${{ inputs.artifact-path }} + TAG: ${{ github.ref_name }} + run: | + python3 - <<'PY' + import hashlib, json, os, pathlib, shutil, zipfile + root = pathlib.Path.cwd().resolve() + source = (root / os.environ['ARTIFACT_PATH'].replace('{version}', os.environ['TAG'][1:])).resolve() + if not source.is_relative_to(root / 'target') or not source.is_file() or source.suffix != '.jar': + raise SystemExit('Expected one existing JAR inside target/') + with zipfile.ZipFile(source) as jar: + if not {'plugin.yml', 'paper-plugin.yml'}.intersection(jar.namelist()): + raise SystemExit('Release JAR has no plugin descriptor') + if jar.testzip() is not None: + raise SystemExit('Release JAR is corrupt') + dest = pathlib.Path(os.environ['RUNNER_TEMP']) / 'plugin-release' + dest.mkdir() + shutil.copyfile(source, dest / source.name) + digest = hashlib.sha256((dest / source.name).read_bytes()).hexdigest() + (dest / 'SHA256SUMS').write_text(f'{digest} {source.name}\n') + (dest / 'build.json').write_text(json.dumps({ + 'repository': os.environ['GITHUB_REPOSITORY'], + 'commit': os.environ['GITHUB_SHA'], + 'tag': os.environ['TAG'], + 'run': f"{os.environ['GITHUB_SERVER_URL']}/{os.environ['GITHUB_REPOSITORY']}/actions/runs/{os.environ['GITHUB_RUN_ID']}", + 'artifact': source.name, + 'sha256': digest, + }, indent=2) + '\n') + PY + + - uses: actions/upload-artifact@v7 + with: + name: plugin-release-${{ github.sha }} + path: ${{ runner.temp }}/plugin-release/ + if-no-files-found: error + retention-days: 30 + + publish: + needs: build + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: write + steps: + - uses: actions/download-artifact@v8 + with: + name: plugin-release-${{ github.sha }} + path: release + + - name: Create draft release + working-directory: release + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + TAG: ${{ github.ref_name }} + run: | + sha256sum --check SHA256SUMS + flags=() + if [[ "$TAG" == *-* ]]; then flags+=(--prerelease); fi + gh release create "$TAG" ./*.jar SHA256SUMS build.json \ + --verify-tag --draft --title "$TAG" --generate-notes "${flags[@]}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0c958b0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,20 @@ +name: Release + +on: + push: + tags: ['v*'] + +permissions: + contents: read + +jobs: + release: + permissions: + contents: write + uses: ./.github/workflows/maven-release.yml + with: + java-version: '25' + # Exact path, not a glob. {version} is replaced with the tag without v. + artifact-path: target/recycler-{version}.jar + secrets: + DEPS_TOKEN: ${{ secrets.DEPS_TOKEN }} diff --git a/.gitignore b/.gitignore index 7a9655e..96afe12 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ Thumbs.db # Logs *.log + +# Downloaded build dependencies +/libs/*.jar diff --git a/pom.xml b/pom.xml index a1082e0..92aa8e5 100644 --- a/pom.xml +++ b/pom.xml @@ -12,12 +12,6 @@ 1.1.0 25 UTF-8 - D:/Documents/TFMC/ReferenceLibs - D:/Documents/TFMC/Builds/Recycler - - D:/Documents/TFMC/Builds/GunsAndGadgets - D:/Documents/TFMC/Builds/AdvancedCrafting - D:/Documents/TFMC/Builds/Magic @@ -31,7 +25,7 @@ spigot-api 1.21.8 system - ${tfmc.refs}/spigot-api.jar + ${project.basedir}/libs/spigot-api.jar me.plugins @@ -48,70 +42,64 @@ AdvancedCrafting 1.2.1 system - ${tfmc.advancedcrafting}/advancedcrafting-1.2.1.jar + ${project.basedir}/libs/advancedcrafting-1.2.1.jar local GunsAndGadgets - 1.0.3 + 1.0.6 system - ${tfmc.gunsandgadgets}/gunsandgadgets-1.0.3.jar + ${project.basedir}/libs/gunsandgadgets-1.0.6.jar local Magic 0.1.0 system - ${tfmc.magic}/magic-0.1.0.jar + ${project.basedir}/libs/magic-0.1.0.jar local ItemsAdder 3.5.0 system - ${tfmc.refs}/ItemsAdder_3.5.0-r2.jar + ${project.basedir}/libs/ItemsAdder_3.5.0-r2.jar local MMOItems 6.10 system - ${tfmc.refs}/MMOItems-6.10.jar + ${project.basedir}/libs/MMOItems-6.10.jar local MythicLib 1.7 system - ${tfmc.refs}/MythicLib-1.7.jar + ${project.basedir}/libs/MythicLib-1.7.jar + + + src/main/resources + true + plugin.yml + + + src/main/resources + false + plugin.yml + + org.apache.maven.plugins maven-compiler-plugin 3.14.1 - - org.apache.maven.plugins - maven-antrun-plugin - 3.1.0 - - - package - run - - - - - - - - - diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 045f737..2658b93 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ main: net.tfminecraft.recycler.Recycler api-version: '1.19' name: Recycler -version: 0.1.0 +version: ${project.version} author: Drefvelin depend: [TLibs, ItemsAdder] softdepend: [AdvancedCrafting, GunsAndGadgets, Magic, MMOItems]