Python在GitHub action配置要求在CI系统配置自动编译和打包,要求在CI系统配置后台测试任务,并获取测试报告的详细步骤
时间: 2024-02-21 11:58:06 浏览: 228
以下是在GitHub Actions中配置Python自动编译和打包以及后台测试任务的详细步骤:
1. 在GitHub仓库的根目录中创建一个名为`.github/workflows`的文件夹,并在该文件夹中创建一个名为`python.yml`的文件。
2. 在`python.yml`文件中添加以下代码,以配置自动编译和打包:
```yml
name: Python CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x.x' # 选择所需的Python版本
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Build
run: python setup.py sdist bdist_wheel
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} # 如果需要上传到pypi,需要设置TWINE_USERNAME和TWINE_PASSWORD
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
```
3. 在`python.yml`文件中添加以下代码,以配置后台测试任务:
```yml
name: Python CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x.x' # 选择所需的Python版本
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Build
run: python setup.py sdist bdist_wheel
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} # 如果需要上传到pypi,需要设置TWINE_USERNAME和TWINE_PASSWORD
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
- name: Test with pytest
run: pytest --junitxml=junit/test-results.xml
env:
SOMETHING_SECRET: ${{ secrets.SOMETHING_SECRET }} # 如果需要在测试中使用环境变量,需要在此处设置
- name: Upload test results
uses: actions/upload-artifact@v2
with:
name: Test Results
path: junit/test-results.xml
```
4. 保存并提交`python.yml`文件,GitHub Actions将自动运行自动编译和打包以及后台测试任务。
5. 可以在GitHub Actions的页面中查看测试结果和测试报告。如果需要在测试中使用环境变量或者需要上传测试结果到其他地方,可以根据项目需求进行修改。
阅读全文