forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
93 lines (66 loc) · 2.39 KB
/
tasks.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
import datetime
from invoke.tasks import task
from invoke.runner import run
VERSION = open('version.txt').read().strip()
BASE_S3_ARGS = ['--acl-public']
JS_S3_ARGS = ['--guess-mime-type', '--add-header "Content-Encoding: gzip"']
SHORT_FUTURE = datetime.timedelta(hours=1)
MEDIUM_FUTURE = datetime.timedelta(days=1)
FAR_FUTURE = datetime.timedelta(days=365)
@task
def test():
run('node_modules/.bin/jshint .')
run('node_modules/.bin/mocha-phantomjs -R dot test/index.html')
@task('test')
def build():
"Publish a nightly build"
make(get_rev())
@task('test')
def release():
"Publish a tagged version"
make(VERSION)
tag(VERSION)
def make(version):
run('VERSION=%s make raven' % version)
for raven in ('raven.js', 'raven.min.js'):
gzip(raven)
publish(raven, version, BASE_S3_ARGS + JS_S3_ARGS)
publish('raven.min.map', version, BASE_S3_ARGS)
def gzip(path):
run('gzip -6 build/%s' % path)
run('mv build/%s.gz build/%s' % (path, path))
def publish(path, version, args):
if '.' in version:
package = 'dist'
cache = get_cache_headers(FAR_FUTURE)
branch = version
else:
package = 'build'
cache = get_cache_headers(SHORT_FUTURE)
branch = get_branch()
upload(path, args + cache, package, branch)
if package == 'dist':
run('mkdir -p dist/%s' % version)
run('cp build/%s dist/%s' % (path, version))
version = version.split('.')
version.pop()
cache = get_cache_headers(MEDIUM_FUTURE)
while version:
upload(path, args + cache, package, '.'.join(version))
version.pop()
def tag(version):
run('git add dist/%s' % version)
run('git commit -m "%s"' % version)
run('git tag %s' % version)
run('git push origin %s' % version)
def upload(path, args, package, build):
run('s3cmd put %s build/%s s3://getsentry-cdn/%s/%s/%s' %
(' '.join(args), path, package, build, path))
def get_cache_headers(delta):
expires = datetime.datetime.utcnow() + delta
return ['--add-header "Cache-Control: public, max-age=%d"' % delta.total_seconds(),
'--add-header "Expires: %s GMT"' % expires.strftime('%a, %d %h %Y %T')]
def get_branch():
return run('git rev-parse --short --abbrev-ref HEAD', hide='both').stdout.strip()
def get_rev():
return run('git rev-parse --short HEAD', hide='both').stdout.strip()