Skip to content

[POLA-9] Upgrade to Django==4.2.16 #9004

[POLA-9] Upgrade to Django==4.2.16

[POLA-9] Upgrade to Django==4.2.16 #9004

Workflow file for this run

---
name: CI Build
on:
push:
branches: ['master', 'prod']
pull_request:
branches: ['master']
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_ORGANIZATION: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
django-tests:
name: "Django tests"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python_version: ["3.11"]
django_version: ['current', "4.2.14"]
env:
PYTHON_VERSION: ${{ matrix.python_version }}
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- if: matrix.django_version != 'latest' && matrix.django_version != 'current'
run: |
echo "DJANGO_VERSION=${DJANGO_VERSION}" | tee "${GITHUB_ENV}";
env:
DJANGO_VERSION: ${{ matrix.django_version }}
- if: matrix.django_version == 'latest'
run: |
latest_version=$(curl 'https://pypi.org/pypi/django/json' | jq .info.version -r)
echo "DJANGO_VERSION=${latest_version}" | tee "${GITHUB_ENV}";
- name: "Copy .env.example to .env"
run: cp .env.example .env
- name: "Build CI image"
run: |
./scripts/ci-docker-image/build_image.sh
./scripts/ci-docker-image/verify_image.sh
- name: Pull images
run: ./scripts/pull_images.py
- name: "Run tests"
run: ./run_test.sh
- name: "Check missing migrations"
run: docker compose run web makemigrations --check -v 3
- name: "Checks the entire Django project for potential problems"
run: docker compose run web check --fail-level DEBUG -v 3
- name: "Upload coverage"
uses: codecov/codecov-action@v4.3.1
with:
fail_ci_if_error: false
verbose: true
- name: "Push image (push)"
if: github.event_name == 'push'
env:
PREPARE_BUILDX_CACHE: true
run: |
./scripts/ci-docker-image/push_image.sh
# Push cache
./scripts/ci-docker-image/build_image.sh
- name: Show logs on fail
if: ${{ failure() }}
run: docker compose logs
static-checks:
name: "Static checks"
runs-on: ubuntu-latest
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'
- name: "Setup Python dependencies"
run: pip install -U pip wheel setuptools virtualenv
- name: "Run static checks"
uses: pre-commit/action@v3.0.1
bi-validate:
name: "BI Validate"
runs-on: ubuntu-latest
needs: [django-tests, static-checks]
env:
COMPOSE_FILE: "docker-compose.yaml:docker-compose.dbt.yaml:docker-compose.dbt-local.yaml"
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Copy .env.example to .env"
run: cp .env.example .env
- name: "Build CI image"
run: |
./scripts/ci-docker-image/build_image.sh
./scripts/ci-docker-image/verify_image.sh
- name: "Build BI image"
run: |
# Build BI image
./scripts/bi-docker-image/build_image.sh
# Verify BI image
./scripts/bi-docker-image/verify_image.sh
- name: Pull images
run: ./scripts/pull_images.py
- run: docker compose config
- run: docker compose up -d
- run: ./run_manage.sh migrate
- run: ./run_manage.sh populate_db
- run: ./run_dbt.sh dbt deps
- run: ./run_dbt.sh dbt build
- name: "Push image (push)"
if: github.event_name == 'push'
run: ./scripts/bi-docker-image/push_image.sh
prod-image:
name: "Build Prod Image"
runs-on: ubuntu-latest
needs: [django-tests, static-checks]
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Set image tag"
if: |
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/prod')
run: |
set -x;
APP_NAME="$(./scripts/detect_app_name.py)";
echo "APP_NAME=${APP_NAME}"
echo "IMAGE_TAG=${APP_NAME}" >> $GITHUB_ENV;
echo "HEROKU_APP=${APP_NAME}" >> $GITHUB_ENV;
- name: "Build image"
run: ./scripts/prod-docker-image/build_image.sh
- name: "Verify image"
run: ./scripts/prod-docker-image/verify_image.sh
- name: "Push image (push)"
if: github.event_name == 'push'
env:
PREPARE_BUILDX_CACHE: true
run: |
# Build cache
./scripts/prod-docker-image/build_image.sh
./scripts/prod-docker-image/push_image.sh
deploy-app:
name: "Deploy app (push) - ${{ github.ref }}"
runs-on: ubuntu-latest
needs: [prod-image, bi-validate]
if: >-
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/prod')
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Login to Heroku Docker Registry"
run: ./scripts/docker_login_heroku.py
- name: "Install Heroku CLI"
run: "curl https://cli-assets.heroku.com/install.sh | sh"
- name: "Set environment env variable"
run: |
APP_NAME="$(./scripts/detect_app_name.py)";
echo "APP_NAME=${APP_NAME}"
echo "IMAGE_TAG=${APP_NAME}" >> $GITHUB_ENV;
echo "HEROKU_APP=${APP_NAME}" >> $GITHUB_ENV;
echo "HEROKU_DOMAIN=$(./scripts/fetch_domain.py "${APP_NAME}")" >> $GITHUB_ENV;
- uses: chrnorm/deployment-action@releases/v1
name: Create GitHub deployment
id: deployment
with:
token: "${{ github.token }}"
target_url: "https://${{ env.HEROKU_DOMAIN }}"
state: in_progress
environment: "${{ env.HEROKU_APP }}"
- name: "Pull image"
run: ./scripts/prod-docker-image/pull_image.sh
- name: "Deploy"
run: './scripts/deploy.sh "${HEROKU_APP}"'
- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@releases/v1
with:
token: "${{ github.token }}"
state: "success"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@releases/v1
with:
token: "${{ github.token }}"
state: "failure"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
deploy-bi:
name: "Deploy BI (push) - ${{ github.ref }}"
runs-on: ubuntu-latest
needs: [prod-image, bi-validate]
if: >-
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/prod')
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
COMPOSE_FILE: "docker-compose.dbt.yaml"
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Build BI image"
run: |
# Build BI image
./scripts/bi-docker-image/build_image.sh
# Verify BI image
./scripts/bi-docker-image/verify_image.sh
- run: pip install django-environ
- name: "Set environment env variable"
if: github.ref == 'refs/heads/prod'
run: |
source <(python ./pola-bi/dev.py --environment prod)
printenv | grep POLA_APP | cut -d "=" -f 2- | xargs -n 1 -I {} echo "::add-mask::{}"
printenv | grep POLA_APP >> $GITHUB_ENV;
- name: "Set environment env variable"
if: github.ref == 'refs/heads/master'
run: |
source <(python ./pola-bi/dev.py --environment staging)
printenv | grep POLA_APP | cut -d "=" -f 2- | xargs -n 1 -I {} echo "::add-mask::{}"
printenv | grep POLA_APP >> $GITHUB_ENV;
- run: ./run_dbt.sh dbt deps
- run: ./run_dbt.sh dbt build
- name: "Push image (push)"
if: github.event_name == 'push'
env:
PREPARE_BUILDX_CACHE: true
run: |
# Build cache
./scripts/bi-docker-image/build_image.sh
./scripts/bi-docker-image/push_image.sh