Skip to content

Commit 3f553ec

Browse files
authored
Merge pull request #333 from rHomelab/chore/requirements_rework
2 parents 25252e4 + cb868b8 commit 3f553ec

11 files changed

Lines changed: 102 additions & 24 deletions

File tree

.github/actions/setup/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ runs:
1313
uses: actions/setup-python@v5
1414
with:
1515
python-version: ${{ steps.find_pyver.outputs.python-version }}
16-
- name: Install base dependencies
16+
- name: Install cog dependencies
1717
shell: bash
1818
run: pip install --quiet --upgrade --requirement requirements.txt
19-
- name: Install CI & cog dependencies
19+
- name: Install CI dependencies
2020
shell: bash
2121
run: pip install --quiet --upgrade --requirement requirements-dev.txt
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Pipeline script for extracting imports from cogs"""
2+
3+
import json
4+
from glob import glob
5+
6+
7+
def fetch_requirements() -> tuple[set[str], int]:
8+
requirements = set()
9+
cogs_with_requirements = 0
10+
11+
for filename in glob("*/info.json"):
12+
with open(filename, "r") as fp:
13+
info = json.load(fp)
14+
if "requirements" in info:
15+
requirements.update(info["requirements"])
16+
cogs_with_requirements += 1
17+
18+
return requirements, cogs_with_requirements
19+
20+
21+
def write_requirements(requirements: set[str]):
22+
with open("requirements.txt", "w") as fp:
23+
fp.write("\n".join(sorted(requirements)) + "\n")
24+
25+
26+
if __name__ == "__main__":
27+
all_requirements, cog_count = fetch_requirements()
28+
write_requirements(all_requirements)
29+
print(f"Compiled {len(all_requirements)} requirements from {cog_count} cogs")
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Compile Requirements
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- "*/info.json"
8+
- ".github/compile_cog_requirements.py"
9+
pull_request:
10+
branches: [main]
11+
paths:
12+
- "*/info.json"
13+
- ".github/compile_cog_requirements.py"
14+
workflow_dispatch:
15+
16+
jobs:
17+
compile-requirements:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
steps:
22+
- name: Checkout the repository
23+
uses: actions/checkout@v5
24+
with:
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v5
29+
30+
- name: Compile requirements
31+
run: python3 .github/compile_cog_requirements.py
32+
33+
- name: Check for changes
34+
id: check_changes
35+
run: |
36+
if git diff --quiet requirements.txt; then
37+
echo "changed=false" >> $GITHUB_OUTPUT
38+
else
39+
echo "changed=true" >> $GITHUB_OUTPUT
40+
fi
41+
42+
- name: Commit and push changes
43+
if: steps.check_changes.outputs.changed == 'true'
44+
run: |
45+
git config --local user.name 'github-actions[bot]'
46+
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
47+
git add requirements.txt
48+
git commit -m "chore: update cog requirements.txt"
49+
git push

guild_profiles/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"utility"
1010
],
1111
"requirements": [
12-
"aiofiles>=24.1.0"
12+
"aiofiles~=24.1.0"
1313
],
1414
"install_msg": "Usage: `[p]guildprofile`",
1515
"min_bot_version": "3.5.1"

jail/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description": "Create individual jails for users when multiple users need to be timed out.",
77
"disabled": false,
88
"name": "jail",
9-
"requirements": ["chat_exporter>=2.8.1"],
9+
"requirements": ["chat_exporter~=2.8.1"],
1010
"tags": [
1111
"utility"
1212
],

prometheus_exporter/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"prom"
1212
],
1313
"min_bot_version": "3.5.1",
14-
"requirements": ["prometheus_client"],
14+
"requirements": ["prometheus-client~=0.22.1"],
1515
"install_msg": "Usage: `[p]prom_export`"
1616
}

purge/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"inactive"
1212
],
1313
"requirements": [
14-
"croniter>=6.0.0"
14+
"croniter~=6.0.0"
1515
],
1616
"install_msg": "Usage: `[p]purge`",
1717
"min_bot_version": "3.5.1"

requirements-dev.txt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
aiofiles>=24.1.0
2-
chat_exporter>=2.8.1
3-
croniter>=6.0.0
4-
fastjsonschema==2.19.1
5-
pre-commit==3.7.0
6-
prometheus-client
7-
pyright==1.1.394
8-
pytest-aiohttp==1.0.5
9-
pytest-asyncio==0.23.6
10-
pytest==8.2.0
11-
python-Levenshtein>=0.27.1
12-
ruff==0.9.6
13-
sentry-sdk>=2.22.0
1+
Red-DiscordBot>=3.5.0
2+
3+
pyright~=1.1.394
4+
ruff~=0.12.0
5+
6+
fastjsonschema~=2.19.1
7+
pre-commit~=3.7.0
8+
pytest-aiohttp~=1.0.5
9+
pytest-asyncio~=0.23.6
10+
pytest~=8.2.0

requirements.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
pip
2-
wheel
3-
Red-DiscordBot
1+
aiofiles~=24.1.0
2+
chat_exporter~=2.8.1
3+
croniter~=6.0.0
4+
prometheus-client~=0.22.1
5+
python-Levenshtein~=0.27.1
6+
sentry-sdk~=2.22.0

sentry/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"sentry"
1111
],
1212
"requirements": [
13-
"sentry-sdk>=2.22.0"
13+
"sentry-sdk~=2.22.0"
1414
],
1515
"install_msg": "Install: `[p]set api sentry dsn,https://fooo@bar.baz/9`",
1616
"min_bot_version": "3.5.1"

0 commit comments

Comments
 (0)