-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaction.yaml
More file actions
93 lines (85 loc) · 3.03 KB
/
Copy pathaction.yaml
File metadata and controls
93 lines (85 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: 'Wait for PyPI version'
description: 'Wait for a specific package version to become available on PyPI or TestPyPI'
inputs:
repository:
description: 'PyPI repository type: "pypi" or "testpypi"'
required: true
package:
description: 'Package name'
required: true
version:
description: 'Package version to wait for'
required: true
max_attempts:
description: 'Maximum number of retry attempts'
required: false
default: '30'
wait_seconds:
description: 'Seconds to wait between attempts'
required: false
default: '10'
runs:
using: composite
steps:
- name: Install requests
shell: bash
run: |
python -m pip install --upgrade pip
pip install requests
- name: Wait for version to be available
shell: python
env:
REPOSITORY: ${{ inputs.repository }}
PACKAGE: ${{ inputs.package }}
VERSION: ${{ inputs.version }}
MAX_ATTEMPTS: ${{ inputs.max_attempts }}
WAIT_SECONDS: ${{ inputs.wait_seconds }}
run: |
import os
import sys
import time
import requests
repository = os.environ["REPOSITORY"].strip().lower()
package = os.environ["PACKAGE"]
version = os.environ["VERSION"]
max_attempts = int(os.environ.get("MAX_ATTEMPTS", "30"))
wait_seconds = int(os.environ.get("WAIT_SECONDS", "10"))
if repository == "testpypi":
api_url = f"https://test.pypi.org/pypi/{package}/json"
repo_name = "TestPyPI"
elif repository == "pypi":
api_url = f"https://pypi.org/pypi/{package}/json"
repo_name = "PyPI"
else:
print(
f"ERROR: repository must be 'pypi' or 'testpypi', got {repository!r}",
file=sys.stderr,
)
sys.exit(1)
for attempt in range(max_attempts):
try:
r = requests.get(api_url, timeout=10)
r.raise_for_status()
data = r.json()
versions = data.get("releases", {})
keys = list(versions.keys())
print("Available versions:", keys[-10:]) # Show last 10 versions
if version in versions:
print(f"✓ Version {version} is available on {repo_name}")
print(f"Version {version} is now available on {repo_name}")
sys.exit(0)
print(f"✗ Version {version} is NOT available on {repo_name}")
except Exception as e:
print(f"Error checking version: {e}")
current = attempt + 1
print(
f"Attempt {current}/{max_attempts}: Version {version} not yet available "
f"on {repo_name}, waiting {wait_seconds} seconds..."
)
time.sleep(wait_seconds)
print(
f"ERROR: Version {version} did not become available on {repo_name} "
f"after {max_attempts} attempts",
file=sys.stderr,
)
sys.exit(1)