parts #119
This file contains 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: Build and Package | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
build: | |
strategy: | |
matrix: | |
include: | |
- os: ubuntu-latest | |
arch: amd64 | |
- os: ubuntu-latest | |
arch: arm64 | |
- os: macos-latest # This will be ARM64 | |
arch: arm64 | |
- os: macos-13 # This will be AMD64 | |
arch: amd64 | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: '1.22' | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install setuptools wheel cffi packaging | |
- name: Install Zig | |
uses: goto-bus-stop/setup-zig@v2 | |
with: | |
version: 0.11.0 | |
- name: Set up Xcode | |
if: runner.os == 'macOS' | |
uses: maxim-lobanov/setup-xcode@v1 | |
with: | |
xcode-version: latest-stable | |
- name: Build Go shared library | |
working-directory: ./py | |
run: | | |
if [ "${{ runner.os }}" = "Linux" ] && [ "${{ matrix.arch }}" = "arm64" ]; then | |
CC="zig cc -target aarch64-linux-gnu" CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -o dnadesign/libdnadesign.so -buildmode=c-shared lib.go | |
elif [ "${{ runner.os }}" = "Linux" ] && [ "${{ matrix.arch }}" = "amd64" ]; then | |
CC="zig cc -target x86_64-linux-gnu" CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o dnadesign/libdnadesign.so -buildmode=c-shared lib.go | |
elif [ "${{ runner.os }}" = "macOS" ] && [ "${{ matrix.arch }}" = "arm64" ]; then | |
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o dnadesign/libdnadesign.dylib -buildmode=c-shared lib.go | |
elif [ "${{ runner.os }}" = "macOS" ] && [ "${{ matrix.arch }}" = "amd64" ]; then | |
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o dnadesign/libdnadesign.dylib -buildmode=c-shared lib.go | |
fi | |
env: | |
CGO_ENABLED: 1 | |
- name: List directory contents | |
working-directory: ./py/dnadesign | |
run: ls -l | |
- name: Build wheel | |
working-directory: ./py | |
run: | | |
pip install wheel packaging | |
if [ "${{ runner.os }}" = "Linux" ] && [ "${{ matrix.arch }}" = "amd64" ]; then | |
python setup.py bdist_wheel --plat-name manylinux2014_x86_64 | |
elif [ "${{ runner.os }}" = "Linux" ] && [ "${{ matrix.arch }}" = "arm64" ]; then | |
python setup.py bdist_wheel --plat-name manylinux2014_aarch64 | |
elif [ "${{ runner.os }}" = "macOS" ] && [ "${{ matrix.arch }}" = "amd64" ]; then | |
python setup.py bdist_wheel --plat-name macosx_10_9_x86_64 | |
elif [ "${{ runner.os }}" = "macOS" ] && [ "${{ matrix.arch }}" = "arm64" ]; then | |
python setup.py bdist_wheel --plat-name macosx_11_0_arm64 | |
elif [ "${{ runner.os }}" = "Windows" ]; then | |
python setup.py bdist_wheel --plat-name win_amd64 | |
else | |
python setup.py bdist_wheel | |
fi | |
- name: Test wheel in fresh environment | |
run: | | |
python -m venv test_env | |
source test_env/bin/activate | |
pip install ./py/dist/*.whl | |
python -c "from dnadesign import parsers; print('Library loaded successfully')" | |
pip install pytest | |
pytest ./py/tests -v --capture=no | |
continue-on-error: true | |
- name: Debug segmentation fault (macOS) | |
if: failure() && runner.os == 'macOS' | |
run: | | |
lldb -o "run" -o "bt all" -o "quit" -- python -m pytest ./py/tests -v | |
- name: Debug segmentation fault (Linux) | |
if: failure() && runner.os == 'Linux' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y gdb | |
gdb -ex "run" -ex "bt full" -ex "quit" --args python -m pytest ./py/tests -v | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: dist-${{ runner.os }}-${{ matrix.arch }} | |
path: py/dist/ | |
publish: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install twine | |
- name: Download artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
path: dist | |
- name: List directory structure | |
run: find dist -type f | |
- name: Check version and publish to PyPI | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
# Get the version from the wheel file name | |
WHEEL_FILE=$(find dist -name "*.whl" | head -n 1) | |
VERSION=$(echo $WHEEL_FILE | sed -E 's/.*dnadesign-([0-9]+\.[0-9]+\.[0-9]+).*/\1/') | |
echo "Package version: $VERSION" | |
# Check if the version exists on PyPI | |
if ! pip index versions dnadesign | grep -q "$VERSION"; then | |
echo "Version $VERSION not found on PyPI. Uploading..." | |
twine upload dist/**/*.whl | |
else | |
echo "Version $VERSION already exists on PyPI. Skipping upload." | |
fi |