Last active
May 5, 2019 23:52
-
-
Save rubenmromero/2caf7534af080ffc8e95fd15d5c93b65 to your computer and use it in GitHub Desktop.
Python :: Web service to deploy a repository on a server through a webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Modules Import | |
# | |
import os, sys, shlex, subprocess | |
# | |
# Variables Definition | |
# | |
workspace = '<repository_root_folder>' | |
# | |
# Main | |
# | |
# For execution through HTTP request | |
print "Content-Type: text/html\n" | |
# Change position to the repository root folder | |
os.chdir(workspace) | |
print "Verify that there are not local changes in '" + workspace + "' path of the target server:" | |
command = shlex.split('git diff --exit-code') | |
command_exec = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
output = command_exec.communicate() | |
if command_exec.returncode != 0: | |
print "It is not possible to deploy in '" + workspace + "' path due to there are local changes on the target server" | |
exit(1) | |
print "OK" | |
print "\nPull the existent new commits from origin on the target server:" | |
command = shlex.split('git pull') | |
output, error = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() | |
if output != '': | |
print output | |
if error != '': | |
print error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment