This repository contains reusable CI/CD scripts for automatically compiling Python files to Cython .so files and syncing them to a production branch.
- 🔍 Automatically detects changed Python files between branches
- 🔨 Compiles Python files to Cython
.sofiles for performance and obfuscation - 🔄 Syncs compiled files to production branch
- 🚫 Exclusion support - Skip specific files/directories from compilation and sync
- 🧹 Handles deleted files cleanup
Use this as a reusable workflow in your repository:
name: Cython Sync
on:
push:
branches:
- main
jobs:
sync:
uses: orangewood-co/ci-scripts/.github/workflows/cython-sync.yml@main
secrets:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
python-version: '3.10'
prod-branch: 'prod'Create a .cythonignore file in the root of your repository (the one using this workflow) to specify which files should NOT be compiled or synced to prod.
# In your project repository (not in ci-scripts)
touch .cythonignoreThe file supports multiple pattern types:
Exact file paths:
setup.py
config/settings.py
Wildcard patterns:
test_*.py # All files starting with test_
*_test.py # All files ending with _test.py
Directory patterns:
tests/ # Exclude entire tests directory
examples/ # Exclude entire examples directory
scripts/ # Exclude entire scripts directory
Comments and blank lines:
# This is a comment
# Blank lines are ignored
# Configuration files
setup.py
config.py
# Test files
test_*.py
tests/
conftest.py
# Examples and demos
examples/
demo_*.py
example_*.py
# Development scripts
scripts/dev_*.py
tools/
- When the workflow runs, it checks for a
.cythonignorefile in your repository root - Any files matching the patterns are excluded from:
- Cython compilation
- Syncing to the prod branch
- Excluded files remain as regular
.pyfiles in the prod branch (if they exist)
Scenario 1: Exclude test files
# .cythonignore
test_*.py
tests/
Result: Test files stay as .py in prod, not compiled to .so
Scenario 2: Exclude configuration and setup
# .cythonignore
setup.py
config/*.py
Result: Setup and config files remain editable in prod
Scenario 3: Exclude entire directories
# .cythonignore
examples/
docs/
scripts/
Result: These directories are completely skipped from Cython compilation
- Python 3.8+
- Cython
- Git repository with
mainandprodbranches
detect_changes.py- Detects changed/deleted Python files and applies exclusionscompile_to_cython.sh- Compiles Python files to Cython.sofilessync_to_prod.sh- Syncs compiled files to production branch
MIT License