-
Notifications
You must be signed in to change notification settings - Fork 2
87 lines (71 loc) · 2.52 KB
/
python-wheel.yml
File metadata and controls
87 lines (71 loc) · 2.52 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
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