mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-05-08 02:28:25 -05:00
feat(workflows): integrate professional compression scripts into build pipelines
- Replace inline Ghostscript commands with compress_pdf.py calls - Add EPUB compression using compress_epub.py in both workflows - Use minimal quality preset for PDF compression to match original behavior - Support both Linux and Windows platforms with proper executable detection - Maintain exact compatibility with previous compression settings - Add comprehensive error handling and progress reporting to builds
This commit is contained in:
81
.github/workflows/quarto-build-baremetal.yml
vendored
81
.github/workflows/quarto-build-baremetal.yml
vendored
@@ -623,28 +623,24 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: 📉 Compress PDF with Ghostscript (Linux)
|
||||
- name: 📉 Compress PDF (Linux)
|
||||
if: matrix.enabled && matrix.format == 'PDF' && runner.os == 'Linux'
|
||||
working-directory: ${{ steps.build.outputs.output_dir }}
|
||||
run: |
|
||||
if [ -f "Machine-Learning-Systems.pdf" ]; then
|
||||
gs \
|
||||
-sDEVICE=pdfwrite \
|
||||
-dCompatibilityLevel=1.4 \
|
||||
-dPDFSETTINGS=/ebook \
|
||||
-dNOPAUSE \
|
||||
-dQUIET \
|
||||
-dBATCH \
|
||||
-sOutputFile="ebook.pdf" \
|
||||
"Machine-Learning-Systems.pdf"
|
||||
|
||||
# Replace original with compressed
|
||||
mv ebook.pdf Machine-Learning-Systems.pdf
|
||||
echo "📉 Compressing PDF with professional compression tool..."
|
||||
python3 ../../../tools/scripts/publish/compress_pdf.py \
|
||||
--input "Machine-Learning-Systems.pdf" \
|
||||
--output "compressed.pdf" \
|
||||
--quality minimal \
|
||||
--verbose
|
||||
mv compressed.pdf Machine-Learning-Systems.pdf
|
||||
echo "✅ PDF compression completed"
|
||||
else
|
||||
echo "⚠️ PDF file not found for compression"
|
||||
fi
|
||||
|
||||
- name: 📉 Compress PDF with Ghostscript (Windows)
|
||||
- name: 📉 Compress PDF (Windows)
|
||||
if: matrix.enabled && matrix.format == 'PDF' && runner.os == 'Windows'
|
||||
shell: pwsh
|
||||
working-directory: ${{ steps.build.outputs.output_dir }}
|
||||
@@ -655,21 +651,66 @@ jobs:
|
||||
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
||||
|
||||
$input = "Machine-Learning-Systems.pdf"
|
||||
$output = "ebook.pdf"
|
||||
$output = "compressed.pdf"
|
||||
|
||||
if (!(Test-Path $input)) {
|
||||
Write-Warning "⚠️ Input PDF not found! Skipping compression..."
|
||||
exit 0 # Non-zero exit would fail the workflow
|
||||
}
|
||||
|
||||
Write-Output "📉 Compressing PDF using Ghostscript..."
|
||||
Write-Output "📉 Compressing PDF with professional compression tool..."
|
||||
|
||||
& gswin64c -sDEVICE=pdfwrite -dCompatibilityLevel:1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile="$output" "$input"
|
||||
python ../../../tools/scripts/publish/compress_pdf.py --input $input --output $output --quality minimal --verbose
|
||||
|
||||
if (Test-Path $output) {
|
||||
$afterSize = (Get-Item $output).Length / 1MB
|
||||
Write-Output ("📏 Compressed PDF size: {0:N2} MB" -f $afterSize)
|
||||
Write-Output "✅ Compression successful"
|
||||
Write-Output "✅ PDF compression completed"
|
||||
Move-Item -Force $output $input
|
||||
} else {
|
||||
Write-Warning "⚠️ Compression failed but continuing"
|
||||
}
|
||||
|
||||
- name: 📚 Compress EPUB (Linux)
|
||||
if: matrix.enabled && matrix.format == 'EPUB' && runner.os == 'Linux'
|
||||
working-directory: ${{ steps.build.outputs.output_dir }}
|
||||
run: |
|
||||
if [ -f "Machine-Learning-Systems.epub" ]; then
|
||||
echo "📚 Compressing EPUB with professional compression tool..."
|
||||
python3 ../../../tools/scripts/publish/compress_epub.py \
|
||||
--input "Machine-Learning-Systems.epub" \
|
||||
--output "compressed.epub" \
|
||||
--quality 70 \
|
||||
--max-size 1600 \
|
||||
--verbose
|
||||
mv compressed.epub Machine-Learning-Systems.epub
|
||||
echo "✅ EPUB compression completed"
|
||||
else
|
||||
echo "⚠️ EPUB file not found for compression"
|
||||
fi
|
||||
|
||||
- name: 📚 Compress EPUB (Windows)
|
||||
if: matrix.enabled && matrix.format == 'EPUB' && runner.os == 'Windows'
|
||||
shell: pwsh
|
||||
working-directory: ${{ steps.build.outputs.output_dir }}
|
||||
run: |
|
||||
# Set UTF-8 encoding for proper emoji display
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
$OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
||||
|
||||
$input = "Machine-Learning-Systems.epub"
|
||||
$output = "compressed.epub"
|
||||
|
||||
if (!(Test-Path $input)) {
|
||||
Write-Warning "⚠️ Input EPUB not found! Skipping compression..."
|
||||
exit 0 # Non-zero exit would fail the workflow
|
||||
}
|
||||
|
||||
Write-Output "📚 Compressing EPUB with professional compression tool..."
|
||||
|
||||
python ../../../tools/scripts/publish/compress_epub.py --input $input --output $output --quality 70 --max-size 1600 --verbose
|
||||
|
||||
if (Test-Path $output) {
|
||||
Write-Output "✅ EPUB compression completed"
|
||||
Move-Item -Force $output $input
|
||||
} else {
|
||||
Write-Warning "⚠️ Compression failed but continuing"
|
||||
|
||||
55
.github/workflows/quarto-build-container.yml
vendored
55
.github/workflows/quarto-build-container.yml
vendored
@@ -257,11 +257,16 @@ jobs:
|
||||
working-directory: quarto/${{ matrix.output_dir }}
|
||||
run: |
|
||||
if [ -f "Machine-Learning-Systems.pdf" ]; then
|
||||
echo "📉 Compressing PDF..."
|
||||
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
|
||||
-dNOPAUSE -dQUIET -dBATCH \
|
||||
-sOutputFile="compressed.pdf" "Machine-Learning-Systems.pdf"
|
||||
echo "📉 Compressing PDF with professional compression tool..."
|
||||
python3 ../../tools/scripts/publish/compress_pdf.py \
|
||||
--input "Machine-Learning-Systems.pdf" \
|
||||
--output "compressed.pdf" \
|
||||
--quality minimal \
|
||||
--verbose
|
||||
mv compressed.pdf Machine-Learning-Systems.pdf
|
||||
echo "✅ PDF compression completed"
|
||||
else
|
||||
echo "⚠️ PDF file not found for compression"
|
||||
fi
|
||||
|
||||
- name: 📉 Compress PDF (Windows)
|
||||
@@ -271,10 +276,11 @@ jobs:
|
||||
Write-Host "🔨 Compressing PDF on Windows container..."
|
||||
docker run --rm -v "$($PWD.Path):C:\workspace" -w "C:\workspace\quarto\${{ matrix.output_dir }}" ${{ env.CONTAINER_IMAGE }} powershell -Command "
|
||||
if (Test-Path 'Machine-Learning-Systems.pdf') {
|
||||
Write-Host '📉 Compressing PDF...'
|
||||
& gswin64c -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile='compressed.pdf' 'Machine-Learning-Systems.pdf'
|
||||
Write-Host '📉 Compressing PDF with professional compression tool...'
|
||||
python ../../tools/scripts/publish/compress_pdf.py --input 'Machine-Learning-Systems.pdf' --output 'compressed.pdf' --quality minimal --verbose
|
||||
if (Test-Path 'compressed.pdf') {
|
||||
Move-Item -Force 'compressed.pdf' 'Machine-Learning-Systems.pdf'
|
||||
Write-Host '✅ PDF compression completed'
|
||||
}
|
||||
} else {
|
||||
Write-Warning '⚠️ Machine-Learning-Systems.pdf not found for compression.'
|
||||
@@ -282,6 +288,43 @@ jobs:
|
||||
"
|
||||
Write-Host "✅ PDF compression completed."
|
||||
|
||||
- name: 📚 Compress EPUB (Linux)
|
||||
if: matrix.platform == 'linux' && matrix.format_name == 'EPUB' && matrix.enabled
|
||||
working-directory: quarto/${{ matrix.output_dir }}
|
||||
run: |
|
||||
if [ -f "Machine-Learning-Systems.epub" ]; then
|
||||
echo "📚 Compressing EPUB with professional compression tool..."
|
||||
python3 ../../tools/scripts/publish/compress_epub.py \
|
||||
--input "Machine-Learning-Systems.epub" \
|
||||
--output "compressed.epub" \
|
||||
--quality 70 \
|
||||
--max-size 1600 \
|
||||
--verbose
|
||||
mv compressed.epub Machine-Learning-Systems.epub
|
||||
echo "✅ EPUB compression completed"
|
||||
else
|
||||
echo "⚠️ EPUB file not found for compression"
|
||||
fi
|
||||
|
||||
- name: 📚 Compress EPUB (Windows)
|
||||
if: matrix.platform == 'windows' && matrix.format_name == 'EPUB' && matrix.enabled
|
||||
shell: pwsh
|
||||
run: |
|
||||
Write-Host "🔨 Compressing EPUB on Windows container..."
|
||||
docker run --rm -v "$($PWD.Path):C:\workspace" -w "C:\workspace\quarto\${{ matrix.output_dir }}" ${{ env.CONTAINER_IMAGE }} powershell -Command "
|
||||
if (Test-Path 'Machine-Learning-Systems.epub') {
|
||||
Write-Host '📚 Compressing EPUB with professional compression tool...'
|
||||
python ../../tools/scripts/publish/compress_epub.py --input 'Machine-Learning-Systems.epub' --output 'compressed.epub' --quality 70 --max-size 1600 --verbose
|
||||
if (Test-Path 'compressed.epub') {
|
||||
Move-Item -Force 'compressed.epub' 'Machine-Learning-Systems.epub'
|
||||
Write-Host '✅ EPUB compression completed'
|
||||
}
|
||||
} else {
|
||||
Write-Warning '⚠️ Machine-Learning-Systems.epub not found for compression.'
|
||||
}
|
||||
"
|
||||
Write-Host "✅ EPUB compression completed."
|
||||
|
||||
- name: 📤 Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
if: matrix.enabled
|
||||
|
||||
Reference in New Issue
Block a user