Skip to content

Upgrade PostgreSQL to 15 (#413) #908

Upgrade PostgreSQL to 15 (#413)

Upgrade PostgreSQL to 15 (#413) #908

Workflow file for this run

name: CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
static:
runs-on: ubuntu-latest
container: node:12
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: ~/.npm
key: v1-npm-deps-${{ hashFiles('**/package-lock.json') }}
restore-keys: v1-npm-deps-
- run: npm ci --no-optional --no-audit --progress=false
# Build static files
- name: Build static files
run: npm run build:prod
# Linting for static files
- run: npm run lint:js
- run: npm run lint:css
- run: npm run lint:format
- name: Upload static_compiled
uses: actions/upload-artifact@v2
with:
name: static_compiled
path: flare_portal/static_compiled
python:
runs-on: ubuntu-latest
needs: [static]
env:
# Run tests with the production settings.
DJANGO_SETTINGS_MODULE: flare_portal.settings.production
# SECRET_KEY is required by Django to start.
SECRET_KEY: fake_secret_key_to_run_tests
# This is the URL used by databases on our CI.
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
# Don't redirect to HTTPS in tests.
SECURE_SSL_REDIRECT: 'false'
# Service container for postgres
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres # pragma: allowlist secret
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- uses: actions/checkout@v2
# Set up environment
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8.x
- name: Install Poetry
run: pip install poetry
- name: Cache virtualenv
uses: actions/cache@v2
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
poetry-
- run: poetry install
# Linting for Python
- run: poetry run flake8 flare_portal
- run: poetry run black --check ./
- run: poetry run isort --check-only --diff --recursive flare_portal
- run: poetry run mypy --no-strict-optional --ignore-missing-imports
# Tests for Python
# We need to run the collectstatic command, because we use ManifestStaticFilesStorage.
# Otherwise the check command will fail
- name: Download static_compiled
uses: actions/download-artifact@v2
with:
name: static_compiled
path: flare_portal/static_compiled
- run: poetry run python manage.py collectstatic --verbosity 0 --noinput --clear
# Run system checks
- run: poetry run python manage.py check
# Check for missing migrations
- run: poetry run python manage.py makemigrations --check --noinput
# Create cache table.
- run: poetry run python manage.py createcachetable
# Run back-end tests
- run: poetry run python manage.py test --settings flare_portal.settings.test
deploy:
if: contains(github.ref, 'main')
runs-on: ubuntu-latest
needs: [python, static]
env:
DEPLOYMENT_KEY: ${{ secrets.DEPLOYMENT_KEY }}
HEROKU_APP: ${{ secrets.HEROKU_APP }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- name: Deploying to Heroku.
run: curl -sf -X POST -m 900 https://heroku-deploy.torchbox.com/$HEROKU_APP/$GITHUB_SHA?key=$DEPLOYMENT_KEY
- name: Sending Slack notification
run: 'curl -H "Content-Type: application/json" --request POST --data "{\"attachments\":[{\"fallback\":\"Deployed $HEROKU_APP\",\"color\":\"#2EB67D\",\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Deployed <https://$HEROKU_APP.herokuapp.com|$HEROKU_APP>\"}},{\"type\":\"context\",\"elements\":[{\"type\":\"image\",\"image_url\":\"https://github.com/$GITHUB_ACTOR.png\",\"alt_text\":\"$GITHUB_ACTOR\"},{\"type\":\"mrkdwn\",\"text\":\"$GITHUB_ACTOR - ref: $GITHUB_REF - SHA: $GITHUB_SHA\"}]}]}]}" $SLACK_WEBHOOK_URL'