Skip to content

Commit 56aa08e

Browse files
authored
New pypi wait strategy to fix release pipeline. (#221)
Our release pipeline needs to wait until a newly uploaded version is available in pypi, before installing the new version for testing. We were using `pip search` to determine that the new version was available, but `pip search` has been disabled at a server level (https://status.python.org/incidents/grk0k7sz6zkp). We've had issues with this approach in the past anyway, where it looked like it was globally available, but then didn't install on some specific platform. New strategy is to just retry install attempts until they work (or cap out).
1 parent 1180914 commit 56aa08e

File tree

8 files changed

+43
-49
lines changed

8 files changed

+43
-49
lines changed

codebuild/cd/publish_to_prod_pypi.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ phases:
2222
- CURRENT_TAG_VERSION=$(git describe --tags | cut -f2 -dv)
2323
- python3 continuous-delivery/pull-pypirc.py prod
2424
- python3 -m twine upload -r pypi ../dist/*
25-
- python3 continuous-delivery/wait-for-pypi.py awscrt $CURRENT_TAG_VERSION --index https://pypi.python.org/pypi
2625
post_build:
2726
commands:
2827
- echo Build completed on `date`

codebuild/cd/publish_to_test_pypi.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ phases:
2222
- CURRENT_TAG_VERSION=$(git describe --tags | cut -f2 -dv)
2323
- python3 continuous-delivery/pull-pypirc.py alpha
2424
- python3 -m twine upload -r testpypi ../dist/*
25-
- python3 continuous-delivery/wait-for-pypi.py awscrt $CURRENT_TAG_VERSION --index https://test.pypi.org/pypi
2625
post_build:
2726
commands:
2827
- echo Build completed on `date`

codebuild/cd/test_prod_pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ phases:
1414
- echo Build started on `date`
1515
- cd aws-crt-python
1616
- CURRENT_TAG_VERSION=$(git describe --tags | cut -f2 -dv)
17-
- python3 -m pip install --no-cache-dir --user awscrt==$CURRENT_TAG_VERSION
17+
- python3 continuous-delivery/pip-install-with-retry.py --no-cache-dir --user awscrt==$CURRENT_TAG_VERSION
1818
- python3 continuous-delivery/test-pip-install.py
1919
post_build:
2020
commands:

codebuild/cd/test_test_pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ phases:
1414
- echo Build started on `date`
1515
- cd aws-crt-python
1616
- CURRENT_TAG_VERSION=$(git describe --tags | cut -f2 -dv)
17-
- python3 -m pip install --no-cache-dir -i https://testpypi.python.org/simple --user awscrt==$CURRENT_TAG_VERSION
17+
- python3 continuous-delivery/pip-install-with-retry.py --no-cache-dir -i https://testpypi.python.org/simple --user awscrt==$CURRENT_TAG_VERSION
1818
- python3 continuous-delivery/test-pip-install.py
1919
post_build:
2020
commands:
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/sanity-check-test-pypi.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FOR /F "delims=" %%A in ('git describe --tags') do ( set TAG_VERSION=%%A )
22
set CURRENT_VERSION=%TAG_VERSION:v=%
33

4-
"C:\Program Files\Python37\python.exe" -m pip install --no-cache-dir -i https://testpypi.python.org/simple --user awscrt==%CURRENT_VERSION% || goto error
4+
"C:\Program Files\Python37\python.exe" continuous-delivery\pip-install-with-retry.py --no-cache-dir -i https://testpypi.python.org/simple --user awscrt==%CURRENT_VERSION% || goto error
55
"C:\Program Files\Python37\python.exe" continuous-delivery\test-pip-install.py || goto error
66

77
goto :EOF
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
set -ex
33
CURRENT_TAG_VERSION=$(git describe --tags | cut -f2 -dv)
4-
python3 -m pip install --no-cache-dir -i https://testpypi.python.org/simple --user awscrt==$CURRENT_TAG_VERSION
4+
python3 continuous-delivery/pip-install-with-retry.py --no-cache-dir -i https://testpypi.python.org/simple --user awscrt==$CURRENT_TAG_VERSION
55
python3 continuous-delivery/test-pip-install.py

continuous-delivery/wait-for-pypi.py

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

0 commit comments

Comments
 (0)