我想编写一个简单的 GitHub Action,在我推送到 GitHub 时运行我的 Django 应用程序的测试。GitHub 在推送时运行工作流程,但出于某种原因,它并不捕获任何测试,即使在本地运行 python ./api/manage.py test 也可以工作。
作业摘要的运行测试
部分显示如下:
1s
Run python ./api/manage.py test
System check identified no issues (0 silenced).
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
1s
2s
0s
背景信息:我的本地设置使用docker-compose,每个应用程序都有一个dockerfile。 Django应用程序是API。我想做的就是在推送时运行django测试。
我遇到了GitHub服务容器,我认为它们可能是必需的,因为django需要与postgres数据库连接才能运行其测试。
我对GitHub Actions很陌生,所以任何方向都将不胜感激。我猜想它应该比这更简单,但下面是我当前的.github/workflows/django.yml
文件:
name: Django CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
tests:
runs-on: ubuntu-latest
container: python:3
services:
# Label used to access the service container
db:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: password
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
# Downloads a copy of the code in your repository before running CI tests
- name: Check out repository code
uses: actions/checkout@v2
# Performs a clean installation of all dependencies
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r api/requirements.txt
- name: Run Tests
run: |
python ./api/manage.py test
env:
# The hostname used to communicate with the PostgreSQL service container
POSTGRES_HOST: postgres
# The default PostgreSQL port
POSTGRES_PORT: 5432