-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (126 loc) · 6.46 KB
/
build.yml
File metadata and controls
154 lines (126 loc) · 6.46 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Build and Release Python Binary
on:
workflow_dispatch:
inputs:
python_version:
description: 'Python version to build (e.g., 3.9.18, 3.10.13, 3.11.7)'
required: true
default: '3.11.7'
jobs:
build-python:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set architecture and build date
run: |
echo "RELEASE_TAG=python-${{ github.event.inputs.python_version }}-linux" >> $GITHUB_ENV
echo "BUILD_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
echo "ARCHITECTURE=$(uname -m)" >> $GITHUB_ENV
- name: Cache apt packages
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: build-essential gdb lcov pkg-config libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev lzma lzma-dev tk-dev uuid-dev zlib1g-dev wget curl llvm make dpkg-deb fakeroot
version: 1.0
- name: Download Python source
run: |
wget https://www.python.org/ftp/python/${{ github.event.inputs.python_version }}/Python-${{ github.event.inputs.python_version }}.tgz
tar xzf Python-${{ github.event.inputs.python_version }}.tgz
- name: Prepare build directory
run: |
mkdir -p python_install
INSTALL_PATH=$(pwd)/python_install
- name: Configure and build Python
run: |
cd Python-${{ github.event.inputs.python_version }}
# Set optimization flags (using level 2 by default)
OPT_FLAGS="--enable-optimizations --with-lto"
# Configure Python build
INSTALL_PATH=$(pwd)/../python_install
./configure --prefix=$INSTALL_PATH $OPT_FLAGS
# Build and install
make -j$(nproc)
make install
# Fix any remaining shebang issues
PY_VERSION=$(echo ${{ github.event.inputs.python_version }} | cut -d. -f1,2)
find "$INSTALL_PATH/bin" -type f -not -name "python*" -exec sed -i '1s|^#!.*/bin/python[0-9.]*|#!/usr/bin/env python'$PY_VERSION'|' {} \;
- name: Remove unnecessary files
run: |
# Remove tests
find python_install -type d -name "test" -o -name "tests" | xargs rm -rf
find python_install -type d -name "__pycache__" | xargs rm -rf
# Remove idle and other GUI tools if not needed
rm -f python_install/bin/idle*
- name: Create binary archives
run: |
PACKAGE_NAME="python-${{ github.event.inputs.python_version }}-linux-$(uname -m)"
# Create tarball
tar -czvf $PACKAGE_NAME.tar.gz -C python_install .
# Create zip file
cd python_install
zip -r ../$PACKAGE_NAME.zip .
cd ..
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
- name: Create deb package
run: |
PACKAGE_NAME="python-${{ github.event.inputs.python_version }}-linux-$(uname -m)"
PY_VERSION="${{ github.event.inputs.python_version }}"
PY_MAJOR_MINOR=$(echo $PY_VERSION | cut -d. -f1,2)
# Create deb package structure
mkdir -p deb_package/DEBIAN
mkdir -p deb_package/opt/python-$PY_VERSION
# Copy Python installation to deb package structure
cp -r python_install/* deb_package/opt/python-$PY_VERSION/
# Create DEBIAN control file
INSTALLED_SIZE=$(du -sk deb_package/opt | cut -f1)
echo "Package: python${PY_MAJOR_MINOR}-custom" > deb_package/DEBIAN/control
echo "Version: $PY_VERSION" >> deb_package/DEBIAN/control
echo "Section: interpreters" >> deb_package/DEBIAN/control
echo "Priority: optional" >> deb_package/DEBIAN/control
echo "Architecture: amd64" >> deb_package/DEBIAN/control
echo "Installed-Size: $INSTALLED_SIZE" >> deb_package/DEBIAN/control
echo "Depends: libc6 (>= 2.17), libssl3 | libssl1.1, zlib1g, libbz2-1.0, libffi8 | libffi7 | libffi6, libgdbm6 | libgdbm5, liblzma5, libncurses6 | libncurses5, libreadline8 | libreadline7 | libreadline6, libsqlite3-0, uuid-runtime" >> deb_package/DEBIAN/control
echo "Maintainer: anubhavkrishna1 <[email protected]>" >> deb_package/DEBIAN/control
echo "Description: Custom Python $PY_VERSION interpreter" >> deb_package/DEBIAN/control
echo " This package provides a custom-built Python $PY_VERSION interpreter" >> deb_package/DEBIAN/control
echo " with optimizations enabled. Built from source with LTO and PGO" >> deb_package/DEBIAN/control
echo " optimizations for better performance." >> deb_package/DEBIAN/control
echo " ." >> deb_package/DEBIAN/control
echo " The Python installation is located in /opt/python-$PY_VERSION/" >> deb_package/DEBIAN/control
echo " and includes pip, setuptools, and wheel." >> deb_package/DEBIAN/control
# Build deb package
fakeroot dpkg-deb --build deb_package $PACKAGE_NAME.deb
- name: Create checksum file
run: |
sha256sum ${{ env.PACKAGE_NAME }}.tar.gz ${{ env.PACKAGE_NAME }}.zip ${{ env.PACKAGE_NAME }}.deb > SHA256SUMS.txt
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.RELEASE_TAG }}
name: Python ${{ github.event.inputs.python_version }} Linux Binary
body: |
Custom Python ${{ github.event.inputs.python_version }} binary build for Linux
**Build Configuration:**
- Python Version: ${{ github.event.inputs.python_version }}
- Optimization Level: 2 (full optimizations with LTO)
- With Pip/Setuptools/Wheel: Yes
- Architecture: ${{ env.ARCHITECTURE }}
- Build Date: ${{ env.BUILD_DATE }}
- Built by: anubhavkrishna1
**Available Formats:**
- `.tar.gz` - Extract to any directory
- `.zip` - Extract to any directory
- `.deb` - Debian/Ubuntu package (installs to /opt/python-${{ github.event.inputs.python_version }}/)
**Installation:**
- **Debian/Ubuntu**: `sudo dpkg -i ${{ env.PACKAGE_NAME }}.deb`
- **Manual**: Extract tar.gz or zip to desired location
draft: false
prerelease: false
files: |
${{ env.PACKAGE_NAME }}.tar.gz
${{ env.PACKAGE_NAME }}.zip
${{ env.PACKAGE_NAME }}.deb
SHA256SUMS.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}