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

apply django-twc-package template #137

Merged
merged 7 commits into from
Feb 10, 2024
Merged
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
26 changes: 26 additions & 0 deletions .copier/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: v2024.8
_src_path: gh:westerveltco/django-twc-package
author_email: josh@joshthomas.dev
author_name: Josh Thomas
current_version: 0.3.0
django_versions:
- "3.2"
- "4.2"
- "5.0"
docs_domain: westervelt.dev
github_owner: westerveltco
github_repo: django-email-relay
module_name: email_relay
package_description:
Centralize and relay email from multiple distributed Django projects
to an internal SMTP server via a database queue.
package_name: django-email-relay
python_versions:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
test_django_main: true
versioning_scheme: SemVer
10 changes: 6 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{{J,j}ustfile,.{J,j}ustfile,{*.{py,rst,ini,md}}}]
[{,.}{j,J}ustfile]
indent_size = 4

[*.{py,rst,ini,md}]
indent_size = 4
indent_style = space

[*.py]
line_length = 120
multi_line_output = 3

[*.{css,html,js,json,sass,scss,yml,yaml}]
[*.{css,html,js,json,jsx,sass,scss,svelte,ts,tsx,yml,yaml}]
indent_size = 2
indent_style = space

[*.md]
trim_trailing_whitespace = false
Expand Down
Empty file added .env.example
Empty file.
6 changes: 5 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ updates:
interval: weekly
timezone: America/Chicago
labels:
- "dependabot"
- dependabot
groups:
gha:
patterns:
- "*"
81 changes: 5 additions & 76 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ name: release
on:
release:
types: [created]
workflow_dispatch:
inputs:
pypi:
description: "Publish to PyPI"
required: false
default: true
type: boolean
docker:
description: "Publish to GHCR"
required: false
default: true
type: boolean

jobs:
check:
Expand All @@ -39,16 +27,14 @@ jobs:

- name: OK
if: ${{ (contains(steps.latest-test-result.outputs.result, 'success')) }}
run: |
exit 0
run: exit 0

- name: Fail
if: ${{ !contains(steps.latest-test-result.outputs.result, 'success') }}
run: |
exit 1
run: exit 1

pypi:
if: ${{ github.event_name == 'release' || inputs.pypi }}
if: ${{ github.event_name == 'release' }}
runs-on: ubuntu-latest
needs: check
environment: release
Expand All @@ -60,7 +46,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12

- name: Install dependencies
run: |
Expand All @@ -71,62 +57,5 @@ jobs:
run: |
hatch build

- if: ${{ github.event_name == 'workflow_dispatch' }}
name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

- if: ${{ github.event_name != 'workflow_dispatch' }}
name: Publish to PyPI
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

docker:
if: ${{ github.event_name == 'release' || inputs.docker }}
runs-on: ubuntu-latest
needs: check
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=pep440,pattern={{version}}
type=pep440,pattern={{major}}.{{minor}}
type=pep440,pattern={{major}}
type=sha,prefix=sha-
type=raw,value=latest,enable={{is_default_branch}}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and publish Docker image
uses: docker/build-push-action@v5
with:
context: .
file: .dockerfiles/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: test

on:
push:
branches: main
branches: [main]
pull_request:

concurrency:
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
python-versions: "3.8"

- name: Run mypy
run: nox --session mypy
run: nox --session "mypy"

coverage:
runs-on: ubuntu-latest
Expand All @@ -87,4 +87,4 @@ jobs:
python-versions: "3.8"

