Skip to content

Commit

Permalink
improve Setup / Documentation / CI (#8)
Browse files Browse the repository at this point in the history
improve ci
  • Loading branch information
pfouque authored Feb 13, 2023
1 parent a506f7e commit f3d150a
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
updates:

updates:
- package-ecosystem: github-actions
directory: /
schedule:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ jobs:
- name: Check out
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry
- uses: snok/install-poetry@v1
with:
version: 1.3.2
virtualenvs-create: true
virtualenvs-in-project: true

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: poetry

- name: Install requirements
run: poetry install
Expand Down
21 changes: 4 additions & 17 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,8 @@ jobs:
- name: Check out
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install pre-commit
run: pip install pre-commit

- name: Cache pre-commit tools
uses: actions/cache@v3
with:
key:
pre-commit-${{ runner.os }}-${{ steps.setup_python.outputs.python-version}}-${{
hashFiles('.pre-commit-config.yaml') }}
path: ~/.cache/pre-commit

- name: Run pre-commit
run: pre-commit run --all-files
uses: pre-commit/[email protected]

- uses: pre-commit-ci/[email protected]
if: always()
15 changes: 7 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- uses: snok/install-poetry@v1
with:
version: 1.3.2
virtualenvs-create: true
virtualenvs-in-project: true

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.2.2
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
cache: poetry

- name: Build project
run: poetry build
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,31 @@ jobs:
strategy:
fail-fast: false
matrix:
# NOTE: https://github.com/jefftriplett/python-github-actions-matrix-demo/
python-version: ["3.8", "3.9", "3.10", "3.11"]
django-version: ["3.2", "4.0", "4.1", "4.2a1"]
anymail-version: ["8.4", "8.5", "8.6", "9.0"]
anymail-version: ["8.6", "9.0"]

steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry
- uses: snok/install-poetry@v1
with:
version: 1.3.2
virtualenvs-create: true
virtualenvs-in-project: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: poetry


- name: Ensure Python version ${{ matrix.python-version }}
# https://github.com/actions/setup-python/issues/425
run: poetry env use ${{ matrix.python-version }}

- name: Install requirements
run: poetry install

Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/upgrade_precommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Pre-commit auto-update

on:
# every month
schedule:
- cron: "0 0 1 * *"
# on demand
workflow_dispatch:

jobs:
auto-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2

- uses: browniebroke/pre-commit-autoupdate-action@main

- uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-hooks
title: Update pre-commit hooks
commit-message: "chore: update pre-commit hooks"
body: Update versions of pre-commit hooks to latest version.
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# anymail-history - Email History for Django Anymail
# anymail-history - Email History (database storage) for [Django Anymail](https://anymail.dev/)

[![CI tests](https://github.com/pfouque/django-anymail-history/actions/workflows/test.yml/badge.svg)](https://github.com/pfouque/django-anymail-history/actions/workflows/test.yml)

[![codecov](https://codecov.io/github/pfouque/django-anymail-history/branch/master/graph/badge.svg?token=GWGDR6AR6D)](https://codecov.io/github/pfouque/django-anymail-history)

[![Documentation](https://img.shields.io/static/v1?label=Docs&message=READ&color=informational&style=plastic)](https://anymail-history.github.io/anymail-history/)

[![Documentation](https://img.shields.io/static/v1?label=Docs&message=READ&color=informational&style=plastic)](https://github.com/pfouque/django-anymail-history#settings)
[![MIT License](https://img.shields.io/static/v1?label=License&message=MIT&color=informational&style=plastic)](https://github.com/pfouque/anymail-history/LICENSE)

Keep history of all emails sent by Django Anymail
Keep history of all emails sent by [Django Anymail](https://anymail.dev/)

## Introduction

anymail-history implements database storage for Django Anymail.

## Resources

- Full documentation: SOON
- Package on PyPI: [https://pypi.org/project/anymail-history/](https://pypi.org/project/anymail-history/)
- Project on Github: [https://github.com/pfouque/django-anymail-history](https://github.com/pfouque/django-anymail-history)

Expand All @@ -35,11 +31,14 @@ anymail-history implements database storage for Django Anymail.

## How to

1. Install
1. [Install Anymail](https://anymail.dev/en/stable/quickstart/)

2. Install
```
$ pip install "django-anymail[mailgun]" "django-anymail-history"
$ pip install "django-anymail-history"
```
2. [Configure Anymail](https://github.com/anymail/django-anymail/#anymail-1-2-3)
3. Register anymail_history in your list of Django applications:
```
INSTALLED_APPS = [
# ...
Expand All @@ -48,11 +47,14 @@ anymail-history implements database storage for Django Anymail.
# ...
]
```
3. Enjoy!
4. Then migrate the app to create the database table
```manage.py migrate```
5. 🎉 Voila!
## settings
## Settings
You can add settings to your project’s settings.py either as a single ANYMAIL dict, or by breaking out individual settings prefixed with ANYMAIL_. So this settings dict:
You can add settings to your project’s settings.py either as a single `ANYMAIL` dict, or by breaking out individual settings prefixed with ANYMAIL_. So this settings dict:
```
ANYMAIL = {
Expand All @@ -69,7 +71,6 @@ ANYMAIL_STORE_HTML = True
- `ANYMAIL_STORE_FAILED_SEND`: (default: False) Store message even if esp didn't returned a message-id.
- `ANYMAIL_STORE_HTML`: (default: False) Store html alternatives.
- `ANYMAIL_RENDER_HTML`: (default: True) Generate html alternatives.
## Contribute
Expand Down Expand Up @@ -133,6 +134,8 @@ $ poetry shell

#### CI

There is a `.github/workflows/lint.yml` file that can be used as a baseline to define and ensure coding rules on Github.
- `.github/workflows/lint.yml`: defines and ensure coding rules on Github.

- `.github/workflows/test.yml`: Runs tests on all compatible combinations of Django (3.2+) & Anymail(8.4+), Python (3.8+)in a Github matrix.

There is a `.github/workflows/test.yml` file that can be used as a baseline to run all of the tests on Github. This file runs the oldest LTS (3.2), newest (4.1), and head of the main Django branch.
- `.github/workflows/coverage.yml`: Calculates the coverage on an up to date version.
15 changes: 4 additions & 11 deletions anymail_history/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from __future__ import annotations

from typing import Any

from django.contrib import admin
from django.http import HttpRequest

from .models import MessageEvent, SentMessage


class ReadonlyInline(admin.TabularInline):
can_delete = False
show_change_link = False
extra = 0

Expand All @@ -26,7 +23,8 @@ def has_change_permission(

class MessageEventInline(ReadonlyInline):
model = MessageEvent
readonly_fields = fields = ("event_name", "created_on")
fields = ("event_name", "created_on")
readonly_fields = fields
ordering = ["-created_on"]


Expand All @@ -47,14 +45,9 @@ def has_change_permission(
) -> bool:
return False

def get_actions(self, request: HttpRequest) -> dict[str, Any]:
actions = super().get_actions(request)
if "delete_selected" in actions:
del actions["delete_selected"]
return actions


class SentMessageInline(ReadonlyInline):
model = SentMessage
readonly_fields = fields = ("message_id", "subject", "status")
fields = ("message_id", "subject", "status")
readonly_fields = fields
ordering = ["-created_on"]
47 changes: 43 additions & 4 deletions anymail_history/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Generated by Django 3.2.16 on 2022-12-08 04:45

from __future__ import annotations
# Generated by Django 4.1.6 on 2023-02-12 16:46

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = []
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
Expand Down Expand Up @@ -41,6 +42,14 @@ class Migration(migrations.Migration):
("content_html", models.TextField(editable=False, null=True)),
("status", models.CharField(editable=False, max_length=256)),
("recipient_email", models.EmailField(editable=False, max_length=254)),
(
"recipient",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
Expand Down Expand Up @@ -69,4 +78,34 @@ class Migration(migrations.Migration):
),
],
),
migrations.AddIndex(
model_name="sentmessage",
index=models.Index(
fields=["created_on"], name="anymail_his_created_22d036_idx"
),
),
migrations.AddIndex(
model_name="sentmessage",
index=models.Index(
fields=["message_id"], name="anymail_his_message_1731a8_idx"
),
),
migrations.AddIndex(
model_name="sentmessage",
index=models.Index(
fields=["recipient_email"], name="anymail_his_recipie_b46581_idx"
),
),
migrations.AddIndex(
model_name="messageevent",
index=models.Index(
fields=["created_on"], name="anymail_his_created_04c5bf_idx"
),
),
migrations.AddIndex(
model_name="messageevent",
index=models.Index(
fields=["event_name"], name="anymail_his_event_n_63f45f_idx"
),
),
]
58 changes: 0 additions & 58 deletions anymail_history/migrations/0002_initial.py

This file was deleted.

Loading

0 comments on commit f3d150a

Please sign in to comment.