-
Notifications
You must be signed in to change notification settings - Fork 2
120 lines (103 loc) · 3.82 KB
/
python-wheel.yml
File metadata and controls
120 lines (103 loc) · 3.82 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Build and Publish Python Wheels for Caterva2
on:
push:
branches:
- main # Rebuild wheels on every commit to main
workflow_dispatch:
inputs:
channel:
description: "Wheel channel to publish"
required: true
default: "staging"
type: choice
options:
- staging
- production
permissions:
contents: write # Needed for GITHUB_TOKEN to push
jobs:
build_wheels:
runs-on: ubuntu-latest
env:
PYTHON_VERSION: 3.12
PUBLISH_CHANNEL: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.channel || 'production' }}
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-${{ env.PUBLISH_CHANNEL }}
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: |
set -eu
# 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
channel="${PUBLISH_CHANNEL}"
if [ "$channel" = "production" ]; then
channel_dir="wheels"
else
channel_dir="wheels-staging"
fi
echo "Publishing channel: $channel"
echo "Target directory: $channel_dir"
# Prepare working directory for the published 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
# Reuse the existing published branch when present so multiple channels can coexist
if git ls-remote --exit-code --heads origin wheels >/dev/null 2>&1; then
git checkout -B wheels origin/wheels
else
git checkout --orphan wheels
git reset --hard
fi
# Replace only the selected channel contents
mkdir -p "$channel_dir"
find "$channel_dir" -maxdepth 1 -type f -name '*.whl' -delete
cp ../dist/*.whl "$channel_dir"/
echo "Wheels to publish:"
ls -lh "$channel_dir"/
# Generate latest.txt (name of newest wheel)
latest_wheel=$(ls -1 "$channel_dir"/*.whl | sort | tail -n 1)
echo "$(basename "$latest_wheel")" > "$channel_dir/latest.txt"
echo "${{ github.sha }}" > "$channel_dir/commit.txt"
echo "${{ github.ref_name }}" > "$channel_dir/ref.txt"
echo "$channel" > "$channel_dir/channel.txt"
echo "Latest wheel: $(cat "$channel_dir/latest.txt")"
# Commit and push
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add "$channel_dir"
if git diff --cached --quiet; then
echo "No changes to publish"
exit 0
fi
git commit -m "Update ${channel} wheels for commit ${{ github.sha }}"
git push origin wheels --force