testjob #705
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Based on https://github.com/actions/starter-workflows/blob/main/ci/django.yml | |
| name: Continuous Integration | |
| on: | |
| pull_request: | |
| branches: | |
| - "*" | |
| push: | |
| branches: [dev, master] | |
| env: | |
| PYTHON_TARGET: 3.11 | |
| DJANGO_SETTINGS_MODULE: tcf_core.settings.ci | |
| SECRET_KEY: ci-secret-key-not-for-production | |
| # CI database (GitHub Actions postgres service) | |
| DB_NAME: tcf_db | |
| DB_USER: postgres | |
| DB_PASSWORD: postgres | |
| DB_HOST: localhost | |
| DB_PORT: 5432 | |
| jobs: | |
| pylint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ env.PYTHON_TARGET }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_TARGET }} | |
| cache: 'pip' | |
| cache-dependency-path: 'requirements/*.txt' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements/ci.txt | |
| - name: Run pylint | |
| run: | | |
| export PYTHONPATH="$(pwd)" | |
| pylint --django-settings-module=${{ env.DJANGO_SETTINGS_MODULE }} --jobs=0 --load-plugins pylint_django tcf_website tcf_core | |
| django: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| code-coverage: ${{ steps.coverage.outputs.percentage }} | |
| services: | |
| postgres: | |
| image: postgres:15.4 | |
| env: | |
| POSTGRES_USER: ${{ env.DB_USER }} | |
| POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }} | |
| POSTGRES_DB: ${{ env.DB_NAME }} | |
| ports: | |
| - 5432:5432 | |
| options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ env.PYTHON_TARGET }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_TARGET }} | |
| cache: 'pip' | |
| cache-dependency-path: 'requirements/*.txt' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements/ci.txt | |
| - name: Migrations & Tests | |
| run: | | |
| python manage.py migrate | |
| coverage run manage.py test | |
| - name: Get code coverage | |
| id: coverage | |
| run: | | |
| echo "percentage=$(coverage report | grep -o '[0-9]\+%' | tail -1)" >> $GITHUB_OUTPUT | |
| eslint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - name: Install npm packages | |
| run: npm ci | |
| - name: Run ESLint | |
| run: npx eslint -c .config/.eslintrc.yml tcf_website/static/ | |
| probe_endpoint: | |
| name: Endpoint probe (compose) | |
| needs: [pylint, django, eslint] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build & start stack | |
| run: | | |
| docker compose up -d --build | |
| - name: Wait for app health | |
| run: | | |
| # Replace /health with your health endpoint | |
| for i in {1..60}; do | |
| if curl -fsS http://localhost:8000 > /dev/null; then | |
| echo "App is up" | |
| exit 0 | |
| fi | |
| echo "Waiting for app..." | |
| sleep 2 | |
| done | |
| echo "App did not become healthy in time" | |
| docker compose ps | |
| docker compose logs --no-color | |
| exit 1 | |