Skip to content

Commit 849dec9

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 849dec9

2 files changed

Lines changed: 124 additions & 4 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
# Export shell variables so Python can access them via os.environ
52+
export API_URL REPO_NAME
53+
54+
ATTEMPT=0
55+
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
56+
if python -c "
57+
import os
58+
import requests
59+
import sys
60+
try:
61+
api_url = os.environ['API_URL']
62+
version = os.environ['VERSION']
63+
repo_name = os.environ['REPO_NAME']
64+
r = requests.get(api_url, timeout=10)
65+
r.raise_for_status()
66+
versions = r.json().get('releases', {})
67+
print('Available versions:', list(versions.keys())[-10:]) # Show last 10 versions
68+
if version in versions:
69+
print(f'✓ Version {version} is available on {repo_name}')
70+
sys.exit(0)
71+
else:
72+
print(f'✗ Version {version} is NOT available on {repo_name}')
73+
sys.exit(1)
74+
except Exception as e:
75+
print(f'Error checking version: {e}')
76+
sys.exit(1)
77+
" 2>/dev/null; then
78+
echo "Version $VERSION is now available on $REPO_NAME"
79+
exit 0
80+
fi
81+
ATTEMPT=$((ATTEMPT + 1))
82+
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS: Version $VERSION not yet available on $REPO_NAME, waiting $WAIT_SECONDS seconds..."
83+
sleep $WAIT_SECONDS
84+
done
85+
echo "ERROR: Version $VERSION did not become available on $REPO_NAME after $MAX_ATTEMPTS attempts"
86+
exit 1

.github/workflows/deploy.yaml

Lines changed: 38 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,24 @@ 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+
# This is a bit dirty; running in a virtual environment would be cleaner.
57+
# (pip install only works because our package's dependencies are easy to install.)
58+
python -m pip install --upgrade pip
59+
pip install "$WHEEL_FILE" --quiet
60+
VERSION=$(python -c "import gridData; print(gridData.__version__)")
61+
pip uninstall -y griddataformats --quiet
62+
fi
63+
echo "version=$VERSION" >> $GITHUB_OUTPUT
64+
echo "Extracted version: $VERSION"
65+
4666
- name: Upload dist files
4767
uses: actions/upload-artifact@v4
4868
with:
@@ -133,7 +153,7 @@ jobs:
133153
fail-fast: false
134154
matrix:
135155
os: [ubuntu-latest, macos-latest]
136-
needs: deploy-testpypi
156+
needs: [build, deploy-testpypi]
137157
if: |
138158
github.repository == 'MDAnalysis/GridDataFormats' &&
139159
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
@@ -143,10 +163,17 @@ jobs:
143163
with:
144164
python-version: "3.14"
145165

166+
- name: Wait for version to be available on TestPyPI
167+
uses: ./.github/actions/wait-for-pypi-version
168+
with:
169+
repository: testpypi
170+
package: GridDataFormats
171+
version: ${{ needs.build.outputs.version }}
172+
146173
- name: Install from TestPyPI
147174
run: |
148175
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]
176+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ "GridDataFormats==${{ needs.build.outputs.version }}[test]"
150177
151178
- name: Test import
152179
run: |
@@ -163,7 +190,7 @@ jobs:
163190
fail-fast: false
164191
matrix:
165192
os: [ubuntu-latest, macos-latest]
166-
needs: deploy-pypi
193+
needs: [build, deploy-pypi]
167194
if: |
168195
github.repository == 'MDAnalysis/GridDataFormats' &&
169196
(github.event_name == 'release' && github.event.action == 'published')
@@ -173,10 +200,17 @@ jobs:
173200
with:
174201
python-version: "3.14"
175202

203+
- name: Wait for version to be available on PyPI
204+
uses: ./.github/actions/wait-for-pypi-version
205+
with:
206+
repository: pypi
207+
package: GridDataFormats
208+
version: ${{ needs.build.outputs.version }}
209+
176210
- name: Install from PyPI
177211
run: |
178212
python -m pip install --upgrade pip
179-
pip install GridDataFormats[test]
213+
pip install "GridDataFormats==${{ needs.build.outputs.version }}[test]"
180214
181215
- name: Test import
182216
run: |

0 commit comments

Comments
 (0)