Skip to content

Commit 0a9ea1e

Browse files
feat: Automatisation complète de la publication
- Nouveau script publish_automated.py (100% automatisé, sans interaction) - Workflow GitHub Actions simplifié utilisant release_and_publish.py - Suppression de publish_all.py (remplacé par publish_automated.py) - Publication PyPI automatique sans token GitHub requis - Gestion d'erreurs robuste avec couleurs
1 parent 2464cf6 commit 0a9ea1e

File tree

2 files changed

+51
-47
lines changed

2 files changed

+51
-47
lines changed

.github/workflows/publish.yml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,21 @@ jobs:
88
deploy:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
12-
13-
- name: Set up Python
14-
uses: actions/setup-python@v4
15-
with:
16-
python-version: '3.11'
17-
18-
- name: Install dependencies
19-
run: |
20-
python -m pip install --upgrade pip
21-
pip install build twine
22-
23-
- name: Build package
24-
run: python -m build
25-
26-
- name: Run tests
27-
run: |
28-
pip install -r requirements.txt
29-
pip install -r requirements-dev.txt
30-
python -m pytest tests/ --cov=stats_toolkit --cov-report=xml
31-
32-
- name: Publish to PyPI
33-
env:
34-
TWINE_USERNAME: __token__
35-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
36-
run: twine upload dist/*
11+
- uses: actions/checkout@v3
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: '3.11'
17+
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install build twine requests
22+
23+
- name: Run release and publish script
24+
env:
25+
TWINE_USERNAME: __token__
26+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: python release_and_publish.py

publish_all.py renamed to publish_automated.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script automatisé pour build et publication PyPI (sans release GitHub)
4+
Basé sur publish_all.py mais 100% automatisé
5+
"""
6+
17
import subprocess
28
import sys
39
import os
@@ -54,6 +60,8 @@ def run(cmd, check=True, timeout=300):
5460

5561
if check and proc.returncode != 0:
5662
print(f"{RED}Erreur lors de l'exécution : {cmd}{ENDC}")
63+
if stderr:
64+
print(f"{RED}Détails: {stderr}{ENDC}")
5765
cleanup_processes()
5866
sys.exit(proc.returncode)
5967

@@ -70,52 +78,56 @@ def run(cmd, check=True, timeout=300):
7078
sys.exit(1)
7179

7280
def install_deps():
73-
run("python -m pip install --upgrade pip build sphinx sphinx-rtd-theme twine", check=True)
81+
print(f"{GREEN}🔄 Installation des dépendances...{ENDC}")
82+
run("python -m pip install --upgrade pip build twine", check=True)
7483

7584
def build_package():
85+
print(f"{GREEN}🔄 Construction du package...{ENDC}")
7686
run("python -m build", check=True)
7787

78-
def build_docs():
79-
run("sphinx-build -b html docs docs/_build/html", check=True)
80-
81-
def git_push_docs():
82-
run("git add -f docs/_build/html", check=True)
83-
run("git commit -m 'Mise à jour de la documentation HTML après build'", check=False)
84-
run("git push", check=True)
88+
def check_package():
89+
print(f"{GREEN}🔄 Vérification du package...{ENDC}")
90+
run("python -m twine check dist/*", check=True)
8591

8692
def publish_pypi():
93+
print(f"{GREEN}🔄 Publication sur PyPI...{ENDC}")
8794
twine_password = os.environ.get('TWINE_PASSWORD')
8895
if twine_password:
96+
# Pour Windows PowerShell
8997
run("python -m twine upload -u __token__ -p $env:TWINE_PASSWORD dist/*", check=True)
9098
elif os.path.exists(os.path.expanduser('~/.pypirc')):
9199
run("python -m twine upload dist/*", check=True)
92100
else:
93-
print(f"{RED}Aucun token PyPI trouvé dans TWINE_PASSWORD ni de fichier .pypirc détecté.\nLa publication ne peut pas continuer sans authentification.{ENDC}")
101+
print(f"{RED}Aucun token PyPI trouvé dans TWINE_PASSWORD ni de fichier .pypirc détecté.{ENDC}")
102+
print(f"{RED}La publication ne peut pas continuer sans authentification.{ENDC}")
94103
sys.exit(1)
95104

96105
def main():
97106
try:
98-
print(f"{GREEN}🚀 Début du processus de publication...{ENDC}")
107+
print(f"{GREEN}🚀 Début du processus de publication automatisé...{ENDC}")
108+
print("=" * 60)
99109

100110
install_deps()
101111
print(f"{GREEN}✅ Dépendances installées{ENDC}")
102112

103113
build_package()
104114
print(f"{GREEN}✅ Package construit{ENDC}")
105115

106-
build_docs()
107-
print(f"{GREEN}✅ Documentation générée{ENDC}")
116+
check_package()
117+
print(f"{GREEN}✅ Package vérifié{ENDC}")
118+
119+
publish_pypi()
120+
print(f"{GREEN}✅ Package publié sur PyPI{ENDC}")
121+
122+
print("\n" + "=" * 60)
123+
print(f"{GREEN}🎉 Publication terminée avec succès !{ENDC}")
124+
print(f"{YELLOW}Le package est maintenant disponible sur PyPI.{ENDC}")
125+
print(f"{YELLOW}Cela peut prendre quelques minutes pour apparaître.{ENDC}")
108126

109-
git_push_docs()
110-
print(f"{GREEN}✅ Documentation poussée sur Git{ENDC}")
127+
print(f"\n🔗 Liens utiles:")
128+
print(f"- PyPI: https://pypi.org/project/py-stats-toolkit/")
129+
print(f"- GitHub: https://github.com/PhoenixGuardianTools/py-stats-toolkit")
111130

112-
print(f"{YELLOW}Vérifie que tout est OK dans dist/ et docs/_build/html avant de publier.{ENDC}")
113-
confirm = input(f"{YELLOW}Souhaites-tu publier sur PyPI ? (o/n) : {ENDC}").strip().lower()
114-
if confirm == 'o':
115-
publish_pypi()
116-
print(f"{GREEN}🎉 Publication terminée avec succès !{ENDC}")
117-
else:
118-
print(f"{RED}Publication annulée.{ENDC}")
119131
finally:
120132
cleanup_processes()
121133

0 commit comments

Comments
 (0)