- python-quality-gates.yml e python-docker-release.yml creano un venv in $RUNNER_TEMP prima dell'install - il toolcache di setup-python è condiviso tra i job del runner: l'install editable di python-wyoming (pacchetto 'wyoming') sopravviveva alla sua workspace e pip lo dava per soddisfatto negli altri repository - sblocca la CI e la release di python-wyoming-piper (ModuleNotFoundError: No module named 'wyoming') Fixes #undefined @1h
133 lines
4.7 KiB
YAML
133 lines
4.7 KiB
YAML
name: Python Docker Release
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
python-version:
|
|
type: string
|
|
default: '3.11'
|
|
install-extras:
|
|
description: 'Extras pip da installare (es: dev, test)'
|
|
type: string
|
|
default: 'dev'
|
|
runner:
|
|
type: string
|
|
default: 'catthehacker-latest'
|
|
working-directory:
|
|
description: 'Directory di lavoro se il progetto non è in root'
|
|
type: string
|
|
default: '.'
|
|
dockerfile:
|
|
description: 'Path al Dockerfile'
|
|
type: string
|
|
default: './Dockerfile'
|
|
|
|
jobs:
|
|
python-docker-release:
|
|
runs-on: ${{ inputs.runner }}
|
|
defaults:
|
|
run:
|
|
working-directory: ${{ inputs.working-directory }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: https://gitea.com/actions/checkout@v6
|
|
|
|
- name: Setup Python
|
|
uses: https://github.com/actions/setup-python@v5.2.0
|
|
with:
|
|
python-version: ${{ inputs.python-version || '3.11' }}
|
|
|
|
# Il toolcache di setup-python è condiviso tra i job dello stesso runner: un
|
|
# 'pip install -e .' fatto lì da un altro repository (es. python-wyoming, che
|
|
# pubblica il pacchetto 'wyoming') sopravvive alla cancellazione della sua
|
|
# workspace e lascia un'installazione editable rotta che pip considera già
|
|
# soddisfatta. Ogni job installa quindi in un virtualenv proprio.
|
|
- name: Virtualenv isolato
|
|
run: |
|
|
python -m venv "$RUNNER_TEMP/venv"
|
|
echo "$RUNNER_TEMP/venv/bin" >> "$GITHUB_PATH"
|
|
echo "VIRTUAL_ENV=$RUNNER_TEMP/venv" >> "$GITHUB_ENV"
|
|
|
|
- name: Cache pip
|
|
uses: https://github.com/actions/cache@v4
|
|
with:
|
|
path: ~/.cache/pip
|
|
key: ${{ runner.os }}-pip-${{ inputs.python-version }}-${{ hashFiles('**/pyproject.toml', '**/requirements*.txt') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pip-${{ inputs.python-version }}-
|
|
${{ runner.os }}-pip-
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
if [ -n "${{ inputs.install-extras }}" ]; then
|
|
pip install -e ".[${{ inputs.install-extras }}]"
|
|
elif [ -f requirements-dev.txt ]; then
|
|
pip install -r requirements-dev.txt
|
|
elif [ -f requirements.txt ]; then
|
|
pip install -r requirements.txt
|
|
else
|
|
pip install -e "."
|
|
fi
|
|
|
|
- name: Lint (ruff)
|
|
run: ruff check .
|
|
|
|
- name: Format check (ruff)
|
|
run: ruff format --check .
|
|
|
|
- name: Type check (mypy)
|
|
run: mypy .
|
|
|
|
- name: Test (pytest)
|
|
run: pytest --tb=short -q
|
|
|
|
- name: Login to container registry
|
|
uses: https://gitea.com/docker/login-action@v4
|
|
with:
|
|
registry: gitea.pzetatouch.it
|
|
username: ${{ secrets.G_USER }}
|
|
password: ${{ secrets.NPM_TOKEN }}
|
|
|
|
- name: Determine image tags
|
|
id: tags
|
|
run: |
|
|
APP_NAME=$(python -c "
|
|
import tomllib, pathlib
|
|
data = tomllib.loads(pathlib.Path('pyproject.toml').read_text())
|
|
print(data['project']['name'])
|
|
" 2>/dev/null || python3 -c "
|
|
import re, pathlib
|
|
content = pathlib.Path('pyproject.toml').read_text()
|
|
m = re.search(r'^name\s*=\s*[\"\'](.*?)[\"\']', content, re.MULTILINE)
|
|
print(m.group(1) if m else 'unknown')
|
|
")
|
|
VERSION=$(python -c "
|
|
import tomllib, pathlib
|
|
data = tomllib.loads(pathlib.Path('pyproject.toml').read_text())
|
|
print(data['project']['version'])
|
|
" 2>/dev/null || python3 -c "
|
|
import re, pathlib
|
|
content = pathlib.Path('pyproject.toml').read_text()
|
|
m = re.search(r'^version\s*=\s*[\"\'](.*?)[\"\']', content, re.MULTILINE)
|
|
print(m.group(1) if m else '0.0.0')
|
|
")
|
|
REGISTRY="gitea.pzetatouch.it/pzeta_touch"
|
|
echo "version_tag=${REGISTRY}/${APP_NAME}:${VERSION}" >> $GITHUB_OUTPUT
|
|
echo "latest_tag=${REGISTRY}/${APP_NAME}:latest" >> $GITHUB_OUTPUT
|
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and push Docker image
|
|
uses: https://gitea.com/docker/build-push-action@v6
|
|
with:
|
|
push: true
|
|
context: ${{ inputs.working-directory }}
|
|
file: ${{ inputs.dockerfile }}
|
|
tags: |
|
|
${{ steps.tags.outputs.version_tag }}
|
|
${{ steps.tags.outputs.latest_tag }}
|
|
labels: |
|
|
org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}
|
|
org.opencontainers.image.revision=${{ gitea.sha }}
|
|
org.opencontainers.image.version=${{ steps.tags.outputs.version }}
|