-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
45 lines (35 loc) · 1.26 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
import datetime
import os
import shutil
import subprocess
from blog import logger
deploy_dir = '__dist'
def deploy() -> None:
try:
logger.info('prepare git repository')
shutil.rmtree('.git', ignore_errors=True)
execute('git init')
execute('git add .')
now = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
commit_message = 'Update at {} UTC'.format(now)
logger.info('commit "{}"'.format(commit_message))
execute('git commit -m "{}"'.format(commit_message))
logger.info('Set remote repository: {}'.format(repository))
execute('git remote add origin %s' % repository)
logger.info('push to master branch')
execute('git push -f origin master')
except Exception as e:
logger.error(str(e))
def execute(cmd: str) -> None:
proc = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(out, err) = proc.communicate()
if err:
logger.warn(out)
raise Exception(err)
if __name__ == '__main__':
pwd = os.path.abspath(os.path.dirname(__file__))
os.chdir(os.path.join(pwd, deploy_dir))
deploy()