Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
111 changes: 111 additions & 0 deletions .github/NativeDependencyPins.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

function Read-NativeProperties([string]$Path) {
$properties = @{}
foreach ($line in Get-Content -LiteralPath $Path) {
if ($line -match '^\s*([^#!\s=]+)\s*=(.*)$') {
$properties[$Matches[1]] = $Matches[2].Trim()
}
}
return $properties
}

function Read-NativeDependencyPins([string]$LockPath, [hashtable]$Properties) {
$lock = Get-Content -LiteralPath $LockPath -Raw | ConvertFrom-Json -AsHashtable
if ($lock.schemaVersion -ne 1) { throw 'Unsupported native dependency lock schema' }
if ($lock.status -ne 'HOSTED_INPUTS_READY') {
throw "BOOTSTRAP_BLOCKED: $($lock.reason)"
}
$target = $lock.target
if ($target.minecraft -ne '1.21.1' -or $target.neoforge -ne '21.1.265' -or
$target.java -ne '21' -or $target.moddev -ne '2.0.148' -or $target.gradle -ne '9.8.0' -or
$target.releaseBranch -ne 'master-1.21.1-neo') { throw 'Wrong native build target' }
if ($Properties.minecraft_version -ne $target.minecraft -or $Properties.neo_version -ne $target.neoforge -or
$Properties.java_version -ne $target.java -or $Properties.loader_name -ne 'neoforge' -or
$Properties.loader_code -ne '2') { throw 'Dependency lock differs from the project target' }
$ids = @($lock.dependencies | ForEach-Object { $_.id } | Sort-Object)
if (($ids -join ',') -ne 'basemetals,mmdlib,orespawn') { throw 'Exactly three unique native dependencies are required' }
$coordinates = @{
basemetals = @('zone.moddev.mc.basemetals', 'BaseMetals', 'basemetals_version', 'basemetals_deobf_sha256')
mmdlib = @('zone.moddev.mc.lib', 'mmdlib', 'mmdlib_version', 'mmdlib_sha256')
orespawn = @('zone.moddev.mc.orespawn', 'OreSpawn', 'orespawn_version', 'orespawn_deobf_sha256')
}
foreach ($pin in $lock.dependencies) {
$expected = $coordinates[$pin.id]
if ($pin.state -ne 'PUBLISHED') { throw "Dependency $($pin.id) is not a published input" }
if ($pin.group -cne $expected[0] -or $pin.artifact -cne $expected[1] -or
$pin.versionProperty -cne $expected[2] -or $pin.hashProperty -cne $expected[3]) {
throw "Unexpected coordinate or project property for $($pin.id)"
}
if ($pin.version -cne $Properties[$pin.versionProperty] -or
$pin.sha256 -cne $Properties[$pin.hashProperty]) { throw "Project pin differs for $($pin.id)" }
if ($pin.sha256 -cnotmatch '^[A-F0-9]{64}$' -or
$pin.mavenVersion -notmatch '^\d+\.\d+\.\d+\.121012(?:\+Neo)?$' -or
$pin.mavenVersion -cnotin @($pin.version, ($pin.version + '+Neo')) -or
$pin.modVersion -cne $pin.mavenVersion -or
[string]::IsNullOrWhiteSpace($pin.modVersion) -or
$pin.modVersion -match '(?i)development|snapshot|unqualified') {
throw "Missing exact public native artifact identity for $($pin.id)"
}
if ($pin.ContainsKey('source')) {
$source = $pin.source
if ($source.repository -cne "MinecraftModDevelopmentMods/$($pin.artifact)" -or
$source.commit -cnotmatch '^[a-f0-9]{40}$' -or
$source.branch -notmatch '^master-1\.21\.1(?:-neo|-neoforge)?$') {
throw "Missing approved source ancestry pin for $($pin.id)"
}
$property = "$($pin.id)_source_commit"
if (!$Properties.ContainsKey($property) -or $Properties[$property] -cne $source.commit) {
throw "Project source pin differs for $($pin.id)"
}
} elseif ($pin.id -eq 'basemetals') { throw 'Base Metals hook requires an exact merged source pin' }
if ($pin.id -eq 'basemetals' -and $pin.requiredEntry -cne 'zone/moddev/mc/basemetals/migration/LegacyWorldDataHook.class') {
throw 'Base Metals migration-hook gate was removed'
}
}
return $lock
}

function Assert-NativeSourceAncestry($Pin, [scriptblock]$Compare = {
param($Uri)
$status = & gh api $Uri --jq '.status'
if ($LASTEXITCODE -ne 0) { throw 'GitHub source comparison failed' }
return $status
}) {
if (!$Pin.ContainsKey('source')) { return }
$source = $Pin.source
$uri = "repos/$($source.repository)/compare/$($source.commit)...$($source.branch)"
$status = & $Compare $uri
if ($status -notin @('identical', 'ahead')) {
throw "Source $($source.commit) is not merged on $($source.branch): $status"
}
}

