Skip to content

Commit 9224c5c

Browse files
committed
ci: always use latest Python version supported by Red-DiscordBot
1 parent 06365da commit 9224c5c

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

.github/actions/setup/action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ 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/actions/setup/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

.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)