Skip to content

Commit 7126624

Browse files
Create build.yml
1 parent be51cd0 commit 7126624

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed

.github/workflow/build.yml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
name: Build and Release Python Binary
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
python_version:
7+
description: 'Python version to build (e.g., 3.9.18, 3.10.13, 3.11.7)'
8+
required: true
9+
default: '3.11.12'
10+
11+
jobs:
12+
build-python:
13+
runs-on: ubuntu-20.04
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Set release tag
19+
run: |
20+
echo "RELEASE_TAG=python-${{ github.event.inputs.python_version }}-linux" >> $GITHUB_ENV
21+
22+
- name: Install build dependencies
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
26+
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
27+
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev \
28+
libgdbm-dev libgdbm-compat-dev uuid-dev
29+
30+
- name: Download Python source
31+
run: |
32+
wget https://www.python.org/ftp/python/${{ github.event.inputs.python_version }}/Python-${{ github.event.inputs.python_version }}.tgz
33+
tar xzf Python-${{ github.event.inputs.python_version }}.tgz
34+
35+
- name: Prepare build directory
36+
run: |
37+
mkdir -p python_install
38+
INSTALL_PATH=$(pwd)/python_install
39+
40+
- name: Configure and build Python
41+
run: |
42+
cd Python-${{ github.event.inputs.python_version }}
43+
44+
# Set optimization flags (using level 2 by default)
45+
OPT_FLAGS="--enable-optimizations --with-lto"
46+
47+
# Configure Python build
48+
INSTALL_PATH=$(pwd)/../python_install
49+
./configure --prefix=$INSTALL_PATH $OPT_FLAGS
50+
51+
# Build and install
52+
make -j$(nproc)
53+
make install
54+
55+
- name: Create binary archives
56+
run: |
57+
PACKAGE_NAME="python-${{ github.event.inputs.python_version }}-linux-$(uname -m)"
58+
59+
# Create tarball
60+
tar -czvf $PACKAGE_NAME.tar.gz -C python_install .
61+
62+
# Create zip file
63+
cd python_install
64+
zip -r ../$PACKAGE_NAME.zip .
65+
cd ..
66+
67+
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
68+
69+
- name: Create installation script
70+
run: |
71+
cat > install.sh << 'EOF'
72+
#!/bin/bash
73+
# Python binary installation script
74+
75+
# Default installation directory
76+
DEFAULT_INSTALL_DIR="/opt/python-${{ github.event.inputs.python_version }}"
77+
INSTALL_DIR=${1:-$DEFAULT_INSTALL_DIR}
78+
79+
# Check if run as root
80+
if [ "$(id -u)" -ne 0 ]; then
81+
echo "This script must be run as root to install to system directories."
82+
echo "Usage: sudo ./install.sh [INSTALL_DIR]"
83+
exit 1
84+
fi
85+
86+
echo "Installing Python ${{ github.event.inputs.python_version }} to $INSTALL_DIR..."
87+
88+
# Create installation directory
89+
mkdir -p "$INSTALL_DIR"
90+
91+
# Extract files
92+
if [ -f "$(dirname "$0")/${{ env.PACKAGE_NAME }}.tar.gz" ]; then
93+
tar -xzf "$(dirname "$0")/${{ env.PACKAGE_NAME }}.tar.gz" -C "$INSTALL_DIR"
94+
elif [ -f "$(dirname "$0")/${{ env.PACKAGE_NAME }}.zip" ]; then
95+
unzip "$(dirname "$0")/${{ env.PACKAGE_NAME }}.zip" -d "$INSTALL_DIR"
96+
else
97+
echo "Error: Neither tar.gz nor zip archive found!"
98+
exit 1
99+
fi
100+
101+
# Create symlinks in /usr/local/bin
102+
echo "Creating symlinks in /usr/local/bin..."
103+
ln -sf "$INSTALL_DIR/bin/python3" /usr/local/bin/python${{ github.event.inputs.python_version }}
104+
ln -sf "$INSTALL_DIR/bin/pip3" /usr/local/bin/pip${{ github.event.inputs.python_version }}
105+
106+
echo "Python ${{ github.event.inputs.python_version }} has been installed successfully!"
107+
echo "You can use it with: python${{ github.event.inputs.python_version }}"
108+
EOF
109+
110+
chmod +x install.sh
111+
112+
- name: Create checksum file
113+
run: |
114+
sha256sum ${{ env.PACKAGE_NAME }}.tar.gz ${{ env.PACKAGE_NAME }}.zip install.sh > SHA256SUMS.txt
115+
116+
- name: Create Release
117+
id: create_release
118+
uses: softprops/action-gh-release@v1
119+
with:
120+
tag_name: ${{ env.RELEASE_TAG }}
121+
name: Python ${{ github.event.inputs.python_version }} Linux Binary
122+
body: |
123+
Custom Python ${{ github.event.inputs.python_version }} binary build for Linux
124+
125+
**Build Configuration:**
126+
- Python Version: ${{ github.event.inputs.python_version }}
127+
- Optimization Level: 2 (full optimizations with LTO)
128+
- With Pip/Setuptools/Wheel: Yes
129+
- Architecture: $(uname -m)
130+
- Build Date: 2025-04-16 14:06:18
131+
- Built by: anubhavkrishna1
132+
133+
**Installation Instructions:**
134+
```bash
135+
# Download the release files (choose either tar.gz or zip)
136+
wget https://github.com/${{ github.repository }}/releases/download/${{ env.RELEASE_TAG }}/${{ env.PACKAGE_NAME }}.tar.gz
137+
# OR
138+
wget https://github.com/${{ github.repository }}/releases/download/${{ env.RELEASE_TAG }}/${{ env.PACKAGE_NAME }}.zip
139+
140+
# Download the installation script
141+
wget https://github.com/${{ github.repository }}/releases/download/${{ env.RELEASE_TAG }}/install.sh
142+
143+
# Verify checksums
144+
wget https://github.com/${{ github.repository }}/releases/download/${{ env.RELEASE_TAG }}/SHA256SUMS.txt
145+
sha256sum -c SHA256SUMS.txt
146+
147+
# Install (system-wide)
148+
sudo bash install.sh
149+
150+
# Or install to custom location
151+
sudo bash install.sh /path/to/custom/location
152+
```
153+
draft: false
154+
prerelease: false
155+
files: |
156+
${{ env.PACKAGE_NAME }}.tar.gz
157+
${{ env.PACKAGE_NAME }}.zip
158+
install.sh
159+
SHA256SUMS.txt
160+
env:
161+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)