Skip to content

Commit 9e76bc2

Browse files
author
Kevin D Smith
committed
Update CI/CD tools
1 parent 02f18d3 commit 9e76bc2

File tree

8 files changed

+1010
-4
lines changed

8 files changed

+1010
-4
lines changed

cicd/download-wheels.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
3+
''' Download Wheel files from URL '''
4+
5+
import argparse
6+
import os
7+
import re
8+
import sys
9+
from urllib.parse import urljoin
10+
from urllib.request import urlopen, urlretrieve
11+
12+
13+
def main(args):
14+
''' Main routine '''
15+
if not args.version:
16+
args.version = r'\d+\.\d+\.\d+(\.\w+)*'
17+
18+
os.makedirs(args.dir, exist_ok=True)
19+
20+
txt = urlopen(args.url).read().decode('utf-8')
21+
whls = re.findall(
22+
r'href=[\'"](.+?/swat-{}(?:-\d+)?-.+?\.whl)'.format(args.version), txt)
23+
for whl in whls:
24+
url = urljoin(args.url, whl)
25+
print(url)
26+
urlretrieve(url, filename=os.path.join(args.dir, whl.split('/')[-1]))
27+
28+
return 0
29+
30+
31+
if __name__ == '__main__':
32+
parser = argparse.ArgumentParser(prog='download-wheels')
33+
34+
parser.add_argument('--version', '-v', type=str, metavar='version',
35+
help='version of package to download')
36+
parser.add_argument('--dir', '-d', type=str, metavar='directory',
37+
default='.',
38+
help='directory to download the files to')
39+
parser.add_argument('url', type=str, metavar='url',
40+
help='URL of PyPI package to download')
41+
42+
args = parser.parse_args()
43+
44+
try:
45+
sys.exit(main(args))
46+
except argparse.ArgumentTypeError as exc:
47+
sys.stderr.write('ERROR: {}\n'.format(exc))
48+
sys.exit(1)
49+
except KeyboardInterrupt:
50+
sys.exit(1)

