mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-03-08 23:03:55 -05:00
fix: resolve PowerShell ScriptBlock parsing error in Windows docker run commands
Refactored Windows container build steps to pipe PowerShell scripts via stdin instead of passing them as command-line arguments to `docker run`. This prevents PowerShell from incorrectly interpreting curly braces inside the script string as a ScriptBlock argument. Applied this fix to: - Preflight toolchain (Windows) - Build format (Windows) - Compress PDF (Windows) - Compress EPUB (Windows)
This commit is contained in:
44
.github/workflows/book-build-container.yml
vendored
44
.github/workflows/book-build-container.yml
vendored
@@ -459,7 +459,8 @@ jobs:
|
||||
shell: pwsh
|
||||
run: |
|
||||
Write-Host "🧪 Running Windows toolchain preflight checks..."
|
||||
docker run --rm -e PYTHONPATH=C:\workspace -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto" ${{ env.CONTAINER_IMAGE }} pwsh -NoLogo -Command "
|
||||
$preflightScript = @"
|
||||
|
||||
`$ErrorActionPreference = 'Stop'
|
||||
`$PSNativeCommandUseErrorActionPreference = `$true
|
||||
|
||||
@@ -528,7 +529,8 @@ jobs:
|
||||
if ('${{ matrix.format_name }}' -eq 'EPUB') {
|
||||
Invoke-Check 'Pillow import' { python -c 'import PIL; print(\"Pillow:\", PIL.__version__)' }
|
||||
}
|
||||
"
|
||||
"@
|
||||
$preflightScript | docker run --rm -e PYTHONPATH=C:\workspace -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto" ${{ env.CONTAINER_IMAGE }} -i pwsh -NoLogo -Command -
|
||||
Write-Host "✅ Windows toolchain preflight checks passed"
|
||||
|
||||
- name: 🔨 Build ${{ matrix.format_name }} (Linux)
|
||||
@@ -548,11 +550,13 @@ jobs:
|
||||
shell: pwsh
|
||||
run: |
|
||||
Write-Host "🔨 Building ${{ matrix.format_name }} on Windows container..."
|
||||
docker run --rm -e PYTHONPATH=C:\workspace -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto" ${{ env.CONTAINER_IMAGE }} pwsh -NoLogo -Command "
|
||||
$buildScript = @"
|
||||
|
||||
if (Test-Path '_quarto.yml') { Remove-Item '_quarto.yml' -Force }
|
||||
Copy-Item 'config\${{ matrix.config }}' '_quarto.yml' -Force
|
||||
quarto render --to ${{ matrix.render_target }} --output-dir '${{ matrix.output_dir }}'
|
||||
"
|
||||
"@
|
||||
$buildScript | docker run --rm -e PYTHONPATH=C:\workspace -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto" ${{ env.CONTAINER_IMAGE }} -i pwsh -NoLogo -Command -
|
||||
Write-Host "✅ ${{ matrix.format_name }} build completed"
|
||||
|
||||
- name: 📉 Compress PDF (Linux)
|
||||
@@ -595,21 +599,22 @@ jobs:
|
||||
shell: pwsh
|
||||
run: |
|
||||
Write-Host "🔨 Compressing PDF on Windows container..."
|
||||
docker run --rm -e PYTHONPATH=C:\workspace -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto\${{ matrix.output_dir }}" ${{ env.CONTAINER_IMAGE }} pwsh -NoLogo -Command "
|
||||
$compressPdfScript = @"
|
||||
|
||||
if (Test-Path 'Machine-Learning-Systems.pdf') {
|
||||
Write-Host '📉 Compressing PDF with professional compression tool...'
|
||||
Write-Host '🔍 DEBUG: Current directory:'
|
||||
Get-Location
|
||||
Write-Host '🔍 DEBUG: Windows environment info:'
|
||||
Write-Host (\"OS: {0}\" -f [System.Environment]::OSVersion.VersionString)
|
||||
Write-Host (\"Architecture: {0}\" -f [System.Environment]::Is64BitOperatingSystem)
|
||||
Write-Host ("OS: {0}" -f [System.Environment]::OSVersion.VersionString)
|
||||
Write-Host ("Architecture: {0}" -f [System.Environment]::Is64BitOperatingSystem)
|
||||
Write-Host '🔍 DEBUG: Verifying Python and Pillow installation:'
|
||||
`$py_version = (python --version 2>&1).Trim()
|
||||
Write-Host \" 🐍 Python Version: `$py_version\"
|
||||
Write-Host " 🐍 Python Version: `$py_version"
|
||||
`$py_path = (python -c 'import sys; print(sys.executable)').Trim()
|
||||
Write-Host \" 🐍 Python Path: `$py_path\"
|
||||
Write-Host " 🐍 Python Path: `$py_path"
|
||||
`$pillow_version = (python -c 'import PIL; print(PIL.__version__)').Trim()
|
||||
Write-Host \" ✅ Pillow Version: `$pillow_version\"
|
||||
Write-Host " ✅ Pillow Version: `$pillow_version"
|
||||
Write-Host '🔍 DEBUG: Checking for script at relative path:'
|
||||
if (Test-Path '..\\..\\publish\\compress_pdf.py') {
|
||||
Write-Host '✅ Found script at ..\\..\\publish\\compress_pdf.py'
|
||||
@@ -625,7 +630,8 @@ jobs:
|
||||
} else {
|
||||
Write-Warning '⚠️ Machine-Learning-Systems.pdf not found for compression.'
|
||||
}
|
||||
"
|
||||
"@
|
||||
$compressPdfScript | docker run --rm -e PYTHONPATH=C:\workspace -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto\${{ matrix.output_dir }}" ${{ env.CONTAINER_IMAGE }} -i pwsh -NoLogo -Command -
|
||||
Write-Host "✅ PDF compression completed."
|
||||
|
||||
- name: 📚 Compress EPUB (Linux)
|
||||
@@ -670,21 +676,22 @@ jobs:
|
||||
shell: pwsh
|
||||
run: |
|
||||
Write-Host "🔨 Compressing EPUB on Windows container..."
|
||||
docker run --rm -e PYTHONPATH=C:\workspace -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto\${{ matrix.output_dir }}" ${{ env.CONTAINER_IMAGE }} pwsh -NoLogo -Command "
|
||||
$compressEpubScript = @"
|
||||
|
||||
if (Test-Path 'Machine-Learning-Systems.epub') {
|
||||
Write-Host '📚 Compressing EPUB with optimized compression tool...'
|
||||
Write-Host '🔍 DEBUG: Current directory:'
|
||||
Get-Location
|
||||
Write-Host '🔍 DEBUG: Windows environment info:'
|
||||
Write-Host (\"OS: {0}\" -f [System.Environment]::OSVersion.VersionString)
|
||||
Write-Host (\"Architecture: {0}\" -f [System.Environment]::Is64BitOperatingSystem)
|
||||
Write-Host ("OS: {0}" -f [System.Environment]::OSVersion.VersionString)
|
||||
Write-Host ("Architecture: {0}" -f [System.Environment]::Is64BitOperatingSystem)
|
||||
Write-Host '🔍 DEBUG: Verifying Python and Pillow installation:'
|
||||
`$py_version = (python --version 2>&1).Trim()
|
||||
Write-Host \" 🐍 Python Version: `$py_version\"
|
||||
Write-Host " 🐍 Python Version: `$py_version"
|
||||
`$py_path = (python -c 'import sys; print(sys.executable)').Trim()
|
||||
Write-Host \" 🐍 Python Path: `$py_path\"
|
||||
Write-Host " 🐍 Python Path: `$py_path"
|
||||
`$pillow_version = (python -c 'import PIL; print(PIL.__version__)').Trim()
|
||||
Write-Host \" ✅ Pillow Version: `$pillow_version\"
|
||||
Write-Host " ✅ Pillow Version: `$pillow_version"
|
||||
Write-Host '🔍 DEBUG: Checking for script at relative path:'
|
||||
if (Test-Path '..\\..\\publish\\compress_epub.py') {
|
||||
Write-Host '✅ Found script at ..\\..\\publish\\compress_epub.py'
|
||||
@@ -700,7 +707,8 @@ jobs:
|
||||
} else {
|
||||
Write-Warning '⚠️ Machine-Learning-Systems.epub not found for compression.'
|
||||
}
|
||||
"
|
||||
"@
|
||||
$compressEpubScript | docker run --rm -e PYTHONPATH=C:\workspace -v "$($PWD.Path):C:\workspace" -w "C:\workspace\book\quarto\${{ matrix.output_dir }}" ${{ env.CONTAINER_IMAGE }} -i pwsh -NoLogo -Command -
|
||||
Write-Host "✅ EPUB compression completed."
|
||||
|
||||
- name: 📤 Upload artifact
|
||||
|
||||
Reference in New Issue
Block a user