Skip to content

Commit

Permalink
Build pre-populated Python distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed May 9, 2024
1 parent 0b9de73 commit 6f75795
Show file tree
Hide file tree
Showing 2 changed files with 254 additions and 0 deletions.
131 changes: 131 additions & 0 deletions .github/workflows/build-distributions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: build distributions

on:
push:
branches:
- master
pull_request:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

defaults:
run:
shell: bash

env:
DIST_PYTHON_VERSION: "3.12.3"
DIST_VERSION: "20240415"
DIST_URL: "https://github.com/indygreg/python-build-standalone/releases/download"
PYTHONDONTWRITEBYTECODE: "1"
# Some pip environment variables are weird, this means do not compile
PIP_NO_COMPILE: "0"

jobs:
distributions-linux:
name: ${{ matrix.job.target }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
job:
- image: quay.io/pypa/manylinux2014_x86_64
target: x86_64-unknown-linux-gnu
- image: quay.io/pypa/manylinux_2_28_aarch64
target: aarch64-unknown-linux-gnu
emulation: arm64

steps:
- name: Set up QEMU
if: matrix.job.emulation
uses: docker/setup-qemu-action@v3

- name: Set up Docker container
run: >-
docker run --rm -d
--name builder
--workdir /home
--env PYTHONDONTWRITEBYTECODE
--env PIP_NO_COMPILE
${{ matrix.job.image }}
sleep infinity
- name: Download distribution
run: >-
docker exec builder
curl -LO
${{ env.DIST_URL }}/${{ env.DIST_VERSION }}/cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz
- name: Unpack distribution
run: >-
docker exec builder
tar xzf cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz
- name: Install Hatch
run: >-
docker exec builder
/home/python/bin/python -m pip install hatch
- name: Archive distribution
run: >-
docker exec builder
tar czf ${{ matrix.job.target }}.tar.gz python
- name: Move to host
run: docker cp builder:/home/${{ matrix.job.target }}.tar.gz .

- name: Check original size
run: >-
docker exec builder
ls -lh cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz
- name: Check final size
run: ls -lh ${{ matrix.job.target }}.tar.gz

- name: Upload archive
uses: actions/upload-artifact@v4
with:
name: distribution-${{ matrix.job.target }}
path: ${{ matrix.job.target }}.tar.gz

distributions-windows-macos:
name: ${{ matrix.job.target }}
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- target: x86_64-pc-windows-msvc
os: windows-2019
- target: aarch64-apple-darwin
os: macos-14
- target: x86_64-apple-darwin
os: macos-12

steps:
- name: Download distribution
run: curl -LO ${{ env.DIST_URL }}/${{ env.DIST_VERSION }}/cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz

- name: Unpack distribution
run: tar xzf cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz

- name: Install Hatch
run: ${{ startsWith(matrix.job.os, 'windows-') && '.\\python\\python.exe' || './python/bin/python' }} -m pip install hatch

- name: Archive distribution
run: tar czf ${{ matrix.job.target }}.tar.gz python

- name: Check original size
run: ls -lh cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz

- name: Check final size
run: ls -lh ${{ matrix.job.target }}.tar.gz

- name: Upload archive
uses: actions/upload-artifact@v4
with:
name: distribution-${{ matrix.job.target }}
path: ${{ matrix.job.target }}.tar.gz
123 changes: 123 additions & 0 deletions .github/workflows/build-hatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,121 @@ env:
APP_NAME: hatch
PYTHON_VERSION: "3.11"
PYOXIDIZER_VERSION: "0.24.0"
DIST_VERSION: "20240415"
DIST_PYTHON_VERSION: "3.12.3"
DIST_URL: "https://github.com/indygreg/python-build-standalone/releases/download"

jobs:
distributions-linux:
name: ${{ matrix.job.target }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
job:
- image: quay.io/pypa/manylinux2014_x86_64
target: x86_64-unknown-linux-gnu
- image: quay.io/pypa/manylinux_2_28_aarch64
target: aarch64-unknown-linux-gnu
emulation: arm64

steps:
- name: Set up QEMU
if: matrix.job.emulation
uses: docker/setup-qemu-action@v3

- name: Set up Docker container
run: >-
docker run --rm -d
--name builder
--workdir /home
--env PYTHONDONTWRITEBYTECODE=1
--env PIP_NO_COMPILE=0
${{ matrix.job.image }}
sleep infinity
- name: Download distribution
run: >-
docker exec builder
curl -LO
${{ env.DIST_URL }}/${{ env.DIST_VERSION }}/cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz
- name: Unpack distribution
run: >-
docker exec builder
tar xzf cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz
- name: Install Hatch
run: >-
docker exec builder
/home/python/bin/python -m pip install hatch
- name: Archive distribution
run: >-
docker exec builder
tar czf ${{ matrix.job.target }}.tar.gz python
- name: Move to host
run: docker cp builder:/home/${{ matrix.job.target }}.tar.gz .

- name: Check original size
run: >-
docker exec builder
ls -lh cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz
- name: Check final size
run: ls -lh ${{ matrix.job.target }}.tar.gz

- name: Upload archive
uses: actions/upload-artifact@v4
with:
name: distribution-${{ matrix.job.target }}
path: ${{ matrix.job.target }}.tar.gz

distributions-windows-macos:
name: ${{ matrix.job.target }}
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- target: x86_64-pc-windows-msvc
os: windows-2019
- target: aarch64-apple-darwin
os: macos-14
- target: x86_64-apple-darwin
os: macos-12

env:
PYTHONDONTWRITEBYTECODE: "1"
# Some pip environment variables are weird, this means do not compile
PIP_NO_COMPILE: "0"

steps:
- name: Download distribution
run: curl -LO ${{ env.DIST_URL }}/${{ env.DIST_VERSION }}/cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz

- name: Unpack distribution
run: tar xzf cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz

- name: Install Hatch
run: ${{ startsWith(matrix.job.os, 'windows-') && '.\\python\\python.exe' || './python/bin/python' }} -m pip install hatch

- name: Archive distribution
run: tar czf ${{ matrix.job.target }}.tar.gz python

- name: Check original size
run: ls -lh cpython-${{ env.DIST_PYTHON_VERSION }}+${{ env.DIST_VERSION }}-${{ matrix.job.target }}-install_only.tar.gz

- name: Check final size
run: ls -lh ${{ matrix.job.target }}.tar.gz

- name: Upload archive
uses: actions/upload-artifact@v4
with:
name: distribution-${{ matrix.job.target }}
path: ${{ matrix.job.target }}.tar.gz

python-artifacts:
name: Build wheel and source distribution
runs-on: ubuntu-latest
Expand Down Expand Up @@ -448,6 +561,8 @@ jobs:
- binaries
- windows-packaging
- macos-packaging
- distributions-linux
- distributions-windows-macos
runs-on: ubuntu-latest

permissions:
Expand Down Expand Up @@ -475,12 +590,20 @@ jobs:
path: installers
merge-multiple: true

- name: Download distributions
uses: actions/download-artifact@v4
with:
name: distribution-*
path: distributions
merge-multiple: true

- name: Add assets to current release
uses: softprops/action-gh-release@v2
with:
files: |-
archives/*
installers/*
distributions/*
- name: Push Python artifacts to PyPI
uses: pypa/[email protected]

0 comments on commit 6f75795

Please sign in to comment.