97 lines
4.0 KiB
YAML
97 lines
4.0 KiB
YAML
on:
|
|
pull_request:
|
|
push:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: windows-latest
|
|
defaults:
|
|
run:
|
|
shell: powershell
|
|
|
|
env:
|
|
PROJECT_NAME: Construct
|
|
BP_SOURCE: "packs/BP"
|
|
RP_SOURCE: "packs/RP"
|
|
|
|
steps:
|
|
- uses: https://github.bibk.top/actions/checkout@v4
|
|
- name: Regenerate Manifest UUIDs (Node.js)
|
|
shell: powershell # 兼容 PowerShell 5.1
|
|
env:
|
|
RP_SOURCE: ${{ env.RP_SOURCE }}
|
|
BP_SOURCE: ${{ env.BP_SOURCE }}
|
|
run: |
|
|
$jsCode = @"
|
|
const fs = require('fs');
|
|
const crypto = require('crypto');
|
|
const path = require('path');
|
|
const genUUID = () => crypto.randomUUID();
|
|
const rpHeader = genUUID();
|
|
const bpHeader = genUUID();
|
|
console.log('Generated RP Header UUID: ' + rpHeader);
|
|
console.log('Generated BP Header UUID: ' + bpHeader);
|
|
function processManifest(filePath, isRP) {
|
|
if (!fs.existsSync(filePath)) {
|
|
console.log('Warning: File not found: ' + filePath);
|
|
return;
|
|
}
|
|
let manifest = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
manifest.header.uuid = isRP ? rpHeader : bpHeader;
|
|
if (manifest.modules) {
|
|
manifest.modules.forEach(mod => {
|
|
if (mod.uuid) mod.uuid = genUUID();
|
|
});
|
|
}
|
|
if (manifest.dependencies) {
|
|
manifest.dependencies.forEach(dep => {
|
|
if (dep.uuid) {
|
|
dep.uuid = isRP ? bpHeader : rpHeader;
|
|
}
|
|
});
|
|
}
|
|
fs.writeFileSync(filePath, JSON.stringify(manifest, null, 4), 'utf8');
|
|
console.log('✅ Successfully updated: ' + filePath);
|
|
}
|
|
const rpDir = process.env.RP_SOURCE || 'packs/RP';
|
|
const bpDir = process.env.BP_SOURCE || 'packs/BP';
|
|
processManifest(path.join(rpDir, 'manifest.json'), true);
|
|
processManifest(path.join(bpDir, 'manifest.json'), false);
|
|
"@
|
|
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
|
[System.IO.File]::WriteAllText("$PWD\update_uuids.js", $jsCode, $utf8NoBom)
|
|
node update_uuids.js
|
|
Remove-Item update_uuids.js -Force
|
|
|
|
- name: Package mcaddon
|
|
shell: powershell # 确保使用 PowerShell
|
|
env:
|
|
PROJECT_NAME: Construct
|
|
BP_SOURCE: "packs/BP"
|
|
RP_SOURCE: "packs/RP"
|
|
run: |
|
|
$VERSION = $env:GITHUB_REF.Split('/')[-1]
|
|
$OUTPUT = "$($env:PROJECT_NAME)-$VERSION.mcaddon"
|
|
$BP_DIR = "$($env:PROJECT_NAME)[BP]"
|
|
$RP_DIR = "$($env:PROJECT_NAME)[RP]"
|
|
$BUILD_PATH = Join-Path -Path $PWD -ChildPath "build"
|
|
New-Item -ItemType Directory -Path $BUILD_PATH -Force | Out-Null
|
|
Copy-Item -Path $env:BP_SOURCE -Destination (Join-Path -Path $BUILD_PATH -ChildPath $BP_DIR) -Recurse
|
|
Copy-Item -Path $env:RP_SOURCE -Destination (Join-Path -Path $BUILD_PATH -ChildPath $RP_DIR) -Recurse
|
|
Copy-Item -Path "LICENSE" -Destination (Join-Path -Path $BUILD_PATH -ChildPath $BP_DIR)
|
|
Copy-Item -Path "LICENSE" -Destination (Join-Path -Path $BUILD_PATH -ChildPath $RP_DIR)
|
|
$BIN_DIR = Join-Path -Path $PWD -ChildPath "bin"
|
|
New-Item -ItemType Directory -Path $BIN_DIR -Force | Out-Null
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
$ZIP_PATH = Join-Path -Path $BIN_DIR -ChildPath $OUTPUT
|
|
if (Test-Path $ZIP_PATH) { Remove-Item $ZIP_PATH }
|
|
[System.IO.Compression.ZipFile]::CreateFromDirectory($BUILD_PATH, $ZIP_PATH)
|
|
Write-Host "✅ Successfully packaged to: $ZIP_PATH"
|
|
|
|
- name: Upload Artifact
|
|
uses: https://github.bibk.top/actions/upload-artifact@v3
|
|
with:
|
|
files: |
|
|
${{ env.PROJECT_NAME }}-${{ github.event.release.tag_name }}.mcaddon
|
|
path: bin/*.mcaddon |