From 218b2a853a2879a38214cca1805b21370106c925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20Jourdane?= Date: Sat, 6 Sep 2025 01:43:26 +0200 Subject: [PATCH] add CI workflow to build binaries and add them on each new release --- .github/workflows/build.yml | 100 +++++++++++++++++++++++++ .github/workflows/{ci.yml => test.yml} | 2 +- .gitignore | 3 + ffsubsync/ffsubsync.py | 2 +- ffsubsync/version.py | 6 ++ 5 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build.yml rename .github/workflows/{ci.yml => test.yml} (99%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..048248e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,100 @@ +name: ffsubsync build + +on: + release: + types: [published] + +jobs: + build-binaries: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + include: + + - os: ubuntu-latest + os-name: "linux" + python-version: "3.11" + arch: "x86_64" + build-deps: "pyinstaller" + + - os: ubuntu-latest + os-name: "linux" + python-version: "3.11" + arch: "arm64" + build-deps: "pyinstaller" + + - os: macos-latest + os-name: "macos" + python-version: "3.11" + arch: "x86_64" + build-deps: "pyinstaller" + + - os: macos-latest + os-name: "macos" + python-version: "3.11" + arch: "arm64" + build-deps: "pyinstaller" + + - os: windows-latest + os-name: "windows" + python-version: "3.11" + arch: "x86_64" + build-deps: "pyinstaller setuptools wheel webrtcvad" + + steps: + - name: Check-out repository + uses: actions/checkout@v4 + + - name: Install UPX (Linux) + if: runner.os == 'Linux' + run: sudo apt-get update && sudo apt-get install -y upx-ucl + + - name: Install UPX (macOS) + if: runner.os == 'macOS' + run: brew install upx + + - name: Install UPX (Windows) + if: runner.os == 'Windows' + run: choco install upx + + - name: Prepare build requirements + run: echo "${{ matrix.build-deps }}" | tr ' ' '\n' > requirements-build.txt + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: pip + cache-dependency-path: | + requirements.txt + requirements-build.txt + + - name: Install dependencies + run: | + pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements-build.txt + + - name: Build executable with PyInstaller + run: | + echo 'FFSUBSYNC_VERSION = "${{ github.event.release.tag_name }}"' > ffsubsync/__version.py + pyinstaller --onefile --name ffsubsync ffsubsync/ffsubsync.py + + - name: Smoke test + run: ./dist/ffsubsync --version || ./dist/ffsubsync.exe --version + + - name: Package binary + shell: bash + run: | + cd dist + if [[ "${{ runner.os }}" == "Windows" ]]; then + powershell Compress-Archive -Path ffsubsync.exe -DestinationPath "${{ matrix.os-name }}-${{ matrix.arch }}.zip" + else + tar -czf "${{ matrix.os-name }}-${{ matrix.arch }}.tar.gz" ffsubsync + fi + + - name: Upload binaries to GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: ./dist/${{ matrix.os-name }}-${{ matrix.arch }}.* diff --git a/.github/workflows/ci.yml b/.github/workflows/test.yml similarity index 99% rename from .github/workflows/ci.yml rename to .github/workflows/test.yml index aea0877..346a5c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: ffsubsync +name: ffsubsync test on: [push, pull_request] diff --git a/.gitignore b/.gitignore index d9a59ea..44c878b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ dist __version__ .venv/ .coverage + +# Generated by PyInstaller +ffsubsync.spec diff --git a/ffsubsync/ffsubsync.py b/ffsubsync/ffsubsync.py index b0114cc..dbd70c2 100755 --- a/ffsubsync/ffsubsync.py +++ b/ffsubsync/ffsubsync.py @@ -564,7 +564,7 @@ def add_cli_only_args(parser: argparse.ArgumentParser) -> None: "--version", action="version", version="{package} {version}".format( - package=__package__, version=get_version() + package=__package__ or "ffsubsync", version=get_version() ), ) parser.add_argument( diff --git a/ffsubsync/version.py b/ffsubsync/version.py index 936e122..45dfd59 100644 --- a/ffsubsync/version.py +++ b/ffsubsync/version.py @@ -9,6 +9,12 @@ def get_version(): if "unknown" in __version__.lower(): + try: + from ffsubsync.__version import FFSUBSYNC_VERSION + return FFSUBSYNC_VERSION + except ImportError: + pass + with open( os.path.join(os.environ[SUBSYNC_RESOURCES_ENV_MAGIC], "__version__") ) as f: