Skip to content

Build and Release Python Binary #7

Build and Release Python Binary

Build and Release Python Binary #7

Workflow file for this run

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
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 checksum file
run: |
sha256sum ${{ env.PACKAGE_NAME }}.tar.gz ${{ env.PACKAGE_NAME }}.zip > 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
draft: false
prerelease: false
files: |
${{ env.PACKAGE_NAME }}.tar.gz
${{ env.PACKAGE_NAME }}.zip
SHA256SUMS.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}