Skip to content

Commit c500104

Browse files
Add compatibility CI workflow (#45)
1 parent 0081c34 commit c500104

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import argparse
2+
import json
3+
4+
import requests
5+
from packaging.specifiers import SpecifierSet
6+
from packaging.version import Version
7+
8+
9+
def get_versions(package: str, version_spec: str) -> list[str]:
10+
specifier = SpecifierSet(version_spec)
11+
12+
url = f"https://pypi.org/pypi/{package}/json"
13+
resp = requests.get(url, timeout=30)
14+
resp.raise_for_status()
15+
data = resp.json()
16+
17+
all_versions = data["releases"].keys()
18+
19+
matched = sorted(
20+
(Version(v) for v in all_versions if Version(v) in specifier),
21+
reverse=True,
22+
)
23+
return [str(v) for v in matched]
24+
25+
26+
def main():
27+
parser = argparse.ArgumentParser(description="List matching PyPI versions as JSON")
28+
parser.add_argument("package", help="package name, e.g. setuptools")
29+
parser.add_argument("version", help='version spec, e.g. ">=77.0.1,<83"')
30+
args = parser.parse_args()
31+
32+
versions = get_versions(args.package, args.version)
33+
print(json.dumps(versions))
34+
35+
36+
if __name__ == "__main__":
37+
main()
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Test Compatibility
2+
3+
on:
4+
push:
5+
paths:
6+
- pyproject.toml
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
prepare:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
versions: ${{ steps.parser.outputs.versions || '[]' }}
17+
steps:
18+
- uses: actions/checkout@v6
19+
with:
20+
fetch-depth: 2
21+
22+
- name: Check license line changed
23+
id: check
24+
run: |
25+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
26+
echo "changed=true" >> "$GITHUB_OUTPUT"
27+
elif git diff HEAD~1 HEAD -- pyproject.toml | grep -q '^[+-].*license = "Apache-2.0"'; then
28+
echo "changed=true" >> "$GITHUB_OUTPUT"
29+
else
30+
echo "changed=false" >> "$GITHUB_OUTPUT"
31+
fi
32+
33+
- uses: actions/setup-python@v6
34+
if: steps.check.outputs.changed == 'true'
35+
with:
36+
python-version: "3.14"
37+
38+
- name: Generate version matrix
39+
if: steps.check.outputs.changed == 'true'
40+
id: parser
41+
run: |
42+
versions=$(python ci_loop_versions.py setuptools ">=77.0.1,<83")
43+
echo "versions=$versions" >> "$GITHUB_OUTPUT"
44+
45+
check:
46+
needs: prepare
47+
if: needs.prepare.outputs.versions != '[]'
48+
runs-on: ubuntu-latest
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
version: ${{ fromJSON(needs.prepare.outputs.versions) }}
53+
54+
steps:
55+
- uses: actions/checkout@v6
56+
- uses: actions/setup-python@v6
57+
with:
58+
python-version: "3.14"
59+
cache: pip
60+
61+
- name: Install package with selected setuptools
62+
run: |
63+
python -m pip install --upgrade pip
64+
python -m pip install . "setuptools==${{ matrix.version }}"
65+
66+
- name: Show versions
67+
run: |
68+
python --version
69+
python -m pip show setuptools

0 commit comments

Comments
 (0)