Skip to content

Merge pull request #38 from bransoned/feature/25-combine-dependency-f… #72

Merge pull request #38 from bransoned/feature/25-combine-dependency-f…

Merge pull request #38 from bransoned/feature/25-combine-dependency-f… #72

# 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-22.04
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
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:
include:
- os: windows-latest
artifact_name: MemorEasy-Windows-X64.exe
- os: ubuntu-22.04
artifact_name: MemorEasy-Linux-X64
- os: macos-latest
artifact_name: MemorEasy-macOS-ARM64
- os: macos-15-intel
artifact_name: MemorEasy-macOS-X64
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
- name: Collect ffmpeg (Linux)
if: runner.os == 'Linux'
run: |
mkdir -p bin
FFMPEG_PATH=$(which ffmpeg)
echo "ffmpeg: $FFMPEG_PATH"
cp "$FFMPEG_PATH" bin/ffmpeg
chmod +x bin/ffmpeg
- name: Install system deps (macOS)
if: runner.os == 'macOS'
run: |
brew install ffmpeg
- name: Collect ffmpeg (macOS)
if: runner.os == 'macOS'
shell: bash
run: |
mkdir -p bin
FFMPEG_PATH=$(which ffmpeg)
echo "ffmpeg: $FFMPEG_PATH"
cp "$FFMPEG_PATH" bin/ffmpeg
chmod +x bin/ffmpeg
- name: Download ExifTool (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
curl -L https://sourceforge.net/projects/exiftool/files/exiftool-13.43_64.zip/download -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"
fi
pyinstaller $COMMON_ARGS $BIN_ARGS script.py
mkdir -p final_bin
cp dist/MemorEasy* final_bin/${{ matrix.artifact_name }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: final_bin/${{ matrix.artifact_name }}
- name: Upload binaries to GitHub Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: final_bin/*