-
Notifications
You must be signed in to change notification settings - Fork 1
312 lines (265 loc) · 11 KB
/
extract-packets.yml
File metadata and controls
312 lines (265 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
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