Extract Hytale Packets #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Extract Hytale Packets | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Server version (e.g., 1.0.0, beta-1, 2024.01.15)' | |
| required: true | |
| type: string | |
| jar_url: | |
| description: 'Direct download URL for the server JAR (optional - leave empty to use uploaded artifact)' | |
| required: false | |
| type: string | |
| artifact_run_id: | |
| description: 'Run ID of the workflow that uploaded the JAR artifact (optional)' | |
| required: false | |
| type: string | |
| generate_wiki: | |
| description: 'Generate wiki documentation' | |
| required: false | |
| type: boolean | |
| default: true | |
| env: | |
| VINEFLOWER_VERSION: '1.10.1' | |
| jobs: | |
| extract-and-decompile: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| actions: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Download JAR from URL | |
| if: inputs.jar_url != '' | |
| shell: pwsh | |
| run: | | |
| New-Item -ItemType Directory -Path "./server-jar" -Force | Out-Null | |
| $jarPath = "./server-jar/HytaleServer.jar" | |
| Write-Host "Downloading JAR from: ${{ inputs.jar_url }}" | |
| Invoke-WebRequest -Uri "${{ inputs.jar_url }}" -OutFile $jarPath -UseBasicParsing | |
| Write-Host "JAR downloaded successfully" | |
| - name: Download JAR from artifact | |
| if: inputs.jar_url == '' && inputs.artifact_run_id != '' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: hytale-server-jar | |
| path: ./server-jar | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ inputs.artifact_run_id }} | |
| - name: Verify JAR file | |
| id: check-jar | |
| shell: pwsh | |
| run: | | |
| $jarFiles = Get-ChildItem -Path "./server-jar" -Filter "*.jar" -ErrorAction SilentlyContinue | |
| if ($null -eq $jarFiles -or $jarFiles.Count -eq 0) { | |
| Write-Host "::error::No JAR file found. Please provide either:" | |
| Write-Host "::error:: - A direct download URL in 'jar_url'" | |
| Write-Host "::error:: - An artifact run ID in 'artifact_run_id'" | |
| exit 1 | |
| } | |
| $jarPath = $jarFiles[0].FullName | |
| Write-Host "Found JAR: $jarPath" | |
| "jar_path=$jarPath" >> $env:GITHUB_OUTPUT | |
| - name: Download Vineflower | |
| shell: pwsh | |
| run: | | |
| $url = "https://github.com/Vineflower/vineflower/releases/download/${{ env.VINEFLOWER_VERSION }}/vineflower-${{ env.VINEFLOWER_VERSION }}.jar" | |
| Write-Host "Downloading Vineflower from: $url" | |
| Invoke-WebRequest -Uri $url -OutFile "vineflower.jar" -UseBasicParsing | |
| Write-Host "Vineflower downloaded successfully" | |
| - name: Extract and decompile protocol | |
| shell: pwsh | |
| run: | | |
| & ./scripts/Extract-Packets.ps1 ` | |
| -JarPath "${{ steps.check-jar.outputs.jar_path }}" ` | |
| -OutputPath "./protocol" ` | |
| -VineflowerPath "./vineflower.jar" | |
| - name: Check for changes | |
| id: changes | |
| shell: pwsh | |
| run: | | |
| git add -A | |
| $status = git status --porcelain | |
| if ($status) { | |
| Write-Host "Changes detected:" | |
| Write-Host $status | |
| "has_changes=true" >> $env:GITHUB_OUTPUT | |
| } else { | |
| Write-Host "No changes detected" | |
| "has_changes=false" >> $env:GITHUB_OUTPUT | |
| } | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install wiki generator dependencies | |
| if: inputs.generate_wiki | |
| working-directory: ./scripts/generate-wiki-ts | |
| run: bun install | |
| - name: Clone existing wiki for merging | |
| if: inputs.generate_wiki | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| repo="${{ github.repository }}" | |
| # Create wiki directory | |
| mkdir -p ./wiki | |
| # Try to clone existing wiki to get current content | |
| if git clone "https://x-access-token:${GH_TOKEN}@github.com/${repo}.wiki.git" ./existing-wiki 2>/dev/null; then | |
| echo "Cloned existing wiki" | |
| # Copy existing files to wiki directory (so generator can find existing versions) | |
| cp -r ./existing-wiki/*.md ./wiki/ 2>/dev/null || echo "No existing MD files to copy" | |
| echo "Existing wiki files:" | |
| ls -la ./wiki/*.md 2>/dev/null || echo "No files yet" | |
| else | |
| echo "Wiki doesn't exist yet, starting fresh" | |
| fi | |
| - name: Generate wiki documentation | |
| if: inputs.generate_wiki | |
| shell: bash | |
| env: | |
| OPENROUTER_KEY: ${{ secrets.OPENROUTER_KEY }} | |
| run: | | |
| version="${{ inputs.version }}" | |
| echo "Generating wiki documentation for version: $version" | |
| # Run the TypeScript wiki generator with Bun | |
| # Key is passed via OPENROUTER_KEY env var (read by the script) | |
| cd ./scripts/generate-wiki-ts | |
| if [ -n "$OPENROUTER_KEY" ]; then | |
| echo "OpenRouter API key detected - enabling AI layout analysis" | |
| else | |
| echo "No OpenRouter API key - skipping AI layout analysis" | |
| fi | |
| bun run src/generate-wiki.ts \ | |
| --protocol-dir "../../protocol" \ | |
| --output-dir "../../wiki" \ | |
| --version "$version" \ | |
| --json | |
| echo "Wiki generation complete" | |
| - name: Create version branch and commit | |
| if: steps.changes.outputs.has_changes == 'true' | |
| shell: pwsh | |
| run: | | |
| $version = "${{ inputs.version }}" | |
| $branchName = "version/$version" | |
| # Configure git | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Remove existing-wiki directory (cloned for merging, not needed in version branch) | |
| if (Test-Path "./existing-wiki") { | |
| Write-Host "Removing existing-wiki directory..." | |
| Remove-Item -Recurse -Force "./existing-wiki" | |
| } | |
| # Check if branch exists on remote | |
| $branchExists = git ls-remote --heads origin $branchName 2>$null | |
| if ($branchExists) { | |
| Write-Host "Branch $branchName already exists, checking out and updating..." | |
| git fetch origin $branchName | |
| git checkout -B $branchName origin/$branchName | |
| git add -A | |
| git commit -m "Update packets for version $version" --allow-empty | |
| } else { | |
| Write-Host "Creating new branch: $branchName" | |
| git checkout -b $branchName | |
| git add -A | |
| git commit -m "Extract packets for version $version" | |
| } | |
| # Push branch | |
| git push -u origin $branchName --force-with-lease | |
| Write-Host "::notice::Successfully pushed to branch: $branchName" | |
| - name: Publish wiki to GitHub Wiki | |
| if: inputs.generate_wiki | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| version="${{ inputs.version }}" | |
| repo="${{ github.repository }}" | |
| echo "Publishing wiki for version: $version" | |
| # Configure git | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # Clone existing wiki or create new one | |
| mkdir -p wiki-repo | |
| cd wiki-repo | |
| if git clone "https://x-access-token:${GH_TOKEN}@github.com/${repo}.wiki.git" . 2>/dev/null; then | |
| echo "Cloned existing wiki" | |
| else | |
| echo "Wiki doesn't exist yet, initializing..." | |
| git init | |
| git remote add origin "https://x-access-token:${GH_TOKEN}@github.com/${repo}.wiki.git" | |
| fi | |
| # Track which files are being added/updated | |
| echo "Files to be updated:" | |
| ls -1 ../wiki/*.md | |
| # Copy only the newly generated wiki files (incremental update) | |
| # This preserves existing wiki pages for other versions | |
| for file in ../wiki/*.md; do | |
| if [ -f "$file" ]; then | |
| basename=$(basename "$file") | |
| if [ -f "$basename" ]; then | |
| echo "Updating existing page: $basename" | |
| else | |
| echo "Adding new page: $basename" | |
| fi | |
| cp -f "$file" ./ | |
| fi | |
| done | |
| echo "Current wiki contents:" | |
| ls -la *.md | |
| # Commit and push | |
| git add -A | |
| if git diff --staged --quiet; then | |
| echo "No wiki changes to commit" | |
| else | |
| # Create a detailed commit message | |
| added_files=$(git diff --cached --name-only --diff-filter=A | wc -l) | |
| modified_files=$(git diff --cached --name-only --diff-filter=M | wc -l) | |
| commit_msg="Update wiki for version ${version}" | |
| if [ "$added_files" -gt 0 ]; then | |
| commit_msg="${commit_msg} (+${added_files} new)" | |
| fi | |
| if [ "$modified_files" -gt 0 ]; then | |
| commit_msg="${commit_msg} (~${modified_files} updated)" | |
| fi | |
| git commit -m "$commit_msg" | |
| git push origin HEAD:master | |
| echo "Wiki published successfully!" | |
| fi | |
| - name: Create summary | |
| shell: pwsh | |
| run: | | |
| $protocolDirs = Get-ChildItem -Path "./protocol" -Directory -ErrorAction SilentlyContinue | |
| $totalFiles = (Get-ChildItem -Path "./protocol" -Filter "*.java" -Recurse -ErrorAction SilentlyContinue).Count | |
| $packetFiles = (Get-ChildItem -Path "./protocol/packets" -Filter "*.java" -Recurse -ErrorAction SilentlyContinue).Count | |
| $wikiFiles = (Get-ChildItem -Path "./wiki" -Filter "*.md" -ErrorAction SilentlyContinue).Count | |
| $summary = @" | |
| ## Protocol Extraction Summary | |
| **Version:** ``${{ inputs.version }}`` | |
| **Branch:** ``version/${{ inputs.version }}`` | |
| **Total Protocol Files:** $totalFiles | |
| **Packet Files:** $packetFiles | |
| **Wiki Pages Generated:** $wikiFiles | |
| ### Protocol Package Breakdown | |
| | Package | Files | | |
| |---------|-------| | |
| "@ | |
| foreach ($dir in $protocolDirs) { | |
| $count = (Get-ChildItem -Path $dir.FullName -Filter "*.java" -Recurse).Count | |
| $summary += "`n| ``$($dir.Name)`` | $count |" | |
| } | |
| if ($wikiFiles -gt 0) { | |
| $summary += "`n`n### Wiki Documentation`n`nWiki documentation has been published to the [repository wiki](https://github.com/${{ github.repository }}/wiki)." | |
| $summary += "`n- [Home](https://github.com/${{ github.repository }}/wiki)" | |
| $summary += "`n- [All Versions](https://github.com/${{ github.repository }}/wiki/Versions)" | |
| } | |
| $summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 |