Add automatic icon optimization to workflow #64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: NuGet Publish | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| paths: | |
| - '**.cs' | |
| - '**.csproj' | |
| - '.github/workflows/nuget-publish.yml' | |
| release: | |
| types: [ published ] | |
| workflow_dispatch: | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Optimize package icon | |
| run: | | |
| python3 << 'EOF' | |
| from PIL import Image | |
| import os | |
| icon_path = 'icon.png' | |
| if os.path.exists(icon_path): | |
| print(f"Processing {icon_path}...") | |
| img = Image.open(icon_path) | |
| # Trim transparent borders | |
| bbox = img.getbbox() | |
| if bbox: | |
| img = img.crop(bbox) | |
| print(f"Trimmed to: {img.size}") | |
| # Resize maintaining aspect ratio | |
| img.thumbnail((512, 512), Image.Resampling.LANCZOS) | |
| print(f"Resized to: {img.size}") | |
| # Center on 512x512 canvas with transparent background | |
| new_img = Image.new('RGBA', (512, 512), (0, 0, 0, 0)) | |
| offset = ((512 - img.width) // 2, (512 - img.height) // 2) | |
| new_img.paste(img, offset) | |
| # Save optimized | |
| new_img.save(icon_path, 'PNG', optimize=True) | |
| print(f"Saved optimized icon: {os.path.getsize(icon_path)} bytes") | |
| else: | |
| print(f"Icon not found at {icon_path}, skipping optimization") | |
| EOF | |
| - name: Setup .NET SDKs | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: | | |
| 8.0.x | |
| 9.0.x | |
| 10.0.x | |
| - name: Install OCR dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ghostscript tesseract-ocr | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build solution | |
| run: dotnet build --configuration Release --no-restore | |
| - name: Run tests | |
| run: dotnet test --configuration Release --no-build --verbosity normal | |
| - name: Pack NuGet package | |
| run: dotnet pack CreatePdf.NET/CreatePdf.NET.csproj --configuration Release --no-build --output ./nupkg -p:GeneratePackageOnBuild=false | |
| - name: Authenticate with NuGet | |
| uses: NuGet/login@v1 | |
| if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' | |
| - name: Publish packages to NuGet.org | |
| if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' | |
| run: | | |
| dotnet nuget push ./nupkg/*.nupkg \ | |
| --source https://api.nuget.org/v3/index.json \ | |
| --skip-duplicate |