cicd/get-host.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
Return a random hostname from the specified collection of names
5+
6+
'''
7+
8+
import argparse
9+
import itertools
10+
import os
11+
import random
12+
import re
13+
import sys
14+
15+
16+
def main(args):
17+
''' Main routine '''
18+
out = []
19+
for arg in args.host_expr:
20+
parts = [x for x in re.split(r'(?:\[|\])', arg) if x]
21+
22+
for i, part in enumerate(parts):
23+
if ',' in part:
24+
parts[i] = re.split(r'\s*,\s*', part)
25+
elif re.match(r'^\d+\-\d+$', part):
26+
start, end = part.split('-')
27+
width = len(start)
28+
start = int(start)
29+
end = int(end)
30+
parts[i] = [('%%0%sd' % width) % x for x in range(start, end + 1)]
31+
else:
32+
parts[i] = [part]
33+
34+
out += list(''.join(x) for x in itertools.product(*parts))
35+
36+
print(random.choice(out))
37+
38+
39+
if __name__ == '__main__':
40+
parser = argparse.ArgumentParser(description=__doc__.strip())
41+
42+
parser.add_argument('host_expr', type=str, metavar='hostname-expr', nargs='+',
43+
help='hostname expression (ex. myhost[01-06].com)')
44+
45+
args = parser.parse_args()
46+
47+
main(args)

cicd/get-server-info.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
get-server-info
5+
6+
Retrieve CAS server information using CAS log. The CAS server command
7+
is expected to have a -display option with a unique key for the invoked
8+
server. This is used to retrieve the PID of the server process. The
9+
basename of the CAS log file must match the value in the -display option.
10+
11+
'''
12+
13+
import argparse
14+
import os
15+
import re
16+
import subprocess
17+
import sys
18+
import time
19+
20+
21+
def main(args):
22+
'''
23+
Main routine
24+
25+
Parameters
26+
----------
27+
args : argparse arguments
28+
Arguments to the command-line
29+
30+
'''
31+
if not os.path.isfile(args.log_file):
32+
sys.stderr.write('error: file not found: {}'.format(args.log_file))
33+
sys.exit(1)
34+
35+
iters = 0
36+
for i in range(args.retries):
37+
iters += 1
38+
time.sleep(args.interval)
39+
if iters > args.retries:
40+
sys.stderr.write('error: could not locate CAS log file\n')
41+
sys.exit(1)
42+
43+
with open(args.log_file, 'r') as logf:
44+
txt = logf.read()
45+
m = re.search(r'===\s+.+?(\S+):(\d+)\s+.+?\s+.+?:(\d+)\s+===', txt)
46+
if m:
47+
hostname = m.group(1)
48+
binary_port = m.group(2)
49+
http_port = m.group(3)
50+
51+
sys.stdout.write('CASHOST={} '.format(hostname))
52+
sys.stdout.write('CAS_HOST={} '.format(hostname))
53+
sys.stdout.write('CAS_BINARY_PORT={} '.format(binary_port))
54+
sys.stdout.write('CAS_HTTP_PORT={} '.format(http_port))
55+
sys.stdout.write('CAS_BINARY_URL=cas://{}:{} '.format(hostname,
56+
binary_port))
57+
sys.stdout.write('CAS_HTTP_URL=http://{}:{} '.format(hostname,
58+
http_port))
59+
60+
if 'CASPROTOCOL' in os.environ or 'CAS_PROTOCOL' in os.environ:
61+
protocol = os.environ.get('CASPROTOCOL',
62+
os.environ.get('CAS_PROTOCOL', 'http'))
63+
if protocol == 'cas':
64+
sys.stdout.write('CASPROTOCOL=cas ')
65+
sys.stdout.write('CAS_PROTOCOL=cas ')
66+
sys.stdout.write('CASPORT={} '.format(binary_port))
67+
sys.stdout.write('CAS_PORT={} '.format(binary_port))
68+
sys.stdout.write('CASURL=cas://{}:{} '.format(hostname,
69+
binary_port))
70+
sys.stdout.write('CAS_URL=cas://{}:{} '.format(hostname,
71+
binary_port))
72+
else:
73+
sys.stdout.write('CASPROTOCOL={} '.format(protocol))
74+
sys.stdout.write('CAS_PROTOCOL={} '.format(protocol))
75+
sys.stdout.write('CASPORT={} '.format(http_port))
76+
sys.stdout.write('CAS_PORT={} '.format(http_port))
77+
sys.stdout.write('CASURL={}://{}:{} '.format(protocol, hostname,
78+
http_port))
79+
sys.stdout.write('CAS_URL={}://{}:{} '.format(protocol, hostname,
80+
http_port))
81+
82+
elif 'REQUIRES_TK' in os.environ:
83+
if os.environ.get('REQUIRES_TK', '') == 'true':
84+
sys.stdout.write('CASPROTOCOL=cas ')
85+
sys.stdout.write('CAS_PROTOCOL=cas ')
86+
sys.stdout.write('CASPORT={} '.format(binary_port))
87+
sys.stdout.write('CAS_PORT={} '.format(binary_port))
88+
sys.stdout.write('CASURL=cas://{}:{} '.format(hostname,
89+
binary_port))
90+
sys.stdout.write('CAS_URL=cas://{}:{} '.format(hostname,
91+
binary_port))
92+
else:
93+
sys.stdout.write('CASPROTOCOL=http ')
94+
sys.stdout.write('CAS_PROTOCOL=http ')
95+
sys.stdout.write('CASPORT={} '.format(http_port))
96+
sys.stdout.write('CAS_PORT={} '.format(http_port))
97+
sys.stdout.write('CASURL=http://{}:{} '.format(hostname,
98+
http_port))
99+
sys.stdout.write('CAS_URL=http://{}:{} '.format(hostname,
100+
http_port))
101+
102+
# Get CAS server pid
103+
cmd = ('ssh -x -o StrictHostKeyChecking=no {} '
104+
'ps ax | grep {} | grep -v grep | head -1'
105+
).format(hostname, '.'.join(args.log_file.split('.')[:-1]))
106+
pid = subprocess.check_output(cmd, shell=True) \
107+
.decode('utf-8').strip().split(' ', 1)[0]
108+
sys.stdout.write('CAS_PID={} '.format(pid))
109+
110+
break
111+
112+
113+
if __name__ == '__main__':
114+
115+
opts = argparse.ArgumentParser(description=__doc__.strip())
116+
117+
opts.add_argument('log_file', type=str, metavar='log-file',
118+
help='path to CAS server log')
119+
120+
opts.add_argument('--retries', '-r', default=5, type=int, metavar='#',
121+
help='number of retries in attempting to locate the log file')
122+
opts.add_argument('--interval', '-i', default=3, type=int, metavar='#',
123+
help='number of seconds between each retry')
124+
125+
args = opts.parse_args()
126+
127+
main(args)

cicd/promote-release-candidate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def copy_assets(url, assets):
6767
)
6868

6969

70-
7170
def git_tag(tag, sha=None):
7271
''' Add a tag '''
7372
cmd = ['git', 'tag', tag]
@@ -107,11 +106,12 @@ def delete_release(tag_name):
107106
Accept='application/vnd.github.v3+json'))
108107

109108
# Delete tags
109+
del_tags = [tag_name, tag_name.replace('-rc', '-snapshot')]
110110
cmd = ['git', 'show-ref', '--tags']
111111
for line in subprocess.check_output(cmd).decode('utf-8').strip().split('\n'):
112112
sha, tag = re.split(r'\s+', line.strip())
113113
tag = tag.split('/')[-1]
114-
if tag == tag_name:
114+
if tag in del_tags:
115115
cmd = ['git', 'tag', '-d', tag]
116116
subprocess.check_call(cmd)
117117
cmd = ['git', 'push', 'origin', ':refs/tags/{}'.format(tag)]
@@ -170,6 +170,7 @@ def main(args):
170170

171171
# Delete rc release
172172
delete_release(args.tag)
173+
delete_release(args.tag.replace('-rc', '-snapshot'))
173174

174175
return 0
175176

cicd/stage-release-candidate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def change_section_headings(m):
176176
r"# What's New\n\nThis document outlines features and "
177177
+ r"improvements from each release.", md_txt, flags=re.M)
178178
md_txt = re.sub(r'^(##\s+\d+\.\d+\.\d+)\s+\-\s+(\d+\-\d+\-\d+)',
179-
change_section_headings, md_txt, flags=re.M|re.I)
179+
change_section_headings, md_txt, flags=re.M | re.I)
180180

181181
with tempfile.TemporaryDirectory() as tmp_dir:
182182
changelog = os.path.join(tmp_dir, 'CHANGELOG.md')

0 commit comments

Comments
 (0)