fix: use find-based file discovery in compress steps and preview deploy

Replace hardcoded Machine-Learning-Systems.pdf/.epub filenames with
find-based discovery in all 4 compress steps (Linux/Windows PDF/EPUB)
and the dev preview deploy workflow. This ensures correct packaging
regardless of the output filename set in Quarto YAML configs.
This commit is contained in:
Vijay Janapa Reddi
2026-03-06 18:11:11 -05:00
parent 9b81b58cef
commit 9f11116c4b
2 changed files with 53 additions and 79 deletions

View File

@@ -629,35 +629,24 @@ jobs:
if: matrix.platform == 'linux' && matrix.format_name == 'PDF' && matrix.enabled
working-directory: ${{ vars.BOOK_QUARTO }}/${{ matrix.output_dir }}
run: |
if [ -f "Machine-Learning-Systems.pdf" ]; then
echo "📉 Compressing PDF with professional compression tool..."
echo "🔍 DEBUG: PWD=$(pwd)"
echo "🔍 DEBUG: Checking for compress script:"
ls -la ../../publish/compress_pdf.py || echo "❌ Script not found at ../../publish/"
PDF_FILE=$(find . -maxdepth 1 -name "*.pdf" -type f | head -1)
if [ -n "$PDF_FILE" ]; then
PDF_NAME=$(basename "$PDF_FILE")
echo "📉 Compressing $PDF_NAME..."
# Use relative path from current working directory (book/quarto/_build/pdf)
SCRIPT_PATH="../../publish/compress_pdf.py"
if [ -f "$SCRIPT_PATH" ]; then
echo "✅ Using script at: $SCRIPT_PATH"
python3 "$SCRIPT_PATH" \
--input "Machine-Learning-Systems.pdf" \
--output "compressed.pdf" \
--quality minimal \
--verbose
else
# Fallback to absolute path via github.workspace
if [ ! -f "$SCRIPT_PATH" ]; then
SCRIPT_PATH="${{ github.workspace }}/${{ vars.BOOK_QUARTO }}/publish/compress_pdf.py"
echo "🔄 Trying fallback path: $SCRIPT_PATH"
python3 "$SCRIPT_PATH" \
--input "Machine-Learning-Systems.pdf" \
--output "compressed.pdf" \
--quality minimal \
--verbose
fi
mv compressed.pdf Machine-Learning-Systems.pdf
echo "✅ PDF compression completed"
python3 "$SCRIPT_PATH" \
--input "$PDF_NAME" \
--output "compressed.pdf" \
--quality minimal \
--verbose
mv compressed.pdf "$PDF_NAME"
echo "✅ PDF compression completed: $PDF_NAME"
else
echo "⚠️ PDF file not found for compression"
echo "⚠️ No PDF file found for compression"
fi
- name: 📉 Compress PDF (Windows)
@@ -669,28 +658,28 @@ jobs:
$scriptContent = @'
$ErrorActionPreference = 'Stop'
if (Test-Path 'Machine-Learning-Systems.pdf') {
Write-Host '📉 Compressing PDF with professional compression tool...'
Write-Host "📋 Current directory: $(Get-Location)"
$pdfFile = Get-ChildItem -Filter '*.pdf' -File | Select-Object -First 1
if ($pdfFile) {
$pdfName = $pdfFile.Name
Write-Host "📉 Compressing $pdfName..."
$scriptPath = '..\..\publish\compress_pdf.py'
if (-not (Test-Path $scriptPath)) {
$scriptPath = 'C:\workspace\book\quarto\publish\compress_pdf.py'
}
Write-Host "📋 Using script: $scriptPath"
python $scriptPath --input 'Machine-Learning-Systems.pdf' --output 'compressed.pdf' --quality minimal --verbose
python $scriptPath --input $pdfName --output 'compressed.pdf' --quality minimal --verbose
if ($LASTEXITCODE -ne 0) { Write-Error "PDF compression failed"; exit $LASTEXITCODE }
if (Test-Path 'compressed.pdf') {
Move-Item -Force 'compressed.pdf' 'Machine-Learning-Systems.pdf'
Write-Host '✅ PDF compression completed'
Move-Item -Force 'compressed.pdf' $pdfName
Write-Host "✅ PDF compression completed: $pdfName"
} else {
Write-Error '❌ compressed.pdf was not produced'
exit 1
}
} else {
Write-Warning '⚠️ Machine-Learning-Systems.pdf not found for compression.'
Write-Warning '⚠️ No PDF file found for compression.'
}
'@
@@ -716,37 +705,23 @@ jobs:
if: matrix.platform == 'linux' && matrix.format_name == 'EPUB' && matrix.enabled
working-directory: ${{ vars.BOOK_QUARTO }}/${{ matrix.output_dir }}
run: |
if [ -f "Machine-Learning-Systems.epub" ]; then
echo "📚 Compressing EPUB with optimized compression tool..."
echo "🔍 DEBUG: PWD=$(pwd)"
echo "🔍 DEBUG: Repository structure from current directory:"
ls -la ../../ | head -10
echo "🔍 DEBUG: Checking for compress script:"
ls -la ../../publish/compress_epub.py || echo "❌ Script not found at ../../publish/"
echo "🔍 DEBUG: Checking fallback path:"
ls -la "${{ github.workspace }}/${{ vars.BOOK_QUARTO }}/publish/compress_epub.py" || echo "❌ Script not found at github.workspace path"
EPUB_FILE=$(find . -maxdepth 1 -name "*.epub" -type f | head -1)
if [ -n "$EPUB_FILE" ]; then
EPUB_NAME=$(basename "$EPUB_FILE")
echo "📚 Compressing $EPUB_NAME..."
# Use relative path from current working directory (book/quarto/_build/epub)
SCRIPT_PATH="../../publish/compress_epub.py"
if [ -f "$SCRIPT_PATH" ]; then
echo "✅ Using script at: $SCRIPT_PATH"
python3 "$SCRIPT_PATH" \
--input "Machine-Learning-Systems.epub" \
--output "compressed.epub" \
--verbose
else
# Fallback to absolute path via github.workspace
if [ ! -f "$SCRIPT_PATH" ]; then
SCRIPT_PATH="${{ github.workspace }}/${{ vars.BOOK_QUARTO }}/publish/compress_epub.py"
echo "🔄 Trying fallback path: $SCRIPT_PATH"
python3 "$SCRIPT_PATH" \
--input "Machine-Learning-Systems.epub" \
--output "compressed.epub" \
--verbose
fi
mv compressed.epub Machine-Learning-Systems.epub
echo "✅ EPUB compression completed (using optimized defaults: quality=50, max-size=1000px)"
python3 "$SCRIPT_PATH" \
--input "$EPUB_NAME" \
--output "compressed.epub" \
--verbose
mv compressed.epub "$EPUB_NAME"
echo "✅ EPUB compression completed: $EPUB_NAME"
else
echo "⚠️ EPUB file not found for compression"
echo "⚠️ No EPUB file found for compression"
fi
- name: 📚 Compress EPUB (Windows)
@@ -758,37 +733,36 @@ jobs:
$scriptContent = @'
$ErrorActionPreference = 'Stop'
if (Test-Path 'Machine-Learning-Systems.epub') {
Write-Host '📚 Compressing EPUB with optimized compression tool...'
Write-Host "📋 Current directory: $(Get-Location)"
$epubFile = Get-ChildItem -Filter '*.epub' -File | Select-Object -First 1
if ($epubFile) {
$epubName = $epubFile.Name
Write-Host "📚 Compressing $epubName..."
$scriptPath = $null
if (Test-Path '..\..\publish\compress_epub.py') {
$scriptPath = '..\..\publish\compress_epub.py'
Write-Host "✅ Found script at $scriptPath"
} elseif (Test-Path 'C:\workspace\book\quarto\publish\compress_epub.py') {
$scriptPath = 'C:\workspace\book\quarto\publish\compress_epub.py'
Write-Host "🔄 Using fallback path: $scriptPath"
} else {
Write-Error '❌ compress_epub.py not found!'
exit 1
}
python $scriptPath --input 'Machine-Learning-Systems.epub' --output 'compressed.epub' --verbose
python $scriptPath --input $epubName --output 'compressed.epub' --verbose
if ($LASTEXITCODE -ne 0) {
Write-Error "❌ EPUB compression failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
}
if (Test-Path 'compressed.epub') {
Move-Item -Force 'compressed.epub' 'Machine-Learning-Systems.epub'
Write-Host '✅ EPUB compression completed'
Move-Item -Force 'compressed.epub' $epubName
Write-Host "✅ EPUB compression completed: $epubName"
} else {
Write-Error '❌ compressed.epub was not created!'
exit 1
}
} else {
Write-Warning '⚠️ Machine-Learning-Systems.epub not found for compression.'
Write-Warning '⚠️ No EPUB file found for compression.'
}
'@

View File

@@ -129,18 +129,18 @@ jobs:
mkdir -p ./preview-site/vol1/assets/downloads ./preview-site/vol2/assets/downloads
if [ -f "./pdf-vol1-artifact/Machine-Learning-Systems.pdf" ]; then
cp "./pdf-vol1-artifact/Machine-Learning-Systems.pdf" "./preview-site/vol1/assets/downloads/Machine-Learning-Systems-Vol1.pdf"
fi
if [ -f "./epub-vol1-artifact/Machine-Learning-Systems.epub" ]; then
cp "./epub-vol1-artifact/Machine-Learning-Systems.epub" "./preview-site/vol1/assets/downloads/Machine-Learning-Systems-Vol1.epub"
fi
if [ -f "./pdf-vol2-artifact/Machine-Learning-Systems.pdf" ]; then
cp "./pdf-vol2-artifact/Machine-Learning-Systems.pdf" "./preview-site/vol2/assets/downloads/Machine-Learning-Systems-Vol2.pdf"
fi
if [ -f "./epub-vol2-artifact/Machine-Learning-Systems.epub" ]; then
cp "./epub-vol2-artifact/Machine-Learning-Systems.epub" "./preview-site/vol2/assets/downloads/Machine-Learning-Systems-Vol2.epub"
fi
# Copy PDF/EPUB downloads (find by extension, rename to consistent volume-specific names)
VOL1_PDF=$(find ./pdf-vol1-artifact -name "*.pdf" -type f 2>/dev/null | head -1)
[ -n "$VOL1_PDF" ] && cp "$VOL1_PDF" "./preview-site/vol1/assets/downloads/Machine-Learning-Systems-Vol1.pdf"
VOL1_EPUB=$(find ./epub-vol1-artifact -name "*.epub" -type f 2>/dev/null | head -1)
[ -n "$VOL1_EPUB" ] && cp "$VOL1_EPUB" "./preview-site/vol1/assets/downloads/Machine-Learning-Systems-Vol1.epub"
VOL2_PDF=$(find ./pdf-vol2-artifact -name "*.pdf" -type f 2>/dev/null | head -1)
[ -n "$VOL2_PDF" ] && cp "$VOL2_PDF" "./preview-site/vol2/assets/downloads/Machine-Learning-Systems-Vol2.pdf"
VOL2_EPUB=$(find ./epub-vol2-artifact -name "*.epub" -type f 2>/dev/null | head -1)
[ -n "$VOL2_EPUB" ] && cp "$VOL2_EPUB" "./preview-site/vol2/assets/downloads/Machine-Learning-Systems-Vol2.epub"
- name: 📝 Create .nojekyll file
run: touch ./preview-site/.nojekyll