Dieses Dokument beschreibt, wie Sie die automatische Veröffentlichung auf PyPI einrichten.
- Gehen Sie zu: https://pypi.org/account/register/
- Erstellen Sie einen Account falls noch nicht vorhanden
- Wichtig: Aktivieren Sie 2FA (Two-Factor Authentication)
- Login bei PyPI: https://pypi.org/account/login/
- Token-Seite: https://pypi.org/manage/account/token/
- Neues Token:
- Klicken Sie "Add API token"
- Token name:
bash-script-maker-github-actions - Scope:
Entire account(empfohlen für den Start) - Klicken Sie "Add token"
- Token kopieren:
⚠️ WICHTIG: Kopieren Sie das Token SOFORT- Format:
pypi-AgEIcHlwaS5vcmcC...(beginnt mitpypi-) - Sie können es später nicht mehr einsehen!
- Repository Settings: https://github.com/securebitsorg/bash-script-maker/settings/secrets/actions
- Neues Secret:
- Klicken Sie "New repository secret"
- Name:
PYPI_API_TOKEN - Secret: Ihr komplettes PyPI Token
- Klicken Sie "Add secret"
Automatisch bei jedem Release (alle Workflows):
- ✅ Semantic Release: Bei
feat:undfix:Commits - ✅ Auto Release on Push: Bei
[release],[minor],[major]Tags - ✅ Manual Release: Bei Tag-Erstellung
- Source Distribution (
.tar.gz) - Wheel (
.whl) - für schnelle Installation - Automatische Metadaten aus
setup.pyundpyproject.toml
publish-pypi:
name: Publish to PyPI
needs: [release, build-and-upload]
runs-on: ubuntu-latest
if: needs.release.outputs.new_release_published == 'true' && !contains(needs.release.outputs.new_release_version, '-')
steps:
- name: Build packages
run: python setup.py sdist bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true- ✅ Release wurde erstellt (
new_release_published == 'true') - ✅ Keine Pre-Release Version (keine
-alpha,-beta,-rc) - ✅ PyPI Token ist verfügbar (
PYPI_API_TOKENSecret) - ✅ Build erfolgreich (alle vorherigen Jobs erfolgreich)
# Pakete lokal bauen
python setup.py sdist bdist_wheel
# Prüfen der Artefakte
ls -la dist/Für Tests können Sie zuerst TestPyPI verwenden:
- TestPyPI Token: https://test.pypi.org/manage/account/token/
- GitHub Secret:
TEST_PYPI_API_TOKEN - Temporärer Test-Upload:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*# Minor Release (neue Features)
git commit -m "feat: neue Funktion für PyPI-Test"
git push origin main
# → Automatischer Release + PyPI Upload
# Patch Release (Bug-Fixes)
git commit -m "fix: kleiner Bugfix für PyPI-Test"
git push origin main
# → Automatischer Release + PyPI UploadNach dem ersten Upload verfügbar unter:
- Projekt: https://pypi.org/project/bash-script-maker/
- Statistiken: https://pypistats.org/packages/bash-script-maker
- Workflows: https://github.com/securebitsorg/bash-script-maker/actions
- Logs: Klicken Sie auf einen Workflow → "publish-pypi" Job
# Nach dem Upload
pip install bash-script-maker
# Spezifische Version
pip install bash-script-maker==1.3.1
# Upgrade
pip install --upgrade bash-script-makerNach dem ersten erfolgreichen Upload:
- PyPI Projekt-Seite: https://pypi.org/project/bash-script-maker/
- Settings → Manage → Publishing
- Neues Token:
- Scope:
Project: bash-script-maker - Name:
bash-script-maker-github-actions-project
- Scope:
- GitHub Secret aktualisieren: Ersetzen Sie
PYPI_API_TOKEN
PyPI unterstützt auch "Trusted Publishing" ohne Token:
# .github/workflows/semantic-release.yml
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# Kein password nötig mit Trusted PublishingSetup: https://docs.pypi.org/trusted-publishers/
- ✅ 2FA aktivieren auf PyPI
- ✅ Projekt-spezifische Tokens verwenden
- ✅ Regelmäßig Tokens rotieren
- ✅ Logs überwachen für unerwartete Uploads
- ✅ Skip-existing verwenden um Fehler zu vermeiden
- 🔒 Niemals Token committen in Git
- 🔒 Nur GitHub Secrets verwenden
- 🔒 Bei Kompromittierung sofort widerrufen
- 🔒 Minimale Berechtigungen (projekt-spezifisch)
Lösung:
- Prüfen Sie das
PYPI_API_TOKENSecret - Token muss mit
pypi-beginnen - Token könnte abgelaufen sein
Lösung:
skip-existing: trueist bereits konfiguriert- Version könnte bereits auf PyPI existieren
- Prüfen Sie: https://pypi.org/project/bash-script-maker/
Lösung:
- Prüfen Sie
setup.pyundpyproject.toml - Lokalen Build testen:
python setup.py check
# Lokale Validierung
python setup.py check --strict
twine check dist/*
# Upload-Simulation
twine upload --dry-run dist/*Nach der Einrichtung:
- Automatische Uploads bei jedem Release
- Professionelle Paketverteilung über PyPI
- Einfache Installation für Benutzer:
pip install bash-script-maker - Versionsverwaltung synchron mit Git-Tags
- Null manueller Aufwand - vollautomatisch!
Einfach committen, pushen - PyPI-Upload passiert automatisch! 🚀