-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
executable file
·78 lines (65 loc) · 2.72 KB
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import subprocess
import questionary
def run_command(command, description=""):
"""Run a shell command and handle errors."""
print(f"Running: {description or command}")
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"\nError while running: {command}")
print(f"Exit status: {e.returncode}")
if e.output:
print("Command output (if any):", e.output.decode('utf-8', errors='ignore'))
raise e
def main():
package_name = "koreancar"
print(f"\n{'=' * 40}\nDeploying {package_name}\n{'=' * 40}")
# Step 1: Run tests
print("Running unit tests...")
try:
run_command("pytest --maxfail=1 --disable-warnings", description="Unit Tests")
except subprocess.CalledProcessError:
print("Unit tests failed. Aborting deployment.")
return
# Step 2: Clean up old build artifacts
print("Cleaning up old build artifacts...")
run_command("rm -rf dist build *.egg-info", description="Cleanup")
# Step 3: Build the package
print("Building the package...")
try:
run_command("python -m build", description="Build")
except subprocess.CalledProcessError:
print("Build failed. Aborting deployment.")
return
# Step 4: Upload to TestPyPI
print("Uploading to TestPyPI...")
try:
run_command("twine upload --repository testpypi dist/*", description="Upload to TestPyPI")
print("Upload to TestPyPI successful.")
except subprocess.CalledProcessError:
print("Upload to TestPyPI failed. Aborting deployment.")
return
# Step 5: Prompt for PyPI upload
upload_to_pypi = questionary.confirm("Do you want to upload to PyPI?").ask()
if upload_to_pypi:
print("Uploading to PyPI...")
try:
run_command("twine upload dist/*", description="Upload to PyPI")
print("Upload to PyPI completed successfully.")
except subprocess.CalledProcessError:
print("Upload to PyPI failed.")
return
else:
print("Skipping upload to PyPI.")
# Step 6: Git commit and push
git_commit = questionary.confirm("Do you want to commit and push changes to GitHub?").ask()
if git_commit:
commit_message = questionary.text("Enter commit message:", default="fix").ask()
try:
run_command(f"git add . && git commit -m \"{commit_message}\" && git push", description="Git Commit & Push")
print("Changes pushed to GitHub successfully.")
except subprocess.CalledProcessError:
print("Git commit or push failed.")
print(f"\n{'=' * 40}\nProcess completed successfully.\n{'=' * 40}")
if __name__ == "__main__":
main()