Files
shared-actions/.gitea/workflows/python-dependency-outdated.yml
T
LucaZanni 2d5eb0da4b ⬆️ chore(ci): actions/checkout passa alla v7 sui 25 step
- v6 -> v7 su tutti gli step, varianti gitea.com e -github
- il breaking change della v7 (rifiuto del codice di una PR da fork su
  pull_request_target e workflow_run) era gia' backportato in v6.1.0, dove il
  tag flottante v6 puntava: il delta reale e' ESM piu' dipendenze
- la guardia non si attiva comunque: serve un ref o un repository esplicito, e
  qui i checkout sono self-checkout nudi su workflow_call
- action.yml identico fra v6.1.0 e v7.0.1, stesso using node24: nessun
  requisito nuovo sui runner

Fixes #24 @1h30m
2026-10-19 16:19:52 +02:00

150 lines
6.3 KiB
YAML

name: Python Dependency Outdated
on:
workflow_call:
inputs:
python-version:
type: string
default: '3.11'
install-extras:
type: string
default: 'dev'
working-directory:
type: string
default: '.'
extra-index-gitea:
description: >-
Aggiunge il registry PyPI privato di Gitea (PZeta_Touch) come indice extra di pip,
autenticato con i secrets G_USER / NPM_TOKEN (serve 'secrets: inherit').
# Stringa e non boolean: su act_runner i valori boolean passati con with: da un
# workflow chiamante non arrivano al workflow riusabile (resta il default false),
# mentre le stringhe si. Il chiamante scrive extra-index-gitea: 'true'.
type: string
default: 'false'
workflow_dispatch:
jobs:
python-dependency-outdated:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- name: Checkout
uses: https://gitea.com/actions/checkout@v7
- name: Setup Python
uses: https://github.com/actions/setup-python@v7
with:
python-version: ${{ inputs.python-version || '3.11' }}
# Registry PyPI privato di Gitea (#17). Le credenziali vanno in un file netrc e non
# nell'URL: PIP_EXTRA_INDEX_URL resta senza segreti, pip legge utente e token dal file
# indicato da NETRC, e nulla di sensibile passa per l'env esportato o per i log.
# L'input si legge come variabile d'ambiente e non nel campo `if:` dello step: nel
# workflow_call di act_runner i valori `with:` del chiamante non arrivano al contesto
# `inputs` in quella posizione (stesso problema di owns-auth-roles in quality-gates.yml).
- name: Registry PyPI di Gitea
id: pypi-gitea
env:
EXTRA_INDEX_GITEA: ${{ inputs.extra-index-gitea }}
G_USER: ${{ secrets.G_USER }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if ! printf "%s" "$EXTRA_INDEX_GITEA" | grep -qix "true"; then
echo "extra-index-gitea non attivo: solo PyPI pubblico."
exit 0
fi
if [ -z "$G_USER" ] || [ -z "$NPM_TOKEN" ]; then
echo "::error::extra-index-gitea richiede i secrets G_USER e NPM_TOKEN: serve 'secrets: inherit' nel workflow chiamante."
exit 1
fi
NETRC_FILE="$RUNNER_TEMP/pip-gitea.netrc"
( umask 077; printf 'machine gitea.pzetatouch.it\nlogin %s\npassword %s\n' "$G_USER" "$NPM_TOKEN" > "$NETRC_FILE" )
echo "NETRC=$NETRC_FILE" >> "$GITHUB_ENV"
echo "PIP_EXTRA_INDEX_URL=https://gitea.pzetatouch.it/api/packages/PZeta_Touch/pypi/simple/" >> "$GITHUB_ENV"
echo "secret_files=pip_netrc=$NETRC_FILE" >> "$GITHUB_OUTPUT"
echo "Registry PyPI di Gitea aggiunto come indice extra (credenziali da netrc)."
- name: Cache pip
uses: https://github.com/actions/cache@v6
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 (isolated venv)
run: |
# venv pulita: elenca come obsolete SOLO le dipendenze dichiarate dal repo,
# non i pacchetti globali del runner (torch/cuda/nvidia su runner ML/GPU)
python -m venv .audit-venv
.audit-venv/bin/pip install --upgrade pip
if [ -n "${{ inputs.install-extras }}" ]; then
.audit-venv/bin/pip install -e ".[${{ inputs.install-extras }}]"
elif [ -f requirements.txt ]; then
.audit-venv/bin/pip install -r requirements.txt
else
.audit-venv/bin/pip install -e "."
fi
- name: Check outdated packages
id: outdated
run: |
.audit-venv/bin/pip list --outdated --format=json > outdated.json 2>/dev/null || echo '[]' > outdated.json
COUNT=$(python3 -c "import json; print(len(json.load(open('outdated.json'))))")
echo "count=$COUNT" >> $GITHUB_OUTPUT
- name: Open or update issue if packages outdated
if: steps.outdated.outputs.count != '0'
env:
GITEA_TOKEN: ${{ gitea.token }}
SERVER_URL: ${{ gitea.server_url }}
REPOSITORY: ${{ gitea.repository }}
run: |
COUNT="${{ steps.outdated.outputs.count }}"
DATE=$(date '+%Y-%m-%d')
TITLE_PREFIX="Dipendenze Python:"
OUTDATED_LIST=$(python3 -c "
import json
try:
data = json.load(open('outdated.json'))
lines = [f\"- {p['name']}: {p['version']} → {p['latest_version']}\" for p in data[:20]]
print('\n'.join(lines))
except Exception:
print('N/A')
")
printf '## Dipendenze Python Obsolete — %s\n\n### Pacchetti da aggiornare: %s\n\n```\n%s\n```\n' \
"$DATE" "$COUNT" "$OUTDATED_LIST" > /tmp/body.md
# Deduplica: se esiste già una issue aperta con lo stesso prefisso,
# aggiungi un commento invece di aprirne una nuova
EXISTING=$(curl -s \
-H "Authorization: token $GITEA_TOKEN" \
"$SERVER_URL/api/v1/repos/$REPOSITORY/issues?state=open&type=issues&limit=50" \
| jq -r --arg p "$TITLE_PREFIX" '[.[] | select(.title | contains($p))] | (first // {}) | .number // empty')
if [ -n "$EXISTING" ]; then
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Authorization: token $GITEA_TOKEN" \
"$SERVER_URL/api/v1/repos/$REPOSITORY/issues/$EXISTING/comments" \
-d "{ \"body\": $(jq -Rs . /tmp/body.md) }"
else
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Authorization: token $GITEA_TOKEN" \
"$SERVER_URL/api/v1/repos/$REPOSITORY/issues" \
-d "{
\"title\": \"[$DATE] Dipendenze Python: $COUNT pacchetti obsoleti\",
\"body\": $(jq -Rs . /tmp/body.md)
}"
fi
- name: Rimozione credenziali registry PyPI
if: always()
run: rm -f "$RUNNER_TEMP/pip-gitea.netrc"