Build and upload PyPI wheels and source dist #102
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 upload PyPI wheels and source dist | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
jobs: | |
build-wheels: | |
strategy: | |
matrix: | |
os: [windows-latest, macos-13, macos-latest, ubuntu-latest] | |
python-version: ['3.10', '3.11', '3.12'] | |
include: | |
- os: windows-latest | |
wheelname: win | |
cibw_archs: "AMD64" | |
- os: macos-13 | |
wheelname: macosx | |
cibw_archs: "x86_64" | |
- os: macos-latest | |
wheelname: macosx | |
cibw_archs: "arm64" | |
- os: ubuntu-latest | |
wheelname: manylinux | |
cibw_archs: "x86_64" | |
- python-version: '3.10' | |
version-tag: cp310 | |
- python-version: '3.11' | |
version-tag: cp311 | |
- python-version: '3.12' | |
version-tag: cp312 | |
fail-fast: false | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout project (for test files) | |
uses: actions/checkout@v4 | |
- name: Setup Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install llvm on Macos | |
if: startsWith(matrix.os, 'macos') | |
shell: bash -l {0} | |
env: | |
# Homebrew location is different on Intel Mac | |
LLVM_DIR: ${{ (matrix.os == 'macos-13') && '/usr/local/opt/llvm' || '/opt/homebrew/opt/llvm' }} | |
run: | | |
brew install llvm | |
echo CC="${LLVM_DIR}/bin/clang" >> $GITHUB_ENV | |
echo LDFLAGS="-L${LLVM_DIR}/lib $LDFLAGS" >> $GITHUB_ENV | |
echo CPPFLAGS="-I${LLVM_DIR}/include $CPPFLAGS" >> $GITHUB_ENV | |
- name: Windows - find MSVC and set environment variables | |
if: startsWith(matrix.os, 'windows') | |
shell: bash -l {0} | |
env: | |
MSVC_PREFIX: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC' | |
run: | | |
echo "Available MSVC installations:" | |
ls "$MSVC_PREFIX" | |
MSVC_BIN=$(ls "$MSVC_PREFIX" | tail -n 1)\\bin\\HostX64\\x64 | |
CC="$MSVC_PREFIX\\$MSVC_BIN\\cl.exe" | |
echo "CC: $CC" | |
echo "CC=$CC" >> $GITHUB_ENV | |
CC_LD="$MSVC_PREFIX\\$MSVC_BIN\\link.exe" | |
echo "CC_LD: $CC_LD" | |
echo "CC_LD=$CC_LD" >> $GITHUB_ENV | |
- name: Update Python pip, build, wheel, and twine | |
shell: bash -l {0} | |
run: | | |
python -m pip install --upgrade pip build wheel twine | |
- name: Build wheels from git checkout | |
uses: pypa/[email protected] | |
env: | |
CIBW_BUILD_FRONTEND: build | |
CIBW_BUILD: ${{ matrix.version-tag }}-* | |
CIBW_ARCHS: ${{ matrix.cibw_archs }} | |
CIBW_SKIP: "*-musllinux*" | |
CIBW_REPAIR_WHEEL_COMMAND_MACOS: "" | |
CIBW_TEST_EXTRAS: "test,brille,phonopy_reader,matplotlib" | |
CIBW_TEST_COMMAND: "python {package}/tests_and_analysis/test/run_tests.py" | |
with: | |
output-dir: wheelhouse | |
- name: Upload wheels as build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheel-${{ matrix.wheelname }}-${{ matrix.python-version }}-${{ matrix.cibw_archs }} | |
path: wheelhouse/*-${{ matrix.wheelname }}*_${{ matrix.cibw_archs }}.whl | |
if-no-files-found: error | |
build-sdist: | |
name: Build sdist | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Ensure tags are fetched for versioning | |
- name: Create source distribution | |
shell: bash -l {0} | |
run: | | |
pipx run build --sdist . | |
- name: Upload source dist as build artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-source-distribution | |
path: dist/ | |
if-no-files-found: error | |
test-sdist: | |
needs: build-sdist | |
name: Test build from sdist on Windows | |
runs-on: windows-latest | |
steps: | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.11 | |
- name: Find MSVC and set environment variables | |
shell: bash -l {0} | |
env: | |
MSVC_PREFIX: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC' | |
run: | | |
echo "Available MSVC installations:" | |
ls "$MSVC_PREFIX" | |
MSVC_BIN=$(ls "$MSVC_PREFIX" | tail -n 1)\\bin\\HostX64\\x64 | |
CC="$MSVC_PREFIX\\$MSVC_BIN\\cl.exe" | |
echo "CC: $CC" | |
echo "CC=$CC" >> $GITHUB_ENV | |
CC_LD="$MSVC_PREFIX\\$MSVC_BIN\\link.exe" | |
echo "CC_LD: $CC_LD" | |
echo "CC_LD=$CC_LD" >> $GITHUB_ENV | |
- name: Download sdist | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist/ | |
merge-multiple: true | |
- name: List downloaded sdist | |
run: | | |
ls -R dist/ | |
- name: Update pip | |
shell: bash -l {0} | |
run: | | |
python -m pip install --upgrade pip | |
- name: Install from sdist | |
shell: bash -l {0} | |
run: python -m pip install $(find dist -name 'euphonic-*.tar.gz')[matplotlib,phonopy_reader,brille,test] | |
- name: Checkout repository (for tests and test data) | |
uses: actions/checkout@v4 | |
- name: Delete source (to ensure we are testing INSTALLED version) | |
shell: bash -l {0} | |
run: rm -rf euphonic | |
- name: run tests | |
shell: bash -l {0} | |
run: python tests_and_analysis/test/run_tests.py --report | |
publish: | |
if: github.event_name == 'release' | |
needs: [build-wheels,test-sdist] | |
name: Upload release to PyPI | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
url: https://pypi.org/p/euphonic | |
permissions: | |
id-token: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # This is possibly unnecessary? | |
- name: Download artifacts to Ubuntu environment | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist/ | |
merge-multiple: true | |
- name: List Files | |
run: ls -R dist/ | |
- name: Upload wheels to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 |