-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·100 lines (90 loc) · 2.85 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
import argparse
import build.git as git
import os
import subprocess
def assert_no_changes():
"""Assert that there are no uncommitted changes."""
if git.has_changes():
print("ERROR: Project has local changes!")
os.sys.exit(1)
def assert_branch_is(branch):
"""Assert that we're on the given branch."""
if git.current_branch() != branch:
print("ERROR: Must be on gh-pages branch!")
os.sys.exit(1)
def sbt(args):
"""Run an 'sbt' command."""
subprocess.run(["sbt"] + args, check = True)
def do_local(args):
"""Preform a local build for development."""
# Tasks
arg = ""
if args.watch:
arg += "~ "
arg += ";fastOptJS"
if args.full:
arg += ";fullOptJS"
arg += ";exportedProducts"
# Build
sbt([arg])
def do_publish(args):
# Preconditions
assert_branch_is("gh-pages")
assert_no_changes()
# Perform a full, clean build.
sbt(["clean", "fastOptJS", "fullOptJS", "exportedProducts"])
# Add build normally-ignored files; we use --force because the files are in
# ignored directories and are not present on the 'master' branch. Any files
# which are not normally ignored must have already been committed because
# of assert_no_changes()
git.force_add([
"target/scala-2.12/bg-stats-fastopt.js",
"target/scala-2.12/bg-stats-fastopt.js.map",
"target/scala-2.12/bg-stats-jsdeps.js",
"target/scala-2.12/bg-stats-jsdeps.min.js",
"target/scala-2.12/bg-stats-opt.js",
"target/scala-2.12/bg-stats-opt.js.map",
"target/web/sass/main/app.css",
"target/web/sass/main/app.css.map",
])
# Commit
git.commit("Update GitHub Pages", allow_empty = True)
# Push?
if args.push:
git.push("origin", force=True)
def main():
# Arguments
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(
title = "Commands",
help = "Run the specified task")
# Parser for the "local" command
parser_local = subparsers.add_parser("local")
parser_local.add_argument(
"--full",
dest = "full",
action = "store_true",
help = "perform FULLY OPTIMIZED build too")
parser_local.add_argument(
"--watch",
dest = "watch",
action = "store_true",
help = "continuously watch the sources and rebuild on change")
parser_local.set_defaults(func = do_local)
# Parser for the "publish" command
parser_publish = subparsers.add_parser("publish")
parser_publish.add_argument(
"--push",
dest = "push",
action = "store_true",
help = "push to origin")
parser_publish.set_defaults(func = do_publish)
# Run
args = parser.parse_args()
if "func" in args:
args.func(args)
else:
parser.print_help()
os.sys.exit(1)
main()