Update python-package.yml #29
Workflow file for this run
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
| # This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | |
| name: Test and Build | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| tags: | |
| - "v*" | |
| pull_request: | |
| branches: [ "main" ] | |
| permissions: | |
| contents: write | |
| jobs: | |
| # Test on multiple Python versions (Linux) | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v3 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| - name: Lint with flake8 | |
| run: | | |
| pip install flake8 | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - name: Test with pytest (if tests exist) | |
| run: | | |
| pip install pytest | |
| pytest || echo "No tests found" | |
| # ----------------------------- | |
| # Build binaries (all OSes) | |
| # ----------------------------- | |
| build: | |
| needs: test | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [windows-latest, ubuntu-latest, macos-latest] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v3 | |
| with: | |
| python-version: "3.12" | |
| # ----------------------------- | |
| # OS-specific dependencies | |
| # ----------------------------- | |
| - name: Install system deps (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ffmpeg exiftool | |
| - name: Collect ffmpeg & exiftool (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| mkdir -p bin | |
| FFMPEG_PATH=$(which ffmpeg) | |
| EXIFTOOL_PATH=$(which exiftool) | |
| echo "ffmpeg: $FFMPEG_PATH" | |
| echo "exiftool: $EXIFTOOL_PATH" | |
| cp "$FFMPEG_PATH" bin/ffmpeg | |
| cp "$EXIFTOOL_PATH" bin/exiftool | |
| chmod +x bin/ffmpeg bin/exiftool | |
| - name: Install system deps (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| brew install ffmpeg exiftool | |
| - name: Collect ffmpeg & exiftool (macOS) | |
| if: runner.os == 'macOS' | |
| shell: bash | |
| run: | | |
| mkdir -p bin | |
| FFMPEG_PATH=$(which ffmpeg) | |
| EXIFTOOL_PATH=$(which exiftool) | |
| echo "ffmpeg: $FFMPEG_PATH" | |
| echo "exiftool: $EXIFTOOL_PATH" | |
| cp "$FFMPEG_PATH" bin/ffmpeg | |
| cp "$EXIFTOOL_PATH" bin/exiftool | |
| chmod +x bin/ffmpeg bin/exiftool | |
| - name: Download ExifTool (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| curl -L https://exiftool.org/exiftool-13.43_64.zip -o exiftool.zip | |
| mkdir bin | |
| Expand-Archive exiftool.zip exiftool_temp -Force | |
| $inner = Get-ChildItem exiftool_temp -Directory | Select-Object -First 1 | |
| Move-Item "$($inner.FullName)\*" exiftool_temp -Force | |
| Remove-Item $inner.FullName -Recurse -Force | |
| Move-Item "exiftool_temp/exiftool(-k).exe" bin/exiftool.exe | |
| Move-Item exiftool_temp/exiftool_files bin/exiftool_files | |
| Remove-Item exiftool_temp, exiftool.zip -Recurse -Force | |
| - name: Download ffmpeg (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| curl -L https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip -o ffmpeg.zip | |
| Expand-Archive ffmpeg.zip ffmpeg_temp -Force | |
| $inner = Get-ChildItem ffmpeg_temp -Directory | Select-Object -First 1 | |
| Move-Item "$($inner.FullName)\*" ffmpeg_temp -Force | |
| Remove-Item $inner.FullName -Recurse -Force | |
| Move-Item ffmpeg_temp/bin/ffmpeg.exe bin/ffmpeg.exe | |
| Remove-Item ffmpeg_temp, ffmpeg.zip -Recurse -Force | |
| # ----------------------------- | |
| # Python + PyInstaller | |
| # ----------------------------- | |
| - name: Install Python deps | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pyinstaller | |
| - name: Build binary | |
| shell: bash | |
| run: | | |
| COMMON_ARGS="--onefile \ | |
| --name MemorEasy \ | |
| --copy-metadata imageio \ | |
| --copy-metadata imageio-ffmpeg \ | |
| --copy-metadata moviepy" | |
| if [[ "$RUNNER_OS" == "Windows" ]]; then | |
| BIN_ARGS="\ | |
| --add-binary bin/exiftool.exe;bin \ | |
| --add-binary bin/ffmpeg.exe;bin \ | |
| --add-data bin/exiftool_files;bin/exiftool_files" | |
| else | |
| BIN_ARGS="\ | |
| --add-binary bin/ffmpeg:bin \ | |
| --add-binary bin/exiftool:bin" | |
| fi | |
| pyinstaller $COMMON_ARGS $BIN_ARGS script.py | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: MemorEasy-${{ runner.os }} | |
| path: dist/* | |
| - name: Upload binaries to GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: dist/* |