Skip to content

Build Python

Build Python #5

Workflow file for this run

name: Build Python
on:
workflow_dispatch:
schedule:
- cron: "0 0 1 * *"
push:
branches:
- main
- develop
paths:
- 'python/**'
- '.github/workflows/python.yml'
release:
types: [published]
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
jobs:
build:
name: "python:${{ matrix.version }}"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
version:
- "3.7"
- "3.8"
- "3.9"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set lowercase repository owner
id: owner
run: |
echo "value=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Check if Dockerfile exists
id: check
run: |
if [ -f "./python/${{ matrix.version }}/Dockerfile" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Set up QEMU
if: steps.check.outputs.exists == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: steps.check.outputs.exists == 'true'
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
if: steps.check.outputs.exists == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate tags
if: steps.check.outputs.exists == 'true'
id: tags
run: |
OWNER="${{ steps.owner.outputs.value }}"
VERSION="${{ matrix.version }}"
TAGS="${{ env.REGISTRY }}/$OWNER/python:python_$VERSION"
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/python:latest"
elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/python:python_$VERSION-dev"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
REL_TAG="${{ github.ref_name }}"
TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/python:python_$VERSION-$REL_TAG"
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build and push
if: steps.check.outputs.exists == 'true'
uses: docker/build-push-action@v6
with:
context: ./python
file: ./python/${{ matrix.version }}/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max