Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WF CI/CD Github #34

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Node CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
git submodule init
git submodule update
sudo apt-get install yarn
yarn install
yarn build
env:
CI: true
32 changes: 32 additions & 0 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Python application

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Pylint
run: |
# list out files that are in directory and working tree
# grep -v will exclude the files being considered for pylint
# grep -E will matches files having .py extension
# This command will help to pass required python files to pylint along with pylint_djanog plugin
# Pylint with -E option will display only if there is any error
git ls-files | grep -v 'migrations' | grep -v 'settings.py' | grep -v 'manage.py' | grep -E '.py$' |
xargs pylint -E --load-plugins=pylint_django
#- name: Test with pytest
# run: |
# pip install pytest
# pytest
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[TYPECHECK]
ignored-classes=__proxy__
26 changes: 15 additions & 11 deletions apps/api/senders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from django.conf import settings
from django.utils.translation import gettext as _
from sendgrid import *
from sendgrid.helpers.mail import *
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail, Email, Attachment, Personalization, Substitution, Category

from apps.api.qrcode import gen_qrcode
from .models import Attendee, Event

sg = sendgrid.SendGridAPIClient(apikey=settings.SENDGRID_API_KEY)
sg = SendGridAPIClient(apikey=settings.SENDGRID_API_KEY)
templates = settings.SENDGRID_TEMPLATES


Expand All @@ -27,7 +27,8 @@ def send_registration_mail(attendee: Attendee, event: Event):
mail.add_attachment(attachment1)

personalization = Personalization()
personalization.add_substitution(Substitution("%first_name%", attendee.name.split()[0]))
personalization.add_substitution(Substitution(
"%first_name%", attendee.name.split()[0]))
personalization.add_substitution(Substitution("%event_name%", event.name))
personalization.add_to(Email(attendee.email, attendee.name))
mail.add_personalization(personalization)
Expand Down Expand Up @@ -60,20 +61,22 @@ def send_certificate_mail(name, email, event, cpf=None):
event_date = event.event_day.event.formated_dates
event_min_percent = event.event_day.event.certificate_minimum_time


cpf_text = _(', bearer of the registry number %(cpf)s,') % {'cpf': cpf} if cpf else ''
cpf_text = _(', bearer of the registry number %(cpf)s,') % {
'cpf': cpf} if cpf else ''
data = {'name': name, 'event': event.name, 'cpf': cpf_text, 'event_date': event_date,
'event_place': event_place, 'event_duration': event_duration,
'event_min_percent': event_min_percent}

certificate_data = event.certificate_model.generate_certificate(data)

attachment1.content = base64.b64encode(certificate_data.read()).decode('ascii')
attachment1.content = base64.b64encode(
certificate_data.read()).decode('ascii')
attachment1.filename = template['FILENAME']
mail.add_attachment(attachment1)

personalization = Personalization()
personalization.add_substitution(Substitution("%first_name%", name.split()[0]))
personalization.add_substitution(
Substitution("%first_name%", name.split()[0]))
personalization.add_substitution(Substitution("%event_name%", event.name))
personalization.add_to(Email(email, name))
mail.add_personalization(personalization)
Expand All @@ -82,7 +85,7 @@ def send_certificate_mail(name, email, event, cpf=None):
response = sg.client.mail.send.post(request_body=mail.get())
return True
except Exception as e:
print(e.body)
print(response.body)
raise e


Expand All @@ -95,7 +98,8 @@ def send_no_certificate_mail(name, email, event):
mail.add_category(Category(template['CATEGORY']))

personalization = Personalization()
personalization.add_substitution(Substitution("%first_name%", name.split()[0]))
personalization.add_substitution(
Substitution("%first_name%", name.split()[0]))
personalization.add_substitution(Substitution("%event_name%", event.name))
personalization.add_to(Email(email, name))
mail.add_personalization(personalization)
Expand All @@ -104,5 +108,5 @@ def send_no_certificate_mail(name, email, event):
response = sg.client.mail.send.post(request_body=mail.get())
return True
except Exception as e:
print(e.body)
print(response.body)
raise e
8 changes: 8 additions & 0 deletions jararaca/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .settings import *

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:'
}
}
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
DJANGO_SETTINGS_MODULE=jararaca.test_settings
addopts = --nomigrations --cov=. --cov-report=html
14 changes: 12 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ django-extensions==2.1.4
django-localflavor==2.1
django-sslserver==0.20
django-webpack-loader==0.6.0
djangorestframework~>3.9.1
djangorestframework>=3.9.1
gunicorn==19.9.0
idna==2.7
Pillow==5.3.0
Expand All @@ -23,7 +23,17 @@ PyQRCode==1.2.1
python-http-client==3.1.0
pytz==2018.9
sendgrid==5.6.0
six==1.11.0
six==1.12.0
sqlparse==0.2.4
whitenoise==4.1.2
XlsxWriter==1.1.2
# test and cov
coverage==4.5.2
pytest
pytest-django
pytest-cov
# lint
pylint==2.3.0
pylint-django==2.0.6
pylint-plugin-utils==0.5