-
Notifications
You must be signed in to change notification settings - Fork 3
138 lines (122 loc) · 5.01 KB
/
python-publish.yml
File metadata and controls
138 lines (122 loc) · 5.01 KB
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
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: deism
on:
release:
types: [published, prereleased]
jobs:
build-and-publish:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.9', '3.10', '3.11']
exclude:
- os: macos-latest
python-version: 3.9
permissions:
id-token: write # OIDC token required for authentication
# contents: read
steps:
- name: Checkout the code
uses: actions/checkout@v3
# Step 2: Set up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# Step 3: Install system dependencies for gmsh (Ubuntu only)
- name: Install system dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libglu1-mesa-dev libgl1-mesa-dev build-essential
# Step 3b: Setup C++ compiler for Windows (for count_reflections compilation)
- name: (Windows) Setup C++ compiler for count_reflections
if: matrix.os == 'windows-latest'
run: |
# Try to use existing g++ if available, otherwise try to install MinGW
if (Get-Command g++ -ErrorAction SilentlyContinue) {
echo "g++ is already available"
} else {
# Try to install MinGW via Chocolatey (if available)
if (Get-Command choco -ErrorAction SilentlyContinue) {
choco install mingw -y
$mingwPath = "$env:ChocolateyInstall\lib\mingw\tools\install\mingw64\bin"
if (Test-Path $mingwPath) {
echo "$mingwPath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
}
} else {
echo "Warning: g++ not found and Chocolatey not available. count_reflections will not be compiled."
echo "This is non-fatal - the package will still work without the C++ optimization."
}
}
# Step 4: Install dependencies using pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip # Ensure pip is up-to-date
pip install -r requirements.txt # Install dependencies from requirements.txt
- name: Build package
run: |
# Add ARCHFLAGS for macOS to build universal binary
if [[ "$RUNNER_OS" == "macOS" ]]; then
export ARCHFLAGS="-arch x86_64 -arch arm64"
fi
python -m pip install -e .
shell: bash
- name: Test with pytest
run: |
pip install -U pytest setuptools build wheel twine
ls -l deism/tests
pytest
# Build wheels (platform-specific)
- name: Build wheels (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
pip install auditwheel
python -m build --wheel
# List what's in dist/ for debugging
ls -la dist/
# Find and repair any .whl files
find dist/ -name "*.whl" -exec auditwheel repair {} \;
# Move repaired wheels to dist/ and remove wheelhouse/
if [ -d wheelhouse ]; then
mv wheelhouse/*.whl dist/
rm -rf wheelhouse
fi
# Remove original linux_x86_64 wheels
rm -f dist/*linux_x86_64.whl
twine check dist/*
- name: Build wheels (macOS/Windows)
if: matrix.os != 'ubuntu-latest'
run: |
python -m build --wheel
twine check dist/*
# Build source distribution on all platforms
- name: Build source distribution
run: |
python -m build --sdist
twine check dist/*
# Publish wheels to PyPI (only for production releases, not prereleases, all platforms)
- name: Publish wheels to PyPI
if: github.event_name == 'release' && github.event.action == 'published' && !github.event.release.prerelease
run: |
python -m pip install --upgrade twine
twine upload --skip-existing dist/*.whl
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.API_TOKEN }}
# Publish source distribution (only for production releases, all platforms)
- name: Publish source distribution to PyPI
if: github.event_name == 'release' && github.event.action == 'published' && !github.event.release.prerelease
run: |
python -m pip install --upgrade twine
twine upload --skip-existing dist/*.tar.gz
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.API_TOKEN }}