From f808f51870029a42ad2336e85230a15c5c406d4d Mon Sep 17 00:00:00 2001 From: Mplan Date: Mon, 8 Jun 2026 22:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=20Python=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=EF=BC=8C=E6=B7=BB=E5=8A=A0=20Gitea=20Actions?= =?UTF-8?q?=20=E5=B7=A5=E4=BD=9C=E6=B5=81=E5=92=8C=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/python-action-test.yml | 27 ++++++++++++++++++++++++ .gitignore | 10 +++++++++ .python-version | 1 + README.md | 28 +++++++++++++++++++++++++ main.py | 6 ++++++ pyproject.toml | 7 +++++++ tests/test_main.py | 6 ++++++ 7 files changed, 85 insertions(+) create mode 100644 .gitea/workflows/python-action-test.yml create mode 100644 .gitignore create mode 100644 .python-version create mode 100644 README.md create mode 100644 main.py create mode 100644 pyproject.toml create mode 100644 tests/test_main.py diff --git a/.gitea/workflows/python-action-test.yml b/.gitea/workflows/python-action-test.yml new file mode 100644 index 0000000..390fc20 --- /dev/null +++ b/.gitea/workflows/python-action-test.yml @@ -0,0 +1,27 @@ +name: Python Action Test +run-name: ${{ gitea.actor }} +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.14 + + - name: Install test dependencies + run: | + python -m pip install --upgrade pip + python -m pip install pytest + + - name: Run unit tests + run: pytest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..505a3b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..6324d40 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.14 diff --git a/README.md b/README.md new file mode 100644 index 0000000..b7f915f --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# python-action-test + +这是一个简单的 Python 项目示例,包含一个 Gitea Actions 工作流。 + +## 说明 + +- `main.py` 包含一个简单的 `main()` 函数,用于打印欢迎消息。 +- `tests/test_main.py` 提供一个最小单元测试,检查 `main()` 是否输出预期文本。 +- `.gitea/workflows/python-action-test.yml` 是 Gitea Actions 的工作流配置,用于在 `push` 和 `pull_request` 事件时运行测试。 + +## 本地运行 + +```bash +python main.py +python -m pip install pytest +pytest +``` + +## Gitea Actions + +将此仓库推送到 Gitea 后,Gitea Actions 会触发以下流程: + +1. 检出仓库代码 +2. 安装 Python 3.14 +3. 安装 `pytest` +4. 执行单元测试 + +工作流文件路径:`.gitea/workflows/python-action-test.yml` diff --git a/main.py b/main.py new file mode 100644 index 0000000..3bc17b0 --- /dev/null +++ b/main.py @@ -0,0 +1,6 @@ +def main(): + print("Hello from python-action-test!") + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0d6c0cf --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "python-action-test" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.14" +dependencies = [] diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..d79c1b7 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,6 @@ +import main + +def test_main_prints_message(capsys): + main.main() + captured = capsys.readouterr() + assert "Hello from python-action-test!" in captured.out