-
Notifications
You must be signed in to change notification settings - Fork 523
449 lines (354 loc) · 15.7 KB
/
cp_dispatch.yml
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
name: Custom Version - Workflow Dispatch
on:
workflow_dispatch:
inputs:
version_to_patch:
description: 'The Version You Want to Patch'
required: true
default: '5.20.0'
env:
VERSION_TO_PATCH: ${{ github.event.inputs.version_to_patch }}
jobs:
validate-version:
runs-on: windows-latest
outputs:
is_valid: ${{ steps.get_validity.outputs.is_valid }}
env:
NODE_JS_VERSION: 23.1.0
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_JS_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_JS_VERSION }}
- name: Cache Node.js dependencies
uses: actions/cache@v4
with:
path: utils/fe-version-validator/node_modules
key: ${{ runner.os }}-node-${{ env.NODE_JS_VERSION }}-${{ hashFiles('utils/fe-version-validator/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ env.NODE_JS_VERSION }}-
- name: Install Node.js dependencies
run: npm ci
working-directory: utils/fe-version-validator
- name: Run the Node.js script
run: node .
working-directory: utils/fe-version-validator
- name: Get Version Validity
id: get_validity
shell: pwsh
run: |
$filePath = "utils/fe-version-validator/versions.txt"
$isValid = 'false'
$patchingVersion = $env:VERSION_TO_PATCH
if (-not [string]::IsNullOrEmpty($patchingVersion)) {
if (Select-String -Path $filePath -Pattern $patchingVersion) {
$compareVersion = "5.9.0"
if ([version]$patchingVersion -ge [version]$compareVersion) {
$isValid = 'true'
Write-Output "Valid Version found."
} else {
Write-Output "Version not Compatible."
}
} else {
Write-Output "Version Empty."
}
} else {
Write-Output "Version not found in List!"
}
echo "is_valid=$isValid" | Out-File -Append -FilePath $env:GITHUB_OUTPUT
download-Yui-patch:
runs-on: windows-latest
needs: validate-version
if: ${{ needs.validate-version.outputs.is_valid }} == 'true'
outputs:
is-compatible-cont: ${{ steps.is-compatible-cont.outputs.is-compatible-cont }}
Yui-fiddler-name: ${{ steps.Yui-fiddler-name.outputs.Yui-fiddler-name }}
steps:
- name: Compare Patching Version Compatible with 5.17.0
id: version_check
run: |
$patchingVersion = $env:VERSION_TO_PATCH
$compareVersion = "5.17.0"
if (-not [string]::IsNullOrEmpty($patchingVersion)) {
if ([version]$patchingVersion -ge [version]$compareVersion) {
echo "IS_COMPATIBLE_CONT=true" | Out-File -Append -FilePath $env:GITHUB_ENV
} else {
echo "IS_COMPATIBLE_CONT=false" | Out-File -Append -FilePath $env:GITHUB_ENV
}
} else {
echo "IS_COMPATIBLE_CONT=false" | Out-File -Append -FilePath $env:GITHUB_ENV
}
shell: pwsh
- name: Set IS_COMPATIBLE_CONT as Output
id: is-compatible-cont
run: echo "is-compatible-cont=${{ env.IS_COMPATIBLE_CONT }}" | Out-File -Append -FilePath $env:GITHUB_OUTPUT
- name: Set Yui name (>= 5.17.0)
if: env.IS_COMPATIBLE_CONT == 'true'
run: echo "YUI_NAME=yui" | Out-File -Append -FilePath $env:GITHUB_ENV
- name: Set Yui name (< 5.17.0)
if: env.IS_COMPATIBLE_CONT == 'false'
run: echo "YUI_NAME=yukihana" | Out-File -Append -FilePath $env:GITHUB_ENV
- name: Set Yui fiddler name (>= 5.17.0)
if: env.IS_COMPATIBLE_CONT == 'true'
run: echo "Yui_FIDDLER_NAME=fiddler" | Out-File -Append -FilePath $env:GITHUB_ENV
- name: Set Yui fiddler name (< 5.17.0)
if: env.IS_COMPATIBLE_CONT == 'false'
run: echo "Yui_FIDDLER_NAME=libfiddler" | Out-File -Append -FilePath $env:GITHUB_ENV
- name: Set Yui_FIDDLER_NAME as Output
id: Yui-fiddler-name
run: echo "Yui-fiddler-name=${{ env.Yui_FIDDLER_NAME }}" | Out-File -Append -FilePath $env:GITHUB_OUTPUT
- name: Create Yui directory
run: |
if (-Not (Test-Path "Yui")) {
New-Item -ItemType Directory -Path "Yui"
}
shell: pwsh
- name: Set Yui Release (>= 5.17.0)
if: env.IS_COMPATIBLE_CONT == 'true'
run: echo "Yui_RELEASE=continuous" | Out-File -Append -FilePath $env:GITHUB_ENV
- name: Set Yui Release (< 5.17.0)
if: env.IS_COMPATIBLE_CONT == 'false'
run: echo "Yui_RELEASE=v1.0.9" | Out-File -Append -FilePath $env:GITHUB_ENV
- name: Download Yui Patch
run: |
try {
# Build the download URLs
$YuiFiddlerUrl = "https://github.com/project-yui/Yui-patch/releases/download/$env:Yui_RELEASE/$env:YUI_NAME-$env:Yui_FIDDLER_NAME-win32-x86_64-$env:Yui_RELEASE.dll"
$YuiHostPolicyUrl = "https://github.com/project-yui/Yui-patch/releases/download/$env:Yui_RELEASE/$env:YUI_NAME-hostpolicy-win32-x86_64-$env:Yui_RELEASE.dll"
# Print the URLs to ensure they're correct
Write-Host "Downloading files from $env:Yui_RELEASE"
Write-Host "Yui Fiddler URL: $YuiFiddlerUrl"
Write-Host "Yui HostPolicy URL: $YuiHostPolicyUrl"
# Download the files
Invoke-WebRequest -Uri $YuiFiddlerUrl -OutFile "Yui\$env:Yui_FIDDLER_NAME.dll"
Invoke-WebRequest -Uri $YuiHostPolicyUrl -OutFile "Yui\hostpolicy.dll"
}
catch {
Write-Error "Failed to download the patch files. Error details: $_"
exit 1
}
shell: pwsh
- name: Upload Yui folder as an artifact
uses: actions/upload-artifact@v4
with:
name: Yui-patch
path: Yui/
if-no-files-found: error
download-msojocs-server:
runs-on: windows-latest
needs: validate-version
if: ${{ needs.validate-version.outputs.is_valid }} == 'true'
steps:
- name: Set up Git
run: |
git init
git remote add origin https://github.com/msojocs/fiddler-everywhere-enhance.git
git config core.sparseCheckout true
- name: Configure sparse-checkout to download the server directory
run: |
echo "server" | Out-File -Append -FilePath .git\info\sparse-checkout
git pull origin main
- name: Move the downloaded directory to the target folder
run: |
mkdir -p msojocs
Move-Item -Path server -Destination msojocs/
- name: List files in the msojocs/server directory
run: Get-ChildItem -Path msojocs\server
- name: Upload msojocs folder as an artifact
uses: actions/upload-artifact@v4
with:
name: msojocs-patch
path: msojocs/
if-no-files-found: error
download-fiddler-everywhere:
runs-on: windows-latest
needs: validate-version
if: ${{ needs.validate-version.outputs.is_valid }} == 'true'
steps:
- name: Build URL & Download
run: |
# Retrieve the patchingVersion version from the previous step
$patchingVersion = $env:VERSION_TO_PATCH
# Check if the patchingVersion version is available
if (-not [string]::IsNullOrEmpty($patchingVersion)) {
$downloadUrl = "https://downloads.getfiddler.com/win/Fiddler%20Everywhere%20$patchingVersion.exe"
Write-Host "Download URL: $downloadUrl"
Invoke-WebRequest -Uri $downloadUrl -OutFile "FiddlerEverywhereSetup.exe"
} else {
Write-Host "VERSION_TO_PATCH is empty or not set"
exit 1
}
shell: pwsh
- name: Extract exe
run: 7z x "FiddlerEverywhereSetup.exe" -ofe_extracted
- name: Extract app64
run: 7z x "fe_extracted/`$PLUGINSDIR/app-64.7z" -ofe_app64
shell: pwsh
- name: Upload Fiddler Everywhere Extracted folder as an artifact
uses: actions/upload-artifact@v4
with:
name: fe_app64
path: fe_app64/
if-no-files-found: error
patch_fe:
runs-on: windows-latest
needs:
- download-Yui-patch
- download-msojocs-server
- download-fiddler-everywhere
outputs:
patched-fe-name: ${{ steps.rename-fe.outputs.patched-fe-name }}
steps:
- name: Download Yukuhana-Patch
uses: actions/download-artifact@v4
with:
name: Yui-patch
path: Yui-patch
- name: Download msojocs-Server
uses: actions/download-artifact@v4
with:
name: msojocs-patch
path: msojocs-patch
- name: Download FE
uses: actions/download-artifact@v4
with:
name: fe_app64
path: fe_app64
- name: List the contents of the downloaded artifacts
run: |
Get-ChildItem -Recurse Yui-patch
Get-ChildItem -Recurse msojocs-patch
Get-ChildItem -Recurse fe_app64
shell: pwsh
- name: Rename main FE folder
run: Rename-Item -Path "fe_app64" -NewName "FE"
- name: Patch fiddler.dll / libfiddler.dll
run: |
$original_fiddler = "FE/${{ needs.download-Yui-patch.outputs.Yui-fiddler-name }}.dll"
$Yui_fiddler = "Yui-patch/${{ needs.download-Yui-patch.outputs.Yui-fiddler-name }}.dll"
if ((Test-Path $original_fiddler) -and (Test-Path $Yui_fiddler)) {
Copy-Item -Path $Yui_fiddler -Destination $original_fiddler -Force
Write-Host "Replaced $original_fiddler with $Yui_fiddler"
} else {
Write-Host "fiddler / libfiddler or Yui patch not found"
}
shell: pwsh
- name: Patch hostpolicy.dll
run: |
$original_hostpolicy = "FE/resources/app/out/WebServer/hostpolicy.dll"
$original_copy_hostpolicy = "FE/resources/app/out/WebServer/hostpolicy.original.dll"
$Yui_hostpolicy = "Yui-patch/hostpolicy.dll"
if ((Test-Path $original_hostpolicy) -and (Test-Path $Yui_hostpolicy)) {
Move-Item -Path $original_hostpolicy -Destination $original_copy_hostpolicy
Copy-Item -Path $Yui_hostpolicy -Destination $original_hostpolicy
Write-Host "Renamed $original_fiddler with $original_copy_hostpolicy & Applied Yui Patch"
} else {
Write-Host "original hostpolicy.dll or Yui hotstpolicy not found"
}
- name: Clean Yui-patch
run: |
if (Test-Path Yui-patch) {
Remove-Item -Path "Yui-patch" -Recurse
} else {
Write-Host "Yui-patch Folder not found"
}
- name: Copy Server Folder
run: |
$source_server_folder = "msojocs-patch/server/file"
$destination_server_folder = "FE/resources/app/out"
if (Test-Path $source_server_folder) {
Copy-Item -Path $source_server_folder -Destination $destination_server_folder -Recurse
} else {
Write-Host "Source Server Folder not found"
}
shell: pwsh
- name: Patch main.js to main.original.js
run: |
$source_main = "FE/resources/app/out/main.js"
$main_content = Get-Content -Path $source_main -Raw
$new_main = "FE/resources/app/out/main.original.js"
$source_index = "msojocs-patch/server/index.js"
$index_content = Get-Content -Path $source_index -Raw
if ((Test-Path $source_main) -and (Test-Path $source_index)) {
Copy-Item -Path $source_main -Destination $new_main
$appended_content = $index_content + $main_content
Set-Content -Path $source_main -Value $appended_content
} else {
Write-Host "Source main.js or index.js (from server) not found"
}
- name: Patch main.XXX.js to main.XXX.original.js
run: |
$directory = 'FE/resources/app/out/WebServer/ClientApp/dist'
$source_main = Get-ChildItem -Path $directory -Filter "main*" | Where-Object { -not $_.PSIsContainer }
if ($source_main) {
# Extract original file name without extension
$originalName = [System.IO.Path]::GetFileNameWithoutExtension($source_main.Name)
$originalFullPath = $source_main.FullName
# Define the new file name in the format "original-name.original.js"
$new_main_name = "$originalName.original.js"
# Rename the file
Copy-Item -Path $originalFullPath -Destination (Join-Path -Path $directory -ChildPath $new_main_name)
Write-Host "File renamed from $($source_main.Name) to $(Join-Path -Path $directory -ChildPath $new_main_name)"
Write-Host "Finding and Replacing now"
$source_content = Get-Content -Path $originalFullPath -Raw
$searchText1 = "https://api.getfiddler.com"
$replaceText1 = "http://127.0.0.1:5678/api.getfiddler.com"
$updatedText1 = $source_content -replace [regex]::Escape($searchText1), $replaceText1
$searchText2 = "https://identity.getfiddler.com"
$replaceText2 = "http://127.0.0.1:5678/identity.getfiddler.com"
$finalUpdatedText = $updatedText1 -replace [regex]::Escape($searchText2), $replaceText2
# Overwrite the file with the new content
Set-Content -Path $originalFullPath -Value $finalUpdatedText
echo "MAIN_XXX_NAME=$originalName" >> $env:GITHUB_ENV
} else {
Write-Host "No file found starting with 'main' in the specified directory. (Main,XXX.js)"
}
- name: Clean msojocs-patch
run: |
if (Test-Path msojocs-patch) {
Remove-Item -Path "msojocs-patch" -Recurse
} else {
Write-Host "msojocs-patch Folder not found"
}
- name: Add patch.json
run: |
$patch_json = "FE/resources/app/out/WebServer/patch.json"
$jsonContent = @{
"ClientApp\\dist\\$env:MAIN_XXX_NAME.js" = @{
"target" = "ClientApp\\dist\\$env:MAIN_XXX_NAME.original.js"
"content" = ""
"cur" = 0
"start" = 0
"end" = 1
}
"..\\main.js" = @{
"target" = "..\\main.original.js"
"content" = ""
"cur" = 0
"start" = 0
"end" = 1
}
}
# Convert the PowerShell object to JSON format
$jsonString = $jsonContent | ConvertTo-Json -Depth 10
# Write the JSON string to the file
$jsonString | Set-Content -Path $patch_json -Encoding UTF8
# Output message
Write-Host "JSON file created successfully at $patch_json"
- name: Rename FE
id: rename-fe
run: |
if (Test-Path FE) {
$newName = "Fiddler-Everywhere-V$env:VERSION_TO_PATCH-Patched"
Rename-Item -Path "FE" -NewName $newName
echo "patched-fe-name=$newName" | Out-File -Append -FilePath $env:GITHUB_OUTPUT
} else {
Write-Host "FE Folder not found!?"
}
- name: Upload Artifact for Patched FE
uses: actions/upload-artifact@v4
with:
name: "${{ steps.rename-fe.outputs.patched-fe-name }}"
path: "${{ steps.rename-fe.outputs.patched-fe-name }}/"
if-no-files-found: error