Make sure dist is created for the HEAD before uploading.
authorCheng Zhao <zcbenz@gmail.com>
Sat, 29 Jun 2013 03:36:02 +0000 (11:36 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sat, 29 Jun 2013 03:36:02 +0000 (11:36 +0800)
script/lib/util.py
script/upload.py

index acbaca3..8b1c473 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 import atexit
+import contextlib
 import errno
 import shutil
 import subprocess
@@ -18,6 +19,16 @@ def tempdir(prefix=''):
   return directory
 
 
+@contextlib.contextmanager
+def scoped_cwd(path):
+  cwd = os.getcwd()
+  os.chdir(path)
+  try:
+    yield
+  finally:
+    os.chdir(cwd)
+
+
 def download(text, url, path):
   with open(path, 'w') as local_file:
     web_file = urllib2.urlopen(url)
index a73f8de..a247bd8 100755 (executable)
@@ -4,8 +4,11 @@ import errno
 import glob
 import os
 import subprocess
+import sys
 import tempfile
 
+from lib.util import *
+
 
 SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
 
@@ -13,6 +16,9 @@ SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
 def main():
   try:
     ensure_s3put()
+    if not dist_newer_than_head():
+      create_dist = os.path.join(SOURCE_ROOT, 'script', 'create-dist.py')
+      subprocess.check_call([sys.executable, create_dist])
     upload()
   except AssertionError as e:
     return e.message
@@ -28,6 +34,20 @@ def ensure_s3put():
   assert 'multipart' in output, 'Error: Please install boto and filechunkio'
 
 
+def dist_newer_than_head():
+  with scoped_cwd(SOURCE_ROOT):
+    try:
+      head_time = subprocess.check_output(['git', 'log', '--pretty=format:%at',
+                                           '-n', '1']).strip()
+      dist_time = os.path.getmtime(os.path.join(SOURCE_ROOT, 'atom-shell.zip'))
+    except OSError as e:
+      if e.errno != errno.ENOENT:
+        raise
+      return False
+
+  return dist_time > int(head_time)
+
+
 def upload():
   os.chdir(SOURCE_ROOT)
   bucket, access_key, secret_key = s3_config()