-
Notifications
You must be signed in to change notification settings - Fork 134
/
publish.py
61 lines (48 loc) · 1.7 KB
/
publish.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import os
import shutil
import sys
import datetime
FILE_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
OUT_PATH = os.path.join(FILE_DIR, 'out')
SRC_PATH = os.path.join(FILE_DIR, 'app')
REPOSITORY = '[email protected]:craft-ai/tutorials.git'
BRANCH = 'gh-pages'
def main():
print "Publishing craft ai tutorials, to '{}/{}'.".format(REPOSITORY, BRANCH)
try:
if os.path.exists(OUT_PATH):
shutil.rmtree(OUT_PATH)
shutil.copytree(SRC_PATH, OUT_PATH)
subprocess.check_output(
["git", "init"],
stderr=subprocess.STDOUT,
cwd=OUT_PATH)
subprocess.check_output(
["git", "checkout", "-B", BRANCH],
stderr=subprocess.STDOUT,
cwd=OUT_PATH)
subprocess.check_output(
["git", "add", "*"],
stderr=subprocess.STDOUT,
cwd=OUT_PATH)
subprocess.check_output(
["git", "commit", "--author=Companion Cube <[email protected]>", "-mPublishing tutorials - {}".format(datetime.datetime.utcnow())],
stderr=subprocess.STDOUT,
cwd=OUT_PATH)
subprocess.check_output(
["git", "remote", "add", "origin", REPOSITORY],
stderr=subprocess.STDOUT,
cwd=OUT_PATH)
subprocess.check_output(
["git", "push", "origin", "+{}".format(BRANCH)],
stderr=subprocess.STDOUT,
cwd=OUT_PATH)
except subprocess.CalledProcessError, e:
raise RuntimeError("Error while publishing to git: {}".format(e.output))
return 1
return 0
if __name__ == "__main__" :
sys.exit(main())