如果只有CI失败了,django会有什么麻烦?

问题描述 投票:0回答:1

概述

github-actions的配置文件如下

name: Django CI

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 1
      matrix:
        python-version: [ 3.11 ]

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}
          cache: pip

      - name: Set up and run tests
        env:
          DB_ENGINE: django.db.backends.mysql
          DB_NAME: portfolio_db
          DB_USER: root
          DB_PASSWORD: root
        run: |
          # https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md#mysql
          sudo systemctl start mysql
          mysql -u$DB_USER -p$DB_PASSWORD -e "CREATE DATABASE $DB_NAME;"
          python3 --version
          python3 -m venv venv
          source venv/bin/activate
          python -m pip install --upgrade pip
          python -m pip install -r requirements.txt
          python manage.py makemigrations register
          python manage.py migrate
          python manage.py makemigrations vietnam_research gmarker shopping linebot warehouse
          python manage.py migrate
          mysql -u$DB_USER -p$DB_PASSWORD -e "USE portfolio_db; SHOW TABLES;"
          export DJANGO_SECRET_KEY="$(base64 <<< "$RANDOM|TeStiNg|$RANDOM" | tr -d '\n')"
          python manage.py test

细节

此时此 CI 将失败。 迁移似乎工作正常,但在测试过程中似乎失败了。 https://github.com/duri0214/portfolio/actions/runs/7517515573/job/20463770730

enter image description here

我也很好奇检测到的测试数量的差异...

它在VPS服务器上运行良好,所以我不知道为什么它在CI中失败。如果有人知道请帮助我

python mysql django django-migrations
1个回答
0
投票

之前: https://github.com/duri0214/portfolio/actions/runs/10016990263/job/27690629902?pr=42

之后: https://github.com/duri0214/portfolio/actions/runs/10019680997/job/27696499042

我已经提前创建了

test_portfolio_db
,但似乎首先不需要迁移。这是因为 test_portfolio_db 是在manage.py test中创建的。

也就是说,我去掉migrate命令执行后测试就通过了。

© www.soinside.com 2019 - 2024. All rights reserved.