name: Python Quality Gates on: workflow_call: inputs: python-version: type: string default: '3.11' install-extras: description: 'Extras pip da installare (es: dev, test). Lasciare vuoto per solo requirements.txt' type: string default: 'dev' working-directory: description: 'Directory di lavoro se il progetto non è in root' 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' jobs: python-quality-gates: runs-on: ubuntu-latest # Il chiamante non puo' dichiararlo: su un job che usa un workflow # riusabile timeout-minutes non e' una chiave ammessa (devops/shared-actions#23). timeout-minutes: 30 defaults: run: working-directory: ${{ inputs.working-directory }} steps: - name: Checkout timeout-minutes: 10 uses: https://gitea.pzetatouch.it/actions/checkout@v7 - name: Setup Python timeout-minutes: 10 uses: https://gitea.pzetatouch.it/actions/setup-python@v7 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" # 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 timeout-minutes: 10 uses: https://gitea.pzetatouch.it/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 timeout-minutes: 15 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) timeout-minutes: 20 run: pytest --tb=short -q - name: Rimozione credenziali registry PyPI if: always() run: rm -f "$RUNNER_TEMP/pip-gitea.netrc"