Skip to content

Commit cdd3556

Browse files
authored
New pypi wait strategy to fix release pipeline. (#157)
The release pipeline would occasionally fail, due to the flakiness of our wait-for-pypi.py script. This technique has been used in aws-crt-python (see PR awslabs/aws-crt-python#221) for weeks with great success. Use it here now too.
1 parent 80f1a9d commit cdd3556

File tree

4 files changed

+41
-47
lines changed

4 files changed

+41
-47
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import time
2+
import sys
3+
import subprocess
4+
5+
DOCS = """Given cmdline args, executes: python3 -m pip install [args...]
6+
Keeps retrying until the new version becomes available in pypi (or we time out)"""
7+
if len(sys.argv) < 2:
8+
sys.exit(DOCS)
9+
10+
RETRY_INTERVAL_SECS = 10
11+
GIVE_UP_AFTER_SECS = 60 * 15
12+
13+
pip_install_args = [sys.executable, '-m', 'pip', 'install'] + sys.argv[1:]
14+
15+
start_time = time.time()
16+
while True:
17+
print(subprocess.list2cmdline(pip_install_args))
18+
result = subprocess.run(pip_install_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
19+
20+
stdout = result.stdout.decode().strip()
21+
if stdout:
22+
print(stdout)
23+
24+
if result.returncode == 0:
25+
# success
26+
sys.exit(0)
27+
28+
if "could not find a version" in stdout.lower():
29+
elapsed_secs = time.time() - start_time
30+
if elapsed_secs < GIVE_UP_AFTER_SECS:
31+
# try again
32+
print("Retrying in", RETRY_INTERVAL_SECS, "secs...")
33+
time.sleep(RETRY_INTERVAL_SECS)
34+
continue
35+
else:
36+
print("Giving up on retries after", int(elapsed_secs), "total secs.")
37+
38+
# fail
39+
sys.exit(result.returncode)

continuous-delivery/test_prod_pypi.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ phases:
1919
- echo Build started on `date`
2020
- cd aws-iot-device-sdk-python-v2
2121
- CURRENT_TAG_VERSION=$(git describe --tags | cut -f2 -dv)
22-
- python3 continuous-delivery/wait-for-pypi.py awsiotsdk $CURRENT_TAG_VERSION --index https://pypi.python.org/pypi
23-
- python3 -m pip install --no-cache-dir --user awsiotsdk==$CURRENT_TAG_VERSION
22+
- python3 continuous-delivery/pip-install-with-retry.py --no-cache-dir --user awsiotsdk==$CURRENT_TAG_VERSION
2423
- python3 samples/basic_discovery.py --region us-east-1 --cert /tmp/certificate.pem --key /tmp/privatekey.pem --root-ca /tmp/AmazonRootCA1.pem --thing-name aws-sdk-crt-unit-test --print-discover-resp-only -v Trace
2524

2625
post_build:

continuous-delivery/test_test_pypi.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ phases:
2121
- CURRENT_TAG_VERSION=$(git describe --tags | cut -f2 -dv)
2222
# this is here because typing isn't in testpypi, so pull it from prod instead
2323
- python3 -m pip install typing
24-
- python3 continuous-delivery/wait-for-pypi.py awsiotsdk $CURRENT_TAG_VERSION --index https://test.pypi.org/pypi
25-
- python3 -m pip install --no-cache-dir -i https://testpypi.python.org/simple --user awsiotsdk==$CURRENT_TAG_VERSION
24+
- python3 continuous-delivery/pip-install-with-retry.py -i https://testpypi.python.org/simple --user awsiotsdk==$CURRENT_TAG_VERSION
2625
- python3 samples/basic_discovery.py --region us-east-1 --cert /tmp/certificate.pem --key /tmp/privatekey.pem --root-ca /tmp/AmazonRootCA1.pem --thing-name aws-sdk-crt-unit-test --print-discover-resp-only -v Trace
2726

2827
post_build:

continuous-delivery/wait-for-pypi.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)