Skip to content

Merge branch 'main' of github.com:ironArray/Caterva2 #423

Merge branch 'main' of github.com:ironArray/Caterva2

Merge branch 'main' of github.com:ironArray/Caterva2 #423

Workflow file for this run

name: Build and Publish Python Wheels for Caterva2
on:
push:
branches:
- main # Rebuild wheels on every commit to main
permissions:
contents: write # Needed for GITHUB_TOKEN to push
jobs:
build_wheels:
runs-on: ubuntu-latest
env:
PYTHON_VERSION: 3.12
steps:
# Checkout the repository
- uses: actions/checkout@v3
# Set up Python
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
# Install build dependencies
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
# Build the wheel(s)
- name: Build the package
run: python -m build
# upload artifact for debugging
- name: Upload built wheels (optional)
uses: actions/upload-artifact@v4
with:
name: wheels
path: ./dist/*.whl
# Publish wheels to orphan `wheels` branch
- name: Publish wheels to wheels branch
if: github.repository == 'ironArray/Caterva2' # Only push from main repo
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Abort if no wheels were built
if [ -z "$(ls -A ./dist/*.whl 2>/dev/null)" ]; then
echo "No wheels found, skipping push"
exit 0
fi
# Prepare fresh working directory for orphan branch
rm -rf wheels-branch
mkdir wheels-branch
cd wheels-branch
# Initialize git repo and authenticate
git init
git remote add origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
git fetch origin wheels || true
# Create orphan branch (separate history)
git checkout --orphan wheels
git reset --hard
# Copy wheels from main repo build output
mkdir -p wheels
cp ../dist/*.whl wheels/
echo "Wheels to publish:"
ls -lh wheels/
# Generate latest.txt (name of newest wheel)
latest_wheel=$(ls -1 wheels/*.whl | sort | tail -n 1)
echo "$(basename $latest_wheel)" > wheels/latest.txt
echo "Latest wheel: $(cat wheels/latest.txt)"
# Commit and push
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add wheels
git commit -m "Update wheels for commit ${{ github.sha }}"
git push origin wheels --force