Skip to content

Application Banner #1975

Application Banner

Application Banner #1975

# Based on https://github.com/actions/starter-workflows/blob/main/ci/django.yml
name: Continuous Integration
on:
pull_request:
branches:
- "*"
# The following is needed to run tests upon direct push to dev or master
push:
branches: [dev, master]
env:
PYTHON_TARGET: 3.11
# Django
DJANGO_SETTINGS_MODULE: tcf_core.settings.ci
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DEBUG: 1
# database
DB_NAME: tcf_db # arbitrary string
DB_USER: postgres # default user
DB_PASSWORD: postgres # default password
DB_HOST: localhost # required for GitHub Actions
DB_PORT: 5432 # default port
# social-auth-app-django
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY: ${{ secrets.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY }}
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET: ${{ secrets.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET }}
# discord
DISCORD_URL_BUG: ${{ secrets.DISCORD_URL_BUG }}
DISCORD_URL_FEEDBACK: ${{ secrets.DISCORD_URL_FEEDBACK }}
# email for account verification
EMAIL_HOST_USER: ${{ secrets.EMAIL_HOST_USER }}
EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD }}
# review drive account information
REVIEW_DRIVE_ID: ${{ secrets.REVIEW_DRIVE_ID }}
REVIEW_DRIVE_EMAIL: ${{ secrets.REVIEW_DRIVE_EMAIL }}
REVIEW_DRIVE_PASSWORD: ${{ secrets.REVIEW_DRIVE_PASSWORD }}
jobs:
pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.PYTHON_TARGET }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_TARGET }}
- name: Install Python packages, excluding the unnecessary ones
run: |
python -m pip install --upgrade pip
sed -i '/\(coverage\|types\-tqdm\|black\|isort\|gunicorn\|django\-heroku\|uwsgi\)/d' requirements.txt
pip install -r requirements.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
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.PYTHON_TARGET }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_TARGET }}
- name: Install Python packages, excluding the unnecessary ones
run: |
python -m pip install --upgrade pip
sed -i '/\(lint\|mypy\|types\-tqdm\|black\|isort\|gunicorn\|django\-heroku\|django\-stubs\|uwsgi\)/d' requirements.txt
pip install -r requirements.txt
- name: Migrations & Tests
run: |
envsubst < .config/.env.example > .env
python manage.py migrate
coverage run manage.py test
- name: Get code coverage
id: coverage
run: |
echo "::set-output name=percentage::$(coverage report | grep -o '[0-9]\+%' | tail -1)"
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Node
uses: actions/setup-node@v1
with:
node-version: 20
- name: Install npm packages
run: npm ci
- name: Run ESLint
run: npx eslint -c .config/.eslintrc.yml tcf_website/static/
discord:
if: ${{ always() }}
needs: [pylint, django, eslint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # needed for PRs
- name: Send a message to tCF Discord Server when all jobs are finished
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_URL_CI }}
PYLINT_RESULT: ${{ needs.pylint.result }}
DJANGO_RESULT: ${{ needs.django.result }}
ESLINT_RESULT: ${{ needs.eslint.result }}
PR_NUMBER: ${{ github.event.number}}
PR_TITLE: ${{ github.event.pull_request.title }}
DJANGO_COVERAGE: ${{ needs.django.outputs.code-coverage }}
LATEST_PR_COMMIT: ${{ github.event.after }}
run: |
bash ./scripts/notify-checks-result.sh
shell: bash