Skip to content

build(python)

build(python) #116

Workflow file for this run

name: build(python)
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
types:
- opened
- synchronize
- reopened
paths:
- 'python/**'
push:
branches:
- main
paths:
- 'python/**'
workflow_dispatch:
schedule:
- cron: '0 0 3 * *'
jobs:
python:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
name: ['python']
suite: ['trixie', 'slim-trixie', 'alpine3.21', 'alpine3.22']
version: ['3.10', '3.11', '3.12', '3.13', '3.14']
latest_version: ['3.14']
steps:
- name: Checkout ${{ matrix.name }}
uses: actions/checkout@v5
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get Version
run: |
echo "build=true" >> $GITHUB_ENV
if [ ! -f "${{ matrix.name }}/${{ matrix.version }}/${{ matrix.suite }}/Dockerfile" ]; then
echo "build=false" >> $GITHUB_ENV
exit 0
fi
full_version=$(grep -m1 -oP "ENV PYTHON_VERSION \K.*" ${{ matrix.name }}/${{ matrix.version }}/${{ matrix.suite }}/Dockerfile)
echo "full_version=${full_version}" >> $GITHUB_ENV
version=${{ matrix.version }}
image_tag=${version}
full_image_tag=${full_version}
if echo ${{ matrix.suite }} | grep -q 'alpine'; then
image_tag=${version}-${{ matrix.suite }}
full_image_tag=${full_version}-${{ matrix.suite }}
fi
if echo ${{ matrix.suite }} | grep -q 'slim'; then
image_tag=${version}-slim
full_image_tag=${full_version}-slim
fi
echo "image_tag=${image_tag}" >> $GITHUB_ENV
echo "full_image_tag=${full_image_tag}" >> $GITHUB_ENV
- name: Build and push image
if: env.build == 'true'
uses: docker/build-push-action@v6
with:
context: ${{ matrix.name }}/${{ matrix.version }}/${{ matrix.suite }}/
platforms: linux/loong64
push: ${{ github.event_name != 'pull_request' }}
tags: |
ghcr.io/${{ github.repository_owner }}/${{ matrix.name }}:${{ env.full_version }}-${{ matrix.suite }}-loong64
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Prepare configuration
run: |
wget -qO- https://github.com/google/go-containerregistry/releases/latest/download/go-containerregistry_Linux_x86_64.tar.gz | sudo tar -xzf - -C /usr/local/bin/ crane
sudo chmod +x /usr/local/bin/crane
sudo chown root:root /usr/local/bin/crane
- name: Pull and Push Images
if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
run: |
full_version="${{ env.full_version }}"
minor_version=$(echo "$full_version" | cut -d'.' -f1-2)
major_version=$(echo "$full_version" | cut -d'.' -f1)
repo="ghcr.io/${{ github.repository_owner }}/python"
suite="${{ matrix.suite }}"
version="${{ matrix.version }}"
latest_version="${{ matrix.latest_version }}"
crane index append -t "$repo:$full_version-$suite" \
-m "$repo:$full_version-$suite-loong64" \
-m "python:$full_version-$suite"
crane cp "$repo:$full_version-$suite" "$repo:$minor_version-$suite"
crane cp "$repo:$full_version-$suite" "$repo:$major_version-$suite"
case "$suite" in
trixie)
if [ "$version" = "$latest_version" ]; then
crane cp "$repo:$version-$suite" "$repo:latest"
crane cp "$repo:$version-$suite" "$repo:$major_version"
fi
;;
alpine3.22)
crane cp "$repo:$full_version-$suite" "$repo:$full_version-alpine"
crane cp "$repo:$full_version-$suite" "$repo:$minor_version-alpine"
if [ "$version" = "$latest_version" ]; then
crane cp "$repo:$full_version-$suite" "$repo:$major_version-alpine"
crane cp "$repo:$full_version-$suite" "$repo:alpine"
fi
;;
*)
echo "No push actions for suite: $suite"
;;
esac