Skip to content

Commit 7ffc88e

Browse files
committed
ensure testing of built version after deployment
- fix #158 - remember version that was built - ensure that we download the built version from TestPyPi or PyPi - built with AI assistance (cursor)
1 parent b29c1f4 commit 7ffc88e

File tree

2 files changed

+112
-4
lines changed

2 files changed

+112
-4
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: 'Wait for PyPI version'
2+
description: 'Wait for a specific package version to become available on PyPI or TestPyPI'
3+
inputs:
4+
repository:
5+
description: 'PyPI repository type: "pypi" or "testpypi"'
6+
required: true
7+
package:
8+
description: 'Package name'
9+
required: true
10+
version:
11+
description: 'Package version to wait for'
12+
required: true
13+
max_attempts:
14+
description: 'Maximum number of retry attempts'
15+
required: false
16+
default: '30'
17+
wait_seconds:
18+
description: 'Seconds to wait between attempts'
19+
required: false
20+
default: '10'
21+
22+
runs:
23+
using: composite
24+
steps:
25+
- name: Install requests
26+
shell: bash
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install requests
30+
31+
- name: Wait for version to be available
32+
shell: bash
33+
env:
34+
REPOSITORY: ${{ inputs.repository }}
35+
PACKAGE: ${{ inputs.package }}
36+
VERSION: ${{ inputs.version }}
37+
MAX_ATTEMPTS: ${{ inputs.max_attempts }}
38+
WAIT_SECONDS: ${{ inputs.wait_seconds }}
39+
run: |
40+
if [ "$REPOSITORY" = "testpypi" ]; then
41+
API_URL="https://test.pypi.org/pypi/$PACKAGE/json"
42+
REPO_NAME="TestPyPI"
43+
elif [ "$REPOSITORY" = "pypi" ]; then
44+
API_URL="https://pypi.org/pypi/$PACKAGE/json"
45+
REPO_NAME="PyPI"
46+
else
47+
echo "ERROR: repository must be 'pypi' or 'testpypi', got '$REPOSITORY'"
48+
exit 1
49+
fi
50+
51+
ATTEMPT=0
52+
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
53+
if python -c "
54+
import requests
55+
import sys
56+
try:
57+
r = requests.get('$API_URL', timeout=10)
58+
r.raise_for_status()
59+
versions = r.json().get('releases', {})
60+
print('Available versions:', list(versions.keys())[-10:]) # Show last 10 versions
61+
if '$VERSION' in versions:
62+
sys.exit(0)
63+
else:
64+
sys.exit(1)
65+
except Exception as e:
66+
print(f'Error checking version: {e}')
67+
sys.exit(1)
68+
" 2>/dev/null; then
69+
echo "Version $VERSION is now available on $REPO_NAME"
70+
exit 0
71+
fi
72+
ATTEMPT=$((ATTEMPT + 1))
73+
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS: Version $VERSION not yet available on $REPO_NAME, waiting $WAIT_SECONDS seconds..."
74+
sleep $WAIT_SECONDS
75+
done
76+
echo "ERROR: Version $VERSION did not become available on $REPO_NAME after $MAX_ATTEMPTS attempts"
77+
exit 1

.github/workflows/deploy.yaml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
build:
2222
name: Build package
2323
runs-on: ubuntu-latest
24+
outputs:
25+
version: ${{ steps.extract-version.outputs.version }}
2426
steps:
2527
- name: Checkout
2628
uses: actions/checkout@v4
@@ -43,6 +45,21 @@ jobs:
4345
run: |
4446
twine check dist/*
4547
48+
- name: Extract package version
49+
id: extract-version
50+
run: |
51+
WHEEL_FILE=$(ls dist/*.whl)
52+
# Extract version from wheel filename (format: GridDataFormats-VERSION-py3-none-any.whl)
53+
VERSION=$(basename "$WHEEL_FILE" | sed -n 's/GridDataFormats-\([^-]*\)-.*/\1/p')
54+
# Fallback: install wheel temporarily and get version
55+
if [ -z "$VERSION" ]; then
56+
pip install "$WHEEL_FILE" --quiet
57+
VERSION=$(python -c "import gridData; print(gridData.__version__)")
58+
pip uninstall -y GridDataFormats --quiet
59+
fi
60+
echo "version=$VERSION" >> $GITHUB_OUTPUT
61+
echo "Extracted version: $VERSION"
62+
4663
- name: Upload dist files
4764
uses: actions/upload-artifact@v4
4865
with:
@@ -133,7 +150,7 @@ jobs:
133150
fail-fast: false
134151
matrix:
135152
os: [ubuntu-latest, macos-latest]
136-
needs: deploy-testpypi
153+
needs: [build, deploy-testpypi]
137154
if: |
138155
github.repository == 'MDAnalysis/GridDataFormats' &&
139156
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
@@ -143,10 +160,17 @@ jobs:
143160
with:
144161
python-version: "3.14"
145162

163+
- name: Wait for version to be available on TestPyPI
164+
uses: ./.github/actions/wait-for-pypi-version
165+
with:
166+
repository: testpypi
167+
package: GridDataFormats
168+
version: ${{ needs.build.outputs.version }}
169+
146170
- name: Install from TestPyPI
147171
run: |
148172
python -m pip install --upgrade pip
149-
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ GridDataFormats[test]
173+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ "GridDataFormats==${{ needs.build.outputs.version }}[test]"
150174
151175
- name: Test import
152176
run: |
@@ -163,7 +187,7 @@ jobs:
163187
fail-fast: false
164188
matrix:
165189
os: [ubuntu-latest, macos-latest]
166-
needs: deploy-pypi
190+
needs: [build, deploy-pypi]
167191
if: |
168192
github.repository == 'MDAnalysis/GridDataFormats' &&
169193
(github.event_name == 'release' && github.event.action == 'published')
@@ -173,10 +197,17 @@ jobs:
173197
with:
174198
python-version: "3.14"
175199

200+
- name: Wait for version to be available on PyPI
201+
uses: ./.github/actions/wait-for-pypi-version
202+
with:
203+
repository: pypi
204+
package: GridDataFormats
205+
version: ${{ needs.build.outputs.version }}
206+
176207
- name: Install from PyPI
177208
run: |
178209
python -m pip install --upgrade pip
179-
pip install GridDataFormats[test]
210+
pip install "GridDataFormats==${{ needs.build.outputs.version }}[test]"
180211
181212
- name: Test import
182213
run: |

0 commit comments

Comments
 (0)