-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·79 lines (67 loc) · 2.47 KB
/
build.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
79
#!/usr/bin/env python3
# -*- coding, utf-8 -*-
# Python script to regenerate FIDATA Website whenever new commit is made
# Copyright © 2014 Basil Peace
# This file is part of code for generation of FIDATA Website.
# This work is licensed under the Creative Commons
# Attribution-ShareAlike 3.0 Unported License. A copy of this license is
# located in LICENSE.code.txt. If you haven't received that file,
# visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter
# to Creative Commons, 444 Castro Street, Suite 900, Mountain View,
# California, 94041, USA.
from subprocess import check_call, check_output, CalledProcessError
import sys
from shutil import which
#from os.path import getmtime
#from datetime import datetime, timedelta
print('Getting last commit message...', flush = True)
commitMsg = check_output(['git', 'log',
'--max-count=1',
'--pretty=%B',
]).decode()
print('Testing for tags in commit message...', flush = True)
delim = commitMsg.find(':')
commitTags = commitMsg[0:delim].split(',')
if not (commitMsg.startswith('Merge pull request') or 'CODE' in commitTags or 'CONTENT' in commitTags) or 'OUTPUT' in commitTags:
exit(0)
# This code tries to find and run Ruby exec depending on platform
def runRubyExecutable(exec_name, args = [], cwd = None):
exec_name = which(exec_name)
if exec_name is None: # Nothing was found
raise FileNotFoundError
check_call([exec_name] + args, cwd = cwd)
#bundle_update_threshold = timedelta(days = 1)
#try:
# need_bundle_update = (datetime.today() - datetime.fromtimestamp(getmtime('Gemfile.lock'))) > bundle_update_threshold
#except OSError:
# need_bundle_update = True
#
#if need_bundle_update:
#print('Updating gems...', flush = True)
#runRubyExecutable('bundle', ['update'])
print('Running nanoc...\n', flush = True)
runRubyExecutable('nanoc', cwd = 'src')
print()
print('Adding changes to the index...', flush = True)
check_call(['git', 'add',
'-A',
])
print('Commiting...', flush = True)
commitMsg = 'OUTPUT' + commitMsg[delim:]
try:
commitRes = check_output(['git', 'commit',
'-m', commitMsg,
]).decode()
print(commitRes, flush = True)
except CalledProcessError as e:
commitRes = e.output.decode()
print(commitRes, flush = True)
if 'nothing to commit, working directory clean' in commitRes:
exit(0)
else:
raise
print('Pushing...', flush = True)
check_call(['git', 'push',
'--set-upstream', 'origin', 'master',
])
print('Done.', flush = True)