✨ feat(ci): workflow Python con registry PyPI privato di Gitea
- 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
This commit is contained in:
1 parent
195407f04c
commit
4b2d986929
4 files changed
+125
No files matched your search
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
Reference in new issue
Block a user