From 4b2d9869296b7ae71e2f2406794eb7268b640742 Mon Sep 17 00:00:00 2001 From: LucaZanni Date: Fri, 2 Oct 2026 02:04:44 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(ci):=20workflow=20Python=20con?= =?UTF-8?q?=20registry=20PyPI=20privato=20di=20Gitea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - nuovo input opzionale extra-index-gitea (default false, retrocompatibile) in python-quality-gates, python-docker-release, python-dependency-check e python-dependency-outdated - le credenziali G_USER / NPM_TOKEN finiscono in un netrc 600 in $RUNNER_TEMP (NETRC): PIP_EXTRA_INDEX_URL resta senza segreti, niente token nell'env o nei log - python-docker-release passa lo stesso file a BuildKit come secret pip_netrc (secret-files), da montare con RUN --mount=type=secret: il token non entra negli strati dell'immagine - il netrc viene rimosso a fine job (always) Fixes #17 @1h30m --- .gitea/workflows/python-dependency-check.yml | 30 ++++++++++++++++ .../workflows/python-dependency-outdated.yml | 30 ++++++++++++++++ .gitea/workflows/python-docker-release.yml | 35 +++++++++++++++++++ .gitea/workflows/python-quality-gates.yml | 30 ++++++++++++++++ 4 files changed, 125 insertions(+) diff --git a/.gitea/workflows/python-dependency-check.yml b/.gitea/workflows/python-dependency-check.yml index 97f0e74..0cc76c5 100644 --- a/.gitea/workflows/python-dependency-check.yml +++ b/.gitea/workflows/python-dependency-check.yml @@ -12,6 +12,12 @@ on: 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'). + type: boolean + default: false workflow_dispatch: jobs: @@ -29,6 +35,26 @@ jobs: 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. + - name: Registry PyPI di Gitea + id: pypi-gitea + if: ${{ inputs.extra-index-gitea }} + env: + G_USER: ${{ secrets.G_USER }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + 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 "netrc=$NETRC_FILE" >> "$GITHUB_OUTPUT" + - name: Cache pip uses: https://github.com/actions/cache@v4 with: @@ -118,3 +144,7 @@ jobs: \"body\": $(jq -Rs . /tmp/body.md) }" fi + + - name: Rimozione credenziali registry PyPI + if: ${{ always() && inputs.extra-index-gitea }} + run: rm -f "$RUNNER_TEMP/pip-gitea.netrc" diff --git a/.gitea/workflows/python-dependency-outdated.yml b/.gitea/workflows/python-dependency-outdated.yml index afc0828..5fc7eb0 100644 --- a/.gitea/workflows/python-dependency-outdated.yml +++ b/.gitea/workflows/python-dependency-outdated.yml @@ -12,6 +12,12 @@ on: 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'). + type: boolean + default: false workflow_dispatch: jobs: @@ -29,6 +35,26 @@ jobs: 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. + - name: Registry PyPI di Gitea + id: pypi-gitea + if: ${{ inputs.extra-index-gitea }} + env: + G_USER: ${{ secrets.G_USER }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + 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 "netrc=$NETRC_FILE" >> "$GITHUB_OUTPUT" + - name: Cache pip uses: https://github.com/actions/cache@v4 with: @@ -106,3 +132,7 @@ jobs: \"body\": $(jq -Rs . /tmp/body.md) }" fi + + - name: Rimozione credenziali registry PyPI + if: ${{ always() && inputs.extra-index-gitea }} + run: rm -f "$RUNNER_TEMP/pip-gitea.netrc" diff --git a/.gitea/workflows/python-docker-release.yml b/.gitea/workflows/python-docker-release.yml index c548a08..6fb5bcb 100644 --- a/.gitea/workflows/python-docker-release.yml +++ b/.gitea/workflows/python-docker-release.yml @@ -17,6 +17,12 @@ on: 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'). + type: boolean + default: false dockerfile: description: 'Path al Dockerfile' type: string @@ -48,6 +54,26 @@ jobs: 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. + - name: Registry PyPI di Gitea + id: pypi-gitea + if: ${{ inputs.extra-index-gitea }} + env: + G_USER: ${{ secrets.G_USER }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + 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 "netrc=$NETRC_FILE" >> "$GITHUB_OUTPUT" + - name: Cache pip uses: https://github.com/actions/cache@v4 with: @@ -130,3 +156,12 @@ jobs: org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }} org.opencontainers.image.revision=${{ gitea.sha }} org.opencontainers.image.version=${{ steps.tags.outputs.version }} + # Con extra-index-gitea il netrc arriva a BuildKit come secret 'pip_netrc' (#17): il + # Dockerfile lo monta solo per la durata del RUN che installa + # RUN --mount=type=secret,id=pip_netrc,target=/root/.netrc pip install ... + # e il token non entra negli strati dell'immagine. Vuoto se l'input non e' attivo. + secret-files: ${{ inputs.extra-index-gitea && format('pip_netrc={0}', steps.pypi-gitea.outputs.netrc) || '' }} + + - name: Rimozione credenziali registry PyPI + if: ${{ always() && inputs.extra-index-gitea }} + run: rm -f "$RUNNER_TEMP/pip-gitea.netrc" diff --git a/.gitea/workflows/python-quality-gates.yml b/.gitea/workflows/python-quality-gates.yml index 9282afb..75bb210 100644 --- a/.gitea/workflows/python-quality-gates.yml +++ b/.gitea/workflows/python-quality-gates.yml @@ -14,6 +14,12 @@ on: 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'). + type: boolean + default: false jobs: python-quality-gates: @@ -41,6 +47,26 @@ jobs: 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. + - name: Registry PyPI di Gitea + id: pypi-gitea + if: ${{ inputs.extra-index-gitea }} + env: + G_USER: ${{ secrets.G_USER }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + 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 "netrc=$NETRC_FILE" >> "$GITHUB_OUTPUT" + - name: Cache pip uses: https://github.com/actions/cache@v4 with: @@ -74,3 +100,7 @@ jobs: - name: Test (pytest) run: pytest --tb=short -q + + - name: Rimozione credenziali registry PyPI + if: ${{ always() && inputs.extra-index-gitea }} + run: rm -f "$RUNNER_TEMP/pip-gitea.netrc"