|
5 | 5 | import argparse
|
6 | 6 | import datetime
|
7 | 7 | import glob
|
| 8 | +import io |
8 | 9 | import os
|
9 | 10 | import re
|
10 | 11 | import requests
|
| 12 | +import shutil |
11 | 13 | import sys
|
12 | 14 | import subprocess
|
| 15 | +import tarfile |
13 | 16 | import tempfile
|
14 | 17 | from urllib.parse import quote
|
15 |
| -from urllib.request import urlopen |
| 18 | +from urllib.request import urlopen, urlretrieve |
16 | 19 |
|
17 | 20 |
|
18 | 21 | GITHUB_TOKEN = os.environ['GITHUB_TOKEN']
|
@@ -125,6 +128,66 @@ def checkout_main(tag=None):
|
125 | 128 | subprocess.check_call(cmd)
|
126 | 129 |
|
127 | 130 |
|
| 131 | +def rotate_doc(tag_name): |
| 132 | + ''' Rotate documentation in the gh-pages branch ''' |
| 133 | + cmd = ['git', 'checkout', 'gh-pages'] |
| 134 | + subprocess.check_call(cmd) |
| 135 | + |
| 136 | + release = get_release(tag_name) |
| 137 | + assets = release['assets'] |
| 138 | + |
| 139 | + doc_url = None |
| 140 | + for asset in assets: |
| 141 | + asset_url = asset['browser_download_url'] |
| 142 | + if asset_url.endswith('-doc.tar.gz'): |
| 143 | + doc_url = asset_url |
| 144 | + break |
| 145 | + |
| 146 | + if not doc_url: |
| 147 | + raise RuntimeError('Could not locate documentation file') |
| 148 | + |
| 149 | + # Change to production tag |
| 150 | + tag_name = tag_name.replace('-rc', '') |
| 151 | + |
| 152 | + # Remove existing directory if it exists |
| 153 | + shutil.rmtree(tag_name, ignore_errors=True) |
| 154 | + |
| 155 | + with urlopen(doc_url) as doc_file: |
| 156 | + try: |
| 157 | + tar_file = tarfile.open(fileobj=doc_file, mode='r|gz') |
| 158 | + tar_file.extractall() |
| 159 | + finally: |
| 160 | + tar_file.close() |
| 161 | + |
| 162 | + for f in glob.glob('python-swat-*-doc'): |
| 163 | + shutil.move(f, tag_name) |
| 164 | + |
| 165 | + # Clear out existing top-level doc |
| 166 | + for f in (glob.glob('*.html') + glob.glob('*.js') |
| 167 | + + glob.glob('*.inv') + ['.buildinfo']): |
| 168 | + os.remove(f) |
| 169 | + for f in ['_images', '_sources', '_static', 'generated']: |
| 170 | + shutil.rmtree(f) |
| 171 | + |
| 172 | + # Copy new doc to the top-level |
| 173 | + from distutils.dir_util import copy_tree |
| 174 | + copy_tree(tag_name, '.') |
| 175 | + |
| 176 | + cmd = ['git', 'add', '*.html', '*.js', '*.inv', '_images', |
| 177 | + '_sources', '_static', 'generated', '.buildinfo', tag_name] |
| 178 | + subprocess.check_call(cmd) |
| 179 | + |
| 180 | + subprocess.check_call(['git', 'status']) |
| 181 | + |
| 182 | + # See if anything needs to be committed |
| 183 | + cmd = ['git', 'status', '--untracked-files=no', '--porcelain'] |
| 184 | + txt = subprocess.check_output(cmd) |
| 185 | + |
| 186 | + if txt: |
| 187 | + cmd = ['git', 'commit', '-m', 'Rotate documentation to {}'.format(tag_name)] |
| 188 | + subprocess.check_call(cmd) |
| 189 | + |
| 190 | + |
128 | 191 | def get_release(tag_name):
|
129 | 192 | ''' Retrieve the upload URL for the given tag '''
|
130 | 193 | res = requests.get(
|
@@ -163,12 +226,18 @@ def main(args):
|
163 | 226 | # Retrieve rc release info
|
164 | 227 | rc_release = get_release(args.tag)
|
165 | 228 |
|
| 229 | + # Rotate documentation |
| 230 | + try: |
| 231 | + rotate_doc(args.tag) |
| 232 | + finally: |
| 233 | + checkout_main() |
| 234 | + |
166 | 235 | # Push release
|
167 | 236 | git_tag(release_tag, sha=release_sha)
|
168 | 237 | git_push(tag=release_tag)
|
169 | 238 | create_release(release_tag, release_sha, rc_release)
|
170 | 239 |
|
171 |
| - # Delete rc release |
| 240 | + # Delete rc release and snapshots |
172 | 241 | delete_release(args.tag)
|
173 | 242 | delete_release(args.tag.replace('-rc', '-snapshot'))
|
174 | 243 |
|
|
0 commit comments