-
-
Notifications
You must be signed in to change notification settings - Fork 1
161 lines (137 loc) · 5.21 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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