Skip to content

Commit e652a76

Browse files
[CI] check setuptools compatibility (#2735)
* [CI] check setuptools compatibility * Potential fix for pull request finding 'CodeQL / Workflow does not contain permissions' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * [CI] add last line --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 59311e4 commit e652a76

2 files changed

Lines changed: 101 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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
20+
- name: Check license line changed
21+
id: check
22+
run: |
23+
if git diff HEAD~1 HEAD -- pyproject.toml | grep -q '^[+-].*license = "Apache-2.0"'; then
24+
echo "changed=true" >> "$GITHUB_OUTPUT"
25+
else
26+
echo "changed=false" >> "$GITHUB_OUTPUT"
27+
fi
28+
29+
- uses: actions/setup-python@v6
30+
if: steps.check.outputs.changed == 'true'
31+
with:
32+
python-version: "3.14"
33+
34+
- name: Generate version matrix
35+
if: steps.check.outputs.changed == 'true'
36+
id: parser
37+
run: |
38+
versions=$(python ci_loop_versions.py setuptools ">=77.0.1,<83")
39+
echo "versions=$versions" >> "$GITHUB_OUTPUT"
40+
41+
check:
42+
needs: prepare
43+
runs-on: ubuntu-latest
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
version: ${{ fromJSON(needs.prepare.outputs.versions) }}
48+
49+
steps:
50+
- uses: actions/checkout@v6
51+
- uses: actions/setup-python@v6
52+
with:
53+
python-version: "3.14"
54+
cache: pip
55+
56+
- name: Install package with selected setuptools
57+
run: |
58+
python -m pip install --upgrade pip
59+
python -m pip install . "setuptools==${{ matrix.version }}"
60+
61+
- name: Show versions
62+
run: |
63+
python --version
64+
python -m pip show setuptools

0 commit comments

Comments
 (0)