【发布时间】:2021-11-06 21:28:29
【问题描述】:
我想编写一个简单的 GitHub Action,在我推送到 GitHub 时运行我的 Django 应用程序的测试。 GitHub 在 push 上运行工作流,但由于某种原因,它不接受任何测试,即使在本地运行 python ./api/manage.py test 也可以。
作业摘要的Run tests 部分显示:
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 db 连接来运行它的测试。
我是 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
【问题讨论】:
标签: python django docker continuous-integration github-actions