Skip to content

Commit 25252e4

Browse files
authored
Merge pull request #332 from rHomelab/ci/python_version
2 parents 06365da + 009c6a9 commit 25252e4

4 files changed

Lines changed: 39 additions & 36 deletions

File tree

.github/actions/setup/action.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ description: Installs project dependencies
33
runs:
44
using: composite
55
steps:
6+
- name: Find latest Python supported by Red-DiscordBot
7+
id: find_pyver
8+
shell: bash
9+
run: |
10+
PYVER=$(bash "$GITHUB_WORKSPACE/.github/find_latest_red_pyver.sh")
11+
echo "python-version=$PYVER" >> "$GITHUB_OUTPUT"
612
- name: Set up Python
713
uses: actions/setup-python@v5
814
with:
9-
python-version: "3.11"
15+
python-version: ${{ steps.find_pyver.outputs.python-version }}
1016
- name: Install base dependencies
1117
shell: bash
1218
run: pip install --quiet --upgrade --requirement requirements.txt
13-
- name: Install CI dependencies
19+
- name: Install CI & cog dependencies
1420
shell: bash
1521
run: pip install --quiet --upgrade --requirement requirements-dev.txt
16-
- name: Install cog dependencies
17-
shell: bash
18-
run: |
19-
python3 .github/actions/setup/compile_requirements.py
20-
pip install --quiet --upgrade --requirement requirements-cogs.txt

.github/actions/setup/compile_requirements.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/find_latest_red_pyver.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
PACKAGE="Red-DiscordBot"
5+
6+
# Fetch requires_python string, e.g. ">=3.9,<3.13"
7+
REQUIRES=$(curl -s "https://pypi.org/pypi/${PACKAGE}/json" | jq -r '.info.requires_python')
8+
9+
# Extract lower and upper bounds
10+
LOWER=$(grep -oP '(?<=\>=)[0-9]+\.[0-9]+' <<<"$REQUIRES" || true)
11+
UPPER=$(grep -oP '(?<=\<)[0-9]+\.[0-9]+' <<<"$REQUIRES" | head -n1 || true)
12+
13+
# Get all active Python versions from endoflife.date API
14+
VERSIONS=$(curl -s https://endoflife.date/api/python.json | jq -r '.[].latest' | cut -d. -f1,2 | sort -Vu)
15+
16+
# Filter by lower/upper bounds
17+
SUPPORTED=$(echo "$VERSIONS" | while read v; do
18+
if [[ -n "$LOWER" && "$(printf '%s\n' "$v" "$LOWER" | sort -V | head -n1)" != "$LOWER" ]]; then
19+
continue
20+
fi
21+
if [[ -n "$UPPER" && "$(printf '%s\n' "$v" "$UPPER" | sort -V | head -n1)" == "$UPPER" ]]; then
22+
continue
23+
fi
24+
echo "$v"
25+
done)
26+
27+
LATEST=$(echo "$SUPPORTED" | sort -V | tail -n1)
28+
29+
echo "$LATEST"

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ jobs:
2323
- name: Checkout the repository at the current branch
2424
uses: actions/checkout@v4
2525
- name: Install dependencies
26+
id: setup_deps
2627
uses: ./.github/actions/setup
2728
- uses: jakebailey/pyright-action@v2
2829
with:
29-
python-version: "3.11"
30+
python-version: ${{ steps.setup_deps.outputs.python-version }}
3031

3132
check-json:
3233
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)