function Assert-NativeDependencyArchive([string]$Path, $Pin) {
if ((Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash -cne $Pin.sha256) {
throw "SHA-256 mismatch for $($Pin.id)"
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
$archive = [IO.Compression.ZipFile]::OpenRead($Path)
try {
$entry = $archive.GetEntry('META-INF/neoforge.mods.toml')
if (!$entry -or $archive.GetEntry('META-INF/mods.toml')) { throw "Not a native NeoForge jar: $($Pin.id)" }
$reader = [IO.StreamReader]::new($entry.Open())
try { $metadata = $reader.ReadToEnd() } finally { $reader.Dispose() }
$header = [regex]::Match($metadata, '(?ms)^[ \t]*\[\[mods\]\][ \t]*(?:#[^\r\n]*)?\r?\n(.*?)(?=^[ \t]*\[|\z)').Groups[1].Value
$id = [regex]::Escape($Pin.id)
$version = [regex]::Escape($Pin.modVersion)
if ($metadata -match '\$\{[^}]+\}' -or
$header -notmatch "(?m)^[ \t]*modId[ \t]*=[ \t]*`"$id`"[ \t]*(?:#[^\r\n]*)?\r?$" -or
$header -notmatch "(?m)^[ \t]*version[ \t]*=[ \t]*`"$version`"[ \t]*(?:#[^\r\n]*)?\r?$" -or
$metadata -notmatch '(?m)^[ \t]*modId[ \t]*=[ \t]*"neoforge"[ \t]*(?:#[^\r\n]*)?\r?$') {
throw "Jar metadata differs for $($Pin.id)"
}
if ($Pin.ContainsKey('requiredEntry') -and !$archive.GetEntry($Pin.requiredEntry)) {
throw 'Base Metals jar does not contain the approved migration hook'
}
} finally { $archive.Dispose() }
}

Export-ModuleMember -Function Read-NativeProperties, Read-NativeDependencyPins, Assert-NativeSourceAncestry, Assert-NativeDependencyArchive
63 changes: 63 additions & 0 deletions .github/native-dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"schemaVersion": 1,
"status": "HOSTED_INPUTS_READY",
"reason": "All three dependencies are public. Base Metals PR #545 is merged and its release jar matches CurseForge, Maven and GitHub downloads.",
"target": {
"minecraft": "1.21.1",
"neoforge": "21.1.265",
"java": "21",
"moddev": "2.0.148",
"gradle": "9.8.0",
"releaseBranch": "master-1.21.1-neo"
},
"dependencies": [
{
"id": "basemetals",
"group": "zone.moddev.mc.basemetals",
"artifact": "BaseMetals",
"versionProperty": "basemetals_version",
"hashProperty": "basemetals_deobf_sha256",
"version": "4.0.1.121012+Neo",
"mavenVersion": "4.0.1.121012+Neo",
"modVersion": "4.0.1.121012+Neo",
"sha256": "B4BB1CBCD54DFCF2EC8465ACE82715EDCCC5BF1E5C15E14C627AE7CC58E8FED1",
"state": "PUBLISHED",
"source": {
"repository": "MinecraftModDevelopmentMods/BaseMetals",
"branch": "master-1.21.1-neo",
"commit": "39b240bb0d9f80997847ab4df70a2dd23e6ea826",
"baselineCommit": "4d63af931292e5020a5e0a3ddbd73a87ab1f410f"
},
"requiredEntry": "zone/moddev/mc/basemetals/migration/LegacyWorldDataHook.class"
},
{
"id": "mmdlib",
"group": "zone.moddev.mc.lib",
"artifact": "mmdlib",
"versionProperty": "mmdlib_version",
"hashProperty": "mmdlib_sha256",
"version": "2.0.2.121012+Neo",
"mavenVersion": "2.0.2.121012+Neo",
"modVersion": "2.0.2.121012+Neo",
"sha256": "EE417C82D588B0050A49709B6430CF836315E71E4DB2DF4036D3735454BC5311",
"state": "PUBLISHED"
},
{
"id": "orespawn",
"group": "zone.moddev.mc.orespawn",
"artifact": "OreSpawn",
"versionProperty": "orespawn_version",
"hashProperty": "orespawn_deobf_sha256",
"version": "4.1.1.121012",
"mavenVersion": "4.1.1.121012",
"modVersion": "4.1.1.121012",
"sha256": "BF02244E25B5FBF89CCAD45F41B2624B850D4BBCB70CF66822249BA233A00976",
"state": "PUBLISHED",
"source": {
"repository": "MinecraftModDevelopmentMods/OreSpawn",
"branch": "master-1.21.1-neo",
"commit": "f141ae56ea69e4c9f7f8ebd7697b933a91ee5001"
}
}
]
}
36 changes: 36 additions & 0 deletions .github/pinned-native-inputs.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import groovy.json.JsonSlurper
import java.security.MessageDigest

allprojects {
afterEvaluate { project ->
def lock = new JsonSlurper().parse(project.file('.github/native-dependencies.json'))
if (lock.status != 'HOSTED_INPUTS_READY') {
throw new GradleException('Hosted dependency bootstrap is blocked; local hook hashes are not release pins')
}
def arguments = [basemetals: 'baseMetalsJar', mmdlib: 'mmdlibJar', orespawn: 'oreSpawnJar']
def resolved = [:]
lock.dependencies.each { pin ->
def path = project.providers.gradleProperty(arguments[pin.id]).orNull
if (!path) throw new GradleException('Missing pinned dependency path: ' + pin.id)
File jar = project.file(path)
String actual = jar.isFile() ? MessageDigest.getInstance('SHA-256').digest(jar.bytes)
.encodeHex().toString().toUpperCase(Locale.ROOT) : ''
if (pin.state != 'PUBLISHED' || actual != pin.sha256
|| project.property(pin.versionProperty) != pin.version
|| project.property(pin.hashProperty) != pin.sha256) {
throw new GradleException('Changed or unapproved hosted input: ' + pin.id)
}
resolved[pin.id] = jar
}
// Use exactly the verified files rather than independently resolving Maven bytes again.
project.configurations.configureEach {
withDependencies { dependencies ->
dependencies.removeAll { dependency -> lock.dependencies.any { pin ->
dependency.group == pin.group && dependency.name == pin.artifact
} }
}
}
project.dependencies.add('pinnedBaseMetals', project.files(resolved.basemetals))
project.dependencies.add('implementation', project.files(resolved.mmdlib, resolved.orespawn))
}
}
51 changes: 1 addition & 50 deletions .github/test-base-metals-pin.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,3 @@
#!/usr/bin/env bash
set -euo pipefail

verify="$(cd "$(dirname "$0")" && pwd)/verify-base-metals-pin.sh"
temporary_root="$(cd "${TMPDIR:-/tmp}" && pwd -P)"
scratch="$(mktemp -d "$temporary_root/basepower-pin.XXXXXXXX")"
cleanup() {
local resolved
resolved="$(cd "$scratch" && pwd -P)"
case "$resolved" in
"$temporary_root"/basepower-pin.*) rm -rf -- "$resolved" ;;
*) echo 'Refusing to clear an unexpected test directory' >&2; return 1 ;;
esac
}
trap cleanup EXIT
mkdir -p "$scratch/bin" "$scratch/project"
cat > "$scratch/bin/gh" <<'MOCK'
#!/usr/bin/env bash
set -euo pipefail
[[ "$#" == 4 && "$1" == api && "$2" == "$EXPECTED_COMPARE" && "$3" == --jq && "$4" == .status ]]
printf '%s\n' "$PIN_STATUS"
MOCK
chmod +x "$scratch/bin/gh"
export PATH="$scratch/bin:$PATH"
commit=1111111111111111111111111111111111111111
cd "$scratch/project"
for minecraft in 1.20.6 1.21.1 1.21.11; do
printf 'minecraft_version=%s\nbasemetals_source_commit=%s\n' "$minecraft" "$commit" > gradle.properties
export EXPECTED_COMPARE="repos/MinecraftModDevelopmentMods/BaseMetals/compare/$commit...master-$minecraft"
export GITHUB_OUTPUT="$scratch/output"
for PIN_STATUS in identical ahead; do
export PIN_STATUS
: > "$GITHUB_OUTPUT"
bash "$verify"
grep -qx "commit=$commit" "$GITHUB_OUTPUT"
done
for PIN_STATUS in behind diverged; do
export PIN_STATUS
: > "$GITHUB_OUTPUT"
if bash "$verify" > "$scratch/rejected.log" 2>&1; then
echo "Incorrectly accepted $minecraft / $PIN_STATUS" >&2
exit 1
fi
test ! -s "$GITHUB_OUTPUT"
done
done
printf 'minecraft_version=invalid\nbasemetals_source_commit=%s\n' "$commit" > gradle.properties
if bash "$verify" > "$scratch/invalid.log" 2>&1; then
echo 'Incorrectly accepted an invalid target' >&2
exit 1
fi
echo 'PASS: target-derived Base Metals ancestry guards and rejection controls'
exec pwsh -NoProfile -File "$(dirname "$0")/test-native-dependencies.ps1" "$@"
Loading
Loading