diff --git a/.github/tools/gen_requirements_txt.py b/.github/tools/gen_requirements_txt.py new file mode 100644 index 000000000..940979e71 --- /dev/null +++ b/.github/tools/gen_requirements_txt.py @@ -0,0 +1,32 @@ +# This script requires python 3.12 to run. +from __future__ import annotations + +import sys +from typing import Any + +import tomllib + + +def gen_requirements_txt(pyproject_cfg: dict[str, Any]) -> str: + _res: list[str] = [ + "# Automatically generated from pyproject.toml by gen_requirements_txt.py script.", + "# DO NOT EDIT! Only for reference use.", + ] + try: + _res.extend(pyproject_cfg["project"]["dependencies"]) + except KeyError: + print("WARNING: no deps are defined in pyproject.toml") + _res.append("") + return "\n".join(_res) + + +if __name__ == "__main__": + script_name, *args = sys.argv + if len(args) < 2: + print(f"Usage: {script_name} ") + sys.exit(1) + + pyproject_toml, requirements_txt, *_ = args + with open(pyproject_toml, "rb") as src, open(requirements_txt, "w") as dst: + _parsed = tomllib.load(src) + dst.write(gen_requirements_txt(_parsed)) diff --git a/.github/workflows/gen_requirements_txt.yaml b/.github/workflows/gen_requirements_txt.yaml new file mode 100644 index 000000000..3ab2f7028 --- /dev/null +++ b/.github/workflows/gen_requirements_txt.yaml @@ -0,0 +1,48 @@ +name: gen requirements.txt on pyproject.toml file changed + +on: + pull_request: + branches: + - main + paths: + - 'pyproject.toml' + # allow manual dispatch of this workflow + workflow_dispatch: + +jobs: + gen-requirements-txt: + runs-on: ubuntu-latest + timeout-minutes: 1 + + steps: + - name: checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: setup python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: generate requirements.txt + run: | + python .github/tools/gen_requirements_txt.py \ + pyproject.toml requirements.txt + + - name: commit change if needed + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + if git diff --exit-code requirements.txt; then + echo "skip commit as requirements.txt is not changed" + else + echo "detect requirements.txt updated, commit change ..." + git add requirements.txt + git commit -m "[GHA] Update requirements.txt on pyproject.toml changed" + git push + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..033939add --- /dev/null +++ b/requirements.txt @@ -0,0 +1,17 @@ +# Automatically generated from pyproject.toml by gen_requirements_txt.py script. +# DO NOT EDIT! Only for reference use. +aiofiles<25,>=24.1 +aiohttp>=3.9.5,<3.11 +cryptography>=42.0.4,<44 +grpcio>=1.53.2,<1.67 +protobuf<4.22,>=4.21.12 +pydantic<3,>=2.6 +pydantic-settings<3,>=2.3 +pyopenssl<25,>=24.1 +pyyaml<7,>=6.0.1 +requests<2.33,>=2.32 +simple-sqlite3-orm<0.3,>=0.2 +typing-extensions>=4.6.3 +urllib3<2.3,>=2.2.2 +uvicorn[standard]<0.31,>=0.30 +zstandard<0.24,>=0.22