Skip to content

Commit 121a182

Browse files
authored
Optimize PyPI package availability checks
Reduced maximum attempts and sleep time for waiting on PyPI package availability. Updated download logic to prioritize CDN and added file size verification.
1 parent ca021c6 commit 121a182

1 file changed

Lines changed: 47 additions & 15 deletions

File tree

.github/workflows/conda_build.yml

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,43 @@ jobs:
3434
id: wait-pypi
3535
run: |
3636
VERSION="${{ steps.get-version.outputs.version }}"
37-
MAX_ATTEMPTS=30
38-
SLEEP_TIME=60
37+
MAX_ATTEMPTS=20
38+
SLEEP_TIME=30
3939
40-
echo "Waiting for omnipkg version $VERSION to be available on PyPI..."
40+
echo "Checking for omnipkg version $VERSION on PyPI..."
4141
4242
for i in $(seq 1 $MAX_ATTEMPTS); do
4343
echo "Attempt $i/$MAX_ATTEMPTS..."
4444
45-
# Check if the package exists on PyPI
45+
# Check PyPI JSON API first (most reliable)
4646
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
47-
"https://pypi.org/packages/source/o/omnipkg/omnipkg-$VERSION.tar.gz")
47+
"https://pypi.org/pypi/omnipkg/$VERSION/json")
4848
4949
if [ "$HTTP_CODE" = "200" ]; then
50-
echo "✓ Package found on PyPI!"
51-
break
52-
elif [ $i -eq $MAX_ATTEMPTS ]; then
50+
echo "✓ Package version found on PyPI API!"
51+
52+
# Also verify the tar.gz file is downloadable
53+
DOWNLOAD_URL="https://files.pythonhosted.org/packages/source/o/omnipkg/omnipkg-$VERSION.tar.gz"
54+
DOWNLOAD_CODE=$(curl -s -o /dev/null -w "%{http_code}" -I "$DOWNLOAD_URL")
55+
56+
if [ "$DOWNLOAD_CODE" = "200" ] || [ "$DOWNLOAD_CODE" = "302" ]; then
57+
echo "✓ Package file is downloadable!"
58+
break
59+
else
60+
echo "⚠ Package found in API but file not yet available (HTTP $DOWNLOAD_CODE)"
61+
fi
62+
else
63+
echo "Package not yet available (HTTP $HTTP_CODE)"
64+
fi
65+
66+
if [ $i -eq $MAX_ATTEMPTS ]; then
5367
echo "✗ Package not found after $MAX_ATTEMPTS attempts"
68+
echo "Check: https://pypi.org/project/omnipkg/$VERSION/"
5469
exit 1
55-
else
56-
echo "Package not yet available (HTTP $HTTP_CODE). Waiting ${SLEEP_TIME}s..."
57-
sleep $SLEEP_TIME
5870
fi
71+
72+
echo "Waiting ${SLEEP_TIME}s..."
73+
sleep $SLEEP_TIME
5974
done
6075
6176
- name: Download and calculate SHA256
@@ -64,14 +79,31 @@ jobs:
6479
VERSION="${{ steps.get-version.outputs.version }}"
6580
6681
echo "Downloading package from PyPI..."
67-
curl -L -o "omnipkg-$VERSION.tar.gz" \
68-
"https://pypi.org/packages/source/o/omnipkg/omnipkg-$VERSION.tar.gz"
82+
# Try the files.pythonhosted.org URL first (CDN)
83+
if ! curl -L -f -o "omnipkg-$VERSION.tar.gz" \
84+
"https://files.pythonhosted.org/packages/source/o/omnipkg/omnipkg-$VERSION.tar.gz"; then
85+
# Fallback to pypi.org URL
86+
echo "CDN failed, trying pypi.org..."
87+
curl -L -f -o "omnipkg-$VERSION.tar.gz" \
88+
"https://pypi.org/packages/source/o/omnipkg/omnipkg-$VERSION.tar.gz"
89+
fi
90+
91+
# Verify file size
92+
FILE_SIZE=$(wc -c < "omnipkg-$VERSION.tar.gz")
93+
echo "File size: $FILE_SIZE bytes"
94+
95+
if [ "$FILE_SIZE" -lt 10000 ]; then
96+
echo "Error: File too small ($FILE_SIZE bytes)"
97+
exit 1
98+
fi
6999
70100
echo "Calculating SHA256..."
71101
if command -v sha256sum &> /dev/null; then
72102
SHA256=$(sha256sum "omnipkg-$VERSION.tar.gz" | cut -d' ' -f1)
73-
else
103+
elif command -v shasum &> /dev/null; then
74104
SHA256=$(shasum -a 256 "omnipkg-$VERSION.tar.gz" | cut -d' ' -f1)
105+
else
106+
SHA256=$(python3 -c "import hashlib; print(hashlib.sha256(open('omnipkg-$VERSION.tar.gz', 'rb').read()).hexdigest())")
75107
fi
76108
77109
echo "sha256=$SHA256" >> $GITHUB_OUTPUT
@@ -139,7 +171,7 @@ jobs:
139171
Automated update to omnipkg version ${{ needs.wait-for-pypi.outputs.version }}
140172
141173
- Updated version in meta.yaml
142-
- Updated SHA256 hash
174+
- Updated SHA256 hash: ${{ needs.wait-for-pypi.outputs.sha256 }}
143175
144176
Changes were automatically generated by GitHub Actions after PyPI release.
145177
branch: "update-v${{ needs.wait-for-pypi.outputs.version }}"

0 commit comments

Comments
 (0)