Skip to content

Use FileSaveOptions (#773) #636

Use FileSaveOptions (#773)

Use FileSaveOptions (#773) #636

# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
#
name: PyPI Wheels
on:
# Build wheels on every push to test the build process
push:
branches:
- "**"
paths-ignore:
- "**/website/**"
tags:
- 'v*'
# Build on pull requests
pull_request:
branches:
- "**"
paths-ignore:
- "**/website/**"
# Allow manual trigger for testing builds or publishing
workflow_dispatch:
inputs:
publish:
description: 'Publish to PyPI (otherwise just build and test)'
required: false
type: boolean
default: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
build_cpu_wheels:
name: pypi-cpu-py${{ matrix.python-version }}-${{ matrix.os-short }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-14]
python-version: ['3.12', '3.13']
include:
- python-version: '3.12'
pixi-environment: py312
- python-version: '3.13'
pixi-environment: py313
- os: ubuntu-latest
os-short: ubuntu
- os: macos-14
os-short: mac-arm64
steps:
# Skip Python 3.13 builds on regular commits to reduce CI cost
# Python 3.13 builds will still run when publishing (tags or manual workflow_dispatch with publish=true)
- name: Check if should run
id: should_run
run: |
if [[ "${{ matrix.python-version }}" == "3.13" ]]; then
if [[ "${{ startsWith(github.ref, 'refs/tags/v') }}" == "true" ]] || \
[[ "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true' }}" == "true" ]]; then
echo "run=true" >> $GITHUB_OUTPUT
else
echo "run=false" >> $GITHUB_OUTPUT
fi
else
echo "run=true" >> $GITHUB_OUTPUT
fi
shell: bash
- uses: actions/checkout@v4
if: steps.should_run.outputs.run == 'true'
with:
submodules: recursive
- name: Set up pixi
if: steps.should_run.outputs.run == 'true'
uses: prefix-dev/[email protected]
with:
pixi-version: latest
cache: true
environments: ${{ matrix.pixi-environment }}
- name: Generate pyproject configs
if: steps.should_run.outputs.run == 'true'
run: pixi run -e ${{ matrix.pixi-environment }} generate_pyproject
- name: Clean distribution artifacts
if: steps.should_run.outputs.run == 'true'
run: pixi run -e ${{ matrix.pixi-environment }} clean_dist
- name: Build CPU wheel
if: steps.should_run.outputs.run == 'true'
run: pixi run -e ${{ matrix.pixi-environment }} build_pypi_wheel
- name: Repair CPU wheel (Linux only)
if: steps.should_run.outputs.run == 'true' && matrix.os == 'ubuntu-latest'
run: pixi run -e ${{ matrix.pixi-environment }} build_pypi_repair
- name: Upload wheel artifacts
if: steps.should_run.outputs.run == 'true'
uses: actions/upload-artifact@v5
with:
name: wheels-cpu-${{ matrix.os }}-py${{ matrix.python-version }}
path: dist/*.whl
retention-days: 7
build_gpu_wheels:
name: pypi-gpu-py${{ matrix.python-version }}-${{ matrix.os-short }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.12', '3.13']
include:
- python-version: '3.12'
pixi-environment: py312-cuda129
cuda-version: "12.9.0"
- python-version: '3.13'
pixi-environment: py313-cuda129
cuda-version: "12.9.0"
- os: ubuntu-latest
os-short: ubuntu
env:
FULL_CUDA_VERSION: ${{ matrix.cuda-version }}
steps:
# Skip Python 3.13 builds on regular commits to reduce CI cost
# Python 3.13 builds will still run when publishing (tags or manual workflow_dispatch with publish=true)
- name: Check if should run
id: should_run
run: |
if [[ "${{ matrix.python-version }}" == "3.13" ]]; then
if [[ "${{ startsWith(github.ref, 'refs/tags/v') }}" == "true" ]] || \
[[ "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true' }}" == "true" ]]; then
echo "run=true" >> $GITHUB_OUTPUT
else
echo "run=false" >> $GITHUB_OUTPUT
fi
else
echo "run=true" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Free disk space
if: steps.should_run.outputs.run == 'true' && matrix.os == 'ubuntu-latest'
run: |
echo "Before cleanup:"
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
echo "After cleanup:"
df -h
- name: Maximize build space (Ubuntu only)
if: steps.should_run.outputs.run == 'true' && matrix.os == 'ubuntu-latest'
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 30720
swap-size-mb: 1024
remove-dotnet: true
remove-android: true
remove-haskell: true
remove-codeql: true
remove-docker-images: true
- uses: actions/checkout@v4
if: steps.should_run.outputs.run == 'true'
with:
submodules: recursive
- name: Setup CUDA
if: steps.should_run.outputs.run == 'true'
uses: ./.github/actions/setup-cuda
with:
cuda-version: ${{ matrix.cuda-version }}
- name: Set up pixi
if: steps.should_run.outputs.run == 'true'
uses: prefix-dev/[email protected]
with:
pixi-version: latest
cache: true
environments: ${{ matrix.pixi-environment }}
- name: Generate pyproject configs
if: steps.should_run.outputs.run == 'true'
run: pixi run -e ${{ matrix.pixi-environment }} generate_pyproject
- name: Clean distribution artifacts
if: steps.should_run.outputs.run == 'true'
run: pixi run -e ${{ matrix.pixi-environment }} clean_dist
- name: Build GPU wheel
if: steps.should_run.outputs.run == 'true'
run: pixi run -e ${{ matrix.pixi-environment }} build_pypi_wheel
- name: Repair GPU wheel (Linux only)
if: steps.should_run.outputs.run == 'true' && matrix.os == 'ubuntu-latest'
run: pixi run -e ${{ matrix.pixi-environment }} build_pypi_repair
- name: Upload wheel artifacts
if: steps.should_run.outputs.run == 'true'
uses: actions/upload-artifact@v5
with:
name: wheels-gpu-${{ matrix.os }}-py${{ matrix.python-version }}
path: dist/*.whl
retention-days: 7
publish_cpu:
name: Publish pymomentum-cpu to PyPI
needs: [build_cpu_wheels]
runs-on: ubuntu-latest
environment:
name: pypi-cpu
url: https://pypi.org/p/pymomentum-cpu
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download CPU wheel artifacts
uses: actions/download-artifact@v6
with:
path: dist
pattern: wheels-cpu-*
merge-multiple: true
- name: List CPU distributions
run: ls -lh dist/
- name: Publish CPU to PyPI
if: |
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true')
uses: pypa/gh-action-pypi-publish@release/v1
publish_gpu:
name: Publish pymomentum-gpu to PyPI
needs: [build_gpu_wheels]
runs-on: ubuntu-latest
environment:
name: pypi-gpu
url: https://pypi.org/p/pymomentum-gpu
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download GPU wheel artifacts
uses: actions/download-artifact@v6
with:
path: dist
pattern: wheels-gpu-*
merge-multiple: true
- name: List GPU distributions
run: ls -lh dist/
- name: Publish GPU to PyPI
if: |
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true')
uses: pypa/gh-action-pypi-publish@release/v1