|
1 | | - |
2 | | -name: Python wheel |
| 1 | +name: Build and Publish Python Wheels for Caterva2 |
3 | 2 |
|
4 | 3 | on: |
5 | 4 | push: |
6 | | - branches: [ "main" ] |
7 | | - pull_request: |
8 | | - branches: [ "main" ] |
| 5 | + branches: |
| 6 | + - main # Rebuild wheels on every commit to main |
9 | 7 |
|
10 | 8 | permissions: |
11 | | - contents: read |
| 9 | + contents: write # Needed for GITHUB_TOKEN to push |
12 | 10 |
|
13 | 11 | jobs: |
14 | | - build: |
15 | | - |
| 12 | + build_wheels: |
16 | 13 | runs-on: ubuntu-latest |
| 14 | + env: |
| 15 | + PYTHON_VERSION: 3.12 |
17 | 16 |
|
18 | 17 | steps: |
19 | | - - uses: actions/checkout@v3 |
20 | | - - name: Set up Python |
21 | | - uses: actions/setup-python@v3 |
22 | | - with: |
23 | | - python-version: '3.12' |
24 | | - - name: Install dependencies |
25 | | - run: | |
26 | | - python -m pip install --upgrade pip |
27 | | - pip install build |
28 | | - - name: Build package |
29 | | - run: python -m build |
| 18 | + # Checkout the repository |
| 19 | + - uses: actions/checkout@v3 |
| 20 | + |
| 21 | + # Set up Python |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v3 |
| 24 | + with: |
| 25 | + python-version: ${{ env.PYTHON_VERSION }} |
| 26 | + |
| 27 | + # Install build dependencies |
| 28 | + - name: Install build dependencies |
| 29 | + run: | |
| 30 | + python -m pip install --upgrade pip |
| 31 | + pip install build |
30 | 32 |
|
31 | | - - name: Upload artifact |
32 | | - uses: actions/upload-artifact@v4 |
33 | | - with: |
34 | | - name: wheel |
35 | | - path: ./dist/*.whl |
| 33 | + # Build the wheel(s) |
| 34 | + - name: Build the package |
| 35 | + run: python -m build |
36 | 36 |
|
37 | | - - name: Publish wheels to orphan `wheels` branch |
38 | | - env: |
39 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
40 | | - run: | |
| 37 | + # upload artifact for debugging |
| 38 | + - name: Upload built wheels (optional) |
| 39 | + uses: actions/upload-artifact@v4 |
| 40 | + with: |
| 41 | + name: wheels |
| 42 | + path: ./dist/*.whl |
41 | 43 |
|
42 | | - # Create a fresh working directory |
43 | | - rm -rf wheels-branch |
44 | | - mkdir wheels-branch |
45 | | - cd wheels-branch |
| 44 | + # Publish wheels to orphan `wheels` branch |
| 45 | + - name: Publish wheels to wheels branch |
| 46 | + if: github.repository == 'ironArray/Caterva2' # Only push from main repo |
| 47 | + env: |
| 48 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + run: | |
| 50 | + # Abort if no wheels were built |
| 51 | + if [ -z "$(ls -A ./dist/*.whl 2>/dev/null)" ]; then |
| 52 | + echo "No wheels found, skipping push" |
| 53 | + exit 0 |
| 54 | + fi |
46 | 55 |
|
47 | | - # Initialize git repo |
48 | | - git init |
49 | | - git remote add origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git |
50 | | - git fetch origin wheels || true |
| 56 | + # Prepare fresh working directory for orphan branch |
| 57 | + rm -rf wheels-branch |
| 58 | + mkdir wheels-branch |
| 59 | + cd wheels-branch |
51 | 60 |
|
52 | | - # Create orphan branch |
53 | | - git checkout --orphan wheels |
54 | | - git reset --hard |
| 61 | + # Initialize git repo and authenticate |
| 62 | + git init |
| 63 | + git remote add origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git |
| 64 | + git fetch origin wheels || true |
55 | 65 |
|
56 | | - # Copy wheels |
57 | | - mkdir -p wheels |
58 | | - cp ../dist/*.whl wheels/ |
59 | | - echo "Wheels to publish:" |
60 | | - ls -lh wheels/ |
| 66 | + # Create orphan branch (separate history) |
| 67 | + git checkout --orphan wheels |
| 68 | + git reset --hard |
61 | 69 |
|
62 | | - # Commit |
63 | | - git config user.name "GitHub Actions" |
64 | | - git config user.email "actions@github.com" |
65 | | - git add wheels |
66 | | - git commit -m "Update wheels for release ${{ github.ref_name }}" |
| 70 | + # Copy wheels from main repo build output |
| 71 | + mkdir -p wheels |
| 72 | + cp ../dist/*.whl wheels/ |
| 73 | + echo "Wheels to publish:" |
| 74 | + ls -lh wheels/ |
67 | 75 |
|
68 | | - # Force push |
69 | | - git push origin wheels --force |
| 76 | + # Commit and push |
| 77 | + git config user.name "GitHub Actions" |
| 78 | + git config user.email "actions@github.com" |
| 79 | + git add wheels |
| 80 | + git commit -m "Update wheels for commit ${{ github.sha }}" |
| 81 | + git push origin wheels --force |
0 commit comments