- name: Run coverage
run: nox --session coverage
run: nox --session "coverage"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ dist-ssr
# Editor directories and files
.vscode/*
!.vscode/extensions.json
!.vscode/*.example
.idea
.DS_Store
*.suo
Expand Down
29 changes: 23 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.11
python: python3.8

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -14,14 +14,14 @@ repos:
rev: 1.15.0
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
args: [--target-version, "3.2"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.0
rev: v0.1.3
hooks:
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--fix]
- id: ruff-format

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
Expand All @@ -32,7 +32,7 @@ repos:
- black==22.12.0

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
rev: v3.0.3
hooks:
- id: prettier
# lint the following with prettier:
Expand All @@ -43,3 +43,20 @@ repos:
# - yaml
# ignore any minified code
files: '^(?!.*\.min\..*)(?P<name>[\w-]+(\.[\w-]+)*\.(js|jsx|ts|tsx|yml|yaml|css))$'

- repo: https://github.com/djlint/djLint
rev: v1.34.1
hooks:
- id: djlint-reformat-django
- id: djlint-django

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.11.0
hooks:
- id: pretty-format-toml
args: [--autofix]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.15
hooks:
- id: validate-pyproject
1 change: 0 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

Expand Down
14 changes: 14 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"recommendations": [
"charliermarsh.ruff",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
"monosans.djlint",
"ms-python.black-formatter",
"ms-python.pylint",
"ms-python.python",
"ms-python.vscode-pylance",
"skellock.just",
"tamasfe.even-better-toml"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"editor.formatOnSave": true,
"files.associations": {
"Justfile": "just"
},
"ruff.organizeImports": true,
"[django-html][handlebars][hbs][mustache][jinja][jinja-html][nj][njk][nunjucks][twig]": {
"editor.defaultFormatter": "monosans.djlint"
}
}
91 changes: 12 additions & 79 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project attempts to adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- A `_email_relay_version` field to `RelayEmailData` to track the version of the schema used to serialize the data. This should allow for future changes to the schema to be handled more gracefully.

## [0.3.0]

### Added

- Support for Django 5.0.

### Removed

- Support for Django 4.1.

## [0.2.1]

### Fixed

- Migration 0002 was not being applied to the `default` database, which is the norm when running the relay in Docker.

## [0.2.0] - **YANKED**

This release has been yanked from PyPI due to a bug in the migration that was not caught.

**This release involves migrations.** Please read below for more information.

### Added
<!--
## [${version}]
### Added - for new features
### Changed - for changes in existing functionality
### Deprecated - for soon-to-be removed features
### Removed - for now removed features
### Fixed - for any bug fixes
### Security - in case of vulnerabilities
[${version}]: https://github.com/westerveltco/django-email-relay/releases/tag/v${version}
-->

- A `RelayEmailData` dataclass for representing the `Message.data` field.
- Documentation in the package's deprecation policy about the road to 1.0.0.
- Complete test coverage for all of the public ways of sending emails that Django provides.

### Changed

- **Breaking**: The internal JSON schema for the `Message.data` field has been updated to bring it more in line with all of the possible fields provided by Django's `EmailMessage` and `EmailMultiAlternatives`. This change involves a migration to update the `Message.data` field to the new schema. This is a one-way update and cannot be rolled back. Please take care when updating to this version and ensure that all projects using `django-email-relay` are updated at the same time. See the [updating](https://django-email-relay.westervelt.dev/en/latest/updating.html) documentation for more information.
- The internal `AppSettings` dataclass is now a `frozen=True` dataclass.

## [0.1.1]

### Added

- Moved a handful of common `Message` queries and actions from the `runrelay` management command to methods on the `MessageManager` class.

### Fixed

- The relay service would crash if requests raised an `Exception` during the healthcheck ping. Now it will log the exception and continue processing the queue.

## [0.1.0]

Initial release!

### Added

- An email backend that stores emails in a database ala a Message model rather than sending them via SMTP or other means.
- Designed to work seamlessly with Django's built-in ways of sending emails.
- A database backend that routes writes to the Message model to a separate database.
- A Message model that stores the contents of an email.
- The Message model stores the contents of the email as a JSONField.
- Attachments are stored in the database, under the 'attachments' key in the JSONField.
- Should be able to handle anything that Django can by default.
- A relay service intended to be run separately, either as a standalone Docker image or as a management command within a Django project.
- A Docker image is provided for the relay service. Currently only PostgreSQL is supported as a database backend.
- A management command is provided for the relay service. Any database backend supported by Django should work (minus SQLite which doesn't make sense for a relay service).
- The relay service can be configured with a healthcheck url to ensure it is running.
- Initial documentation.
- Initial tests.
- Initial CI/CD (GitHub Actions).
## [Unreleased]

### New Contributors!

- Josh Thomas <josh@joshthomas.dev> (maintainer)
- Jeff Triplett <@jefftriplett>

### Thanks ❤️

Big thank you to the original authors of [`django-mailer`](https://github.com/pinax/django-mailer) for the inspiration and for doing the hard work of figuring out a good way of queueing emails in a database in the first place.

[unreleased]: https://github.com/westerveltco/django-email-relay/compare/v0.2.1...HEAD
[0.1.0]: https://github.com/westerveltco/django-email-relay/releases/tag/v0.1.0
[0.1.1]: https://github.com/westerveltco/django-email-relay/releases/tag/v0.1.1
[0.2.0]: https://github.com/westerveltco/django-email-relay/releases/tag/v0.2.0
[0.2.1]: https://github.com/westerveltco/django-email-relay/releases/tag/v0.2.1
[0.3.0]: https://github.com/westerveltco/django-email-relay/releases/tag/v0.3.0
[unreleased]: https://github.com/westerveltco/django-email-relay/commits/main/
Loading
Loading