初始化 Python 项目,添加 Gitea Actions 工作流和基本测试
This commit is contained in:
@@ -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
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
# Python-generated files
|
||||||
|
__pycache__/
|
||||||
|
*.py[oc]
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
wheels/
|
||||||
|
*.egg-info
|
||||||
|
|
||||||
|
# Virtual environments
|
||||||
|
.venv
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
3.14
|
||||||
@@ -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`
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
def main():
|
||||||
|
print("Hello from python-action-test!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -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 = []
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user