Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit
Browse files Browse the repository at this point in the history
* main:
  ⬛ Black (#93)
  🕸 VSCode Debugger (#85)
  🎬 Workflow Actions (#76)
  • Loading branch information
mrharpo committed Nov 6, 2023
2 parents 5792214 + ea179cb commit 87a58f4
Show file tree
Hide file tree
Showing 30 changed files with 360 additions and 101 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OV_DB_ENGINE=django.db.backends.postgresql
OV_DB_HOST=0.0.0.0
OV_DB_PORT=5432
OV_DB_NAME=postgres
OV_DB_USER=postgres
OV_DB_PASSWORD=""
19 changes: 19 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 🪂 Deploy

on:
push:
branches:
- main
pull_request:
branches:
- main
release:
types: [published, edited, prereleased]
workflow_dispatch:

jobs:
build:
name: 🔨 Build and deploy docker image
uses: WGBH-MLA/.github/.github/workflows/build.yml@main
with:
target: production
21 changes: 21 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 🧪 Integration Tests

on: [push, pull_request, workflow_dispatch]

jobs:
tests:
name: ⚗️ Application Tests
uses: WGBH-MLA/.github/.github/workflows/pytest-with-postgres.yml@main
secrets: inherit
with:
pdm_args: -G test,ci
pytest_args: -n auto --nbmake -ra -s
pg_db: ov-test

lint:
name: 👕 Lint
uses: WGBH-MLA/.github/.github/workflows/lint.yml@main

black:
name: 🖤 Black
uses: WGBH-MLA/.github/.github/workflows/black.yml@main
17 changes: 0 additions & 17 deletions .github/workflows/ci.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: 🏛 Publish to PyPi
on:
workflow_dispatch:
push:
tags:
- '*'

jobs:
build:
name: 📦 Build package
runs-on: ubuntu-latest
steps:
- name: 📰 Checkout
uses: actions/checkout@v3

- name: 📲 Setup PDM
uses: pdm-project/setup-pdm@v3
id: setup-python
with:
python-version: 3.x

- name: 🚚 Install dependencies
run: pdm install --prod

- name: 🏗️ Build package
run: pdm build

- name: 🛫 Export build files
uses: actions/upload-artifact@v3
with:
name: dist
path: dist

publish:
name: 🗞 Publish package
needs: build
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- name: 🛬 Download artifacts
uses: actions/download-artifact@v3

- name: 🗞 Publish package
uses: pypa/gh-action-pypi-publish@release/v1
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 📦 Release

on:
milestone:
types: [closed]
workflow_dispatch:

jobs:
release:
name: 📝 Draft Release
uses: WGBH-MLA/.github/.github/workflows/draft_release.yml@main
12 changes: 12 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 🛍 Update dependencies
# On Wednesdays, we update our dependencies.

on:
schedule:
- cron: 0 12 * * 3
workflow_dispatch:

jobs:
update:
name: 🦿 Update dependencies
uses: WGBH-MLA/.github/.github/workflows/update.yml@main
14 changes: 9 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
__pycache__
*.pyc
.DS_Store
/venv/

# Database
db/
# Virtual environment
.venv

# Environment files
# Environment variable files
.env
.db
!.env.example

# VS Code
.vscode/
!.vscode/settings.json
!.vscode/launch.json
64 changes: 64 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"inputs": [
{
"id": "numWorkers",
"type": "promptString",
"default": "4",
"description": "Number of Gunicorn workers to run"
}
],
"configurations": [
{
"name": "OV Wagtail - Django dev server",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"0.0.0.0:8000"
],
"django": true,
"justMyCode": false
},
{
"name": "OV Wagtail - Gunicorn",
"type": "python",
"request": "launch",
"program": "gunicorn",
"args": [
"-w ${input:numWorkers}",
"-b 0.0.0.0:4000",
"ov-wag.wsgi:applications",
],
"django": true,
"justMyCode": false
},
{
"name": "Run Migrations",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"migrate",
"--noinput"
],
"django": true,
"justMyCode": false
},
{
"name": "Run Tests",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"test",
],
"django": true,
"justMyCode": false
},
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"-v",
],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
}
3 changes: 1 addition & 2 deletions dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ services:
- db
environment:
OV_DB_HOST: db
# OV_DB_PASSWORD:
env_file:
- .env
db:
env_file:
- .db
- .env
30 changes: 14 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ services:
build:
context: .
target: base
image: ov-wag
# Use the `image` property to run a prebuilt image from GHCR instead of building locally. Requires disabling the `build` section above.
# image: ghcr.io/wgbh-mla/ov-wag:main
volumes:
- ./:/app/
entrypoint: /app/docker_entrypoints/dev.sh
Expand All @@ -15,20 +16,17 @@ services:
delay: 5s
max_attempts: 3
window: 5s
wagtail-tests:
build:
context: .
target: test
image: ov-tests
volumes:
- ./:/app/
entrypoint: /app/docker_entrypoints/test.sh
environment:
- OV_DB_ENGINE=django.db.backends.sqlite3
- OV_DB_NAME=testdb
db:
image: postgres:14.2-alpine
volumes:
- ./db:/var/lib/postgresql/data:Z
user: ${UID}:${GID}
image: postgres:16-alpine
restart: always
ports:
- 5432:5432
environment:
- POSTGRES_DB=${OV_DB_NAME}
- POSTGRES_USER=${OV_DB_USER}
- POSTGRES_PASSWORD=${OV_DB_PASSWORD}
volumes:
- db:/var/lib/postgresql/data

volumes:
db:
19 changes: 15 additions & 4 deletions exhibits/management/commands/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ def handle(self, old_name, new_name, models, *args, **options):
# Rename model
old_name = old_name[0]
new_name = new_name[0]
cursor.execute("UPDATE django_content_type SET app_label='{}' WHERE app_label='{}'".format(new_name, old_name))
cursor.execute("UPDATE django_migrations SET app='{}' WHERE app='{}'".format(new_name, old_name))
cursor.execute(
"UPDATE django_content_type SET app_label='{}' WHERE app_label='{}'".format(
new_name, old_name
)
)
cursor.execute(
"UPDATE django_migrations SET app='{}' WHERE app='{}'".format(
new_name, old_name
)
)

for model in models:
cursor.execute("ALTER TABLE {old_name}_{model_name} RENAME TO {new_name}_{model_name}".format(
old_name=old_name, new_name=new_name, model_name=model))
cursor.execute(
"ALTER TABLE {old_name}_{model_name} RENAME TO {new_name}_{model_name}".format(
old_name=old_name, new_name=new_name, model_name=model
)
)
19 changes: 11 additions & 8 deletions exhibits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,20 @@ class ExhibitPage(Page):
]

content_panels = Page.content_panels + [
MultiFieldPanel([
FieldPanel('cover_image'),
FieldPanel('hero_image'),
], heading='Images'),
MultiFieldPanel(
[
FieldPanel('cover_image'),
FieldPanel('hero_image'),
],
heading='Images',
),
FieldPanel('body', classname='collapsed'),
InlinePanel('authors', heading='Author(s)'),
InlinePanel(
'other_exhibits',
heading='Other Exhibits',
max_num=3,
)
'other_exhibits',
heading='Other Exhibits',
max_num=3,
),
]

api_fields = [
Expand Down
1 change: 0 additions & 1 deletion exhibits/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class ExhibitPageFactory(PageFactory):

cover_image = SubFactory(ImageChooserBlockFactory)
hero_image = SubFactory(ImageChooserBlockFactory)
# other_exhibits =
Expand Down
1 change: 1 addition & 0 deletions exhibits/tests/test_exhibit_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ..models import ExhibitPage
from .factories import ExhibitPageFactory


# Create your tests here.
class ExhibitPageTests(TestCase):
def test_exhibit_page_factory(self):
Expand Down
5 changes: 2 additions & 3 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.api import APIField


class HomePage(Page):
body = RichTextField(blank=True)

content_panels = Page.content_panels + [
FieldPanel('body', classname="full"),
]

api_fields = [
APIField('body')
]
api_fields = [APIField('body')]
5 changes: 5 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import os
import sys

from dotenv import load_dotenv

# take environment variables from .env.
load_dotenv()

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ov_wag.settings.dev")

Expand Down
Loading

0 comments on commit 87a58f4

Please sign in to comment.