Skip to content

Commit 7efb150

Browse files
authored
chore: maintenance (#46)
* refactor: remove unnecessary attribute * chore: add information about MJML * chore: add `include-hidden-files` This is added to `upload-artefacts` GitHub action. * chore: improve playwright CI job fastapi/full-stack-fastapi-template#1335 (comment) * chore: see previous commit * feat: add db healthcheck * chore: bump axios 1.6.2 to 1.7.4 * chore: remove complexity of www * feat: simplify domains * feat: include `FRONTEND_HOST` in CORS origins by default * chore: upgrade FastAPI * refactor: move prestart (migrations) to own container * refactor: move location of scripts * chore: use official Python docker image * feat: use docker compose watch * chore: remove logic for dev deps * chore: add new Dockerfile * feat: add GH Action to lint * refactor: use top level `.env` * feat: auto-generate frontend client * chore: make it fail on errors * test: run tests from Python env * feat: use `uv` to generate client * chore: update GH Actions format * chore: use uv cache * chore: only commit on repo PRs; on forks, show error * fix: error * fix: log output directly to Docker * fix: exclude email-templates * chore: bump astral-sh/setup-uv from 2 to 3 * fix: enable logging for emails by default * refactor: use enc algo from settings * chore: bump rollup * refactor: add `PaginationFooter` component * fix: ignore `.auth` * feat: migrate from Poetry to `uv` * chore: add MailCatcher links * fix: checkout files in CI * fix: improve Playwright CI speed * chore: instructions to install runner * chore: change token name and commit * fix: remove dupe `dependabot.yml` * fix: add environment variables * fix: format backend * fix: missing `STACK_NAME` * fix: use `.env` file * fix: add `.env` files * fix: type errors * fix: add `frontend/.env` * fix: add `.env` file * chore: comment out tests
1 parent 4e1b448 commit 7efb150

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3253
-3244
lines changed

.env.example

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
# domain: this would be set to the production domain with an env var on deployment
1+
# Domain
2+
# This would be set to the production domain with an env var on deployment
3+
# used by Traefik to transmit traffic and aqcuire TLS certificates
24
DOMAIN=localhost
5+
# To test the local Traefik config
6+
# DOMAIN=localhost.davidsha.me
7+
8+
# Used by the backend to generate links in emails to the frontend
9+
FRONTEND_HOST=http://localhost:5173
10+
# In staging and production, set this env var to the frontend host, e.g.
11+
# FRONTEND_HOST=https://dashboard.example.com
312

413
# environment: local, staging, production
514
ENVIRONMENT=local

.github/dependabot.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
version: 2
22
updates:
3-
# github actions
4-
- package-ecosystem: "github-actions"
5-
directory: "/"
3+
# GitHub Actions
4+
- package-ecosystem: github-actions
5+
directory: /
66
schedule:
7-
interval: "daily"
7+
interval: daily
88
commit-message:
9-
prefix: ":arrow_up:"
10-
# python
11-
- package-ecosystem: "pip"
12-
directory: "/"
9+
prefix:
10+
# Python
11+
- package-ecosystem: pip
12+
directory: /
1313
schedule:
14-
interval: "daily"
14+
interval: daily
1515
commit-message:
16-
prefix: ":arrow_up:"
16+
prefix:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Generate Client
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
9+
jobs:
10+
generate-client:
11+
permissions:
12+
contents: write
13+
runs-on: ubuntu-latest
14+
steps:
15+
# For PRs from forks
16+
- uses: actions/checkout@v4
17+
# For PRs from the same repo
18+
- uses: actions/checkout@v4
19+
if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' )
20+
with:
21+
ref: ${{ github.head_ref }}
22+
token: ${{ secrets.REPO_TOKEN }}
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version: lts/*
26+
- uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.10"
29+
- name: Install uv
30+
uses: astral-sh/setup-uv@v3
31+
with:
32+
version: "0.4.15"
33+
enable-cache: true
34+
- name: Install dependencies
35+
run: npm ci
36+
working-directory: frontend
37+
- run: uv sync
38+
working-directory: backend
39+
- run: cp .env.example .env
40+
- run: uv run bash scripts/generate-client.sh
41+
env:
42+
VIRTUAL_ENV: backend/.venv
43+
- name: Add changes to git
44+
run: |
45+
git config --local user.email "[email protected]"
46+
git config --local user.name "github-actions"
47+
git add frontend/src/client
48+
# Same repo PRs
49+
- name: Push changes
50+
if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' )
51+
run: |
52+
git diff --staged --quiet || git commit -m "chore: autogenerate frontend client"
53+
git push
54+
# Fork PRs
55+
- name: Check changes
56+
if: ( github.event_name == 'pull_request' && github.secret_source != 'Actions' )
57+
run: |
58+
git diff --staged --quiet || (echo "Changes detected in generated client, run scripts/generate-client.sh and commit the changes" && exit 1)

.github/workflows/lint-backend.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Lint Backend
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
12+
jobs:
13+
lint-backend:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.10"
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v3
24+
with:
25+
version: "0.4.15"
26+
enable-cache: true
27+
- run: uv run bash scripts/lint.sh
28+
working-directory: backend

.github/workflows/playwright.yml

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Playwright Tests
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88
types:
99
- opened
@@ -16,10 +16,36 @@ on:
1616
default: 'false'
1717

1818
jobs:
19+
changes:
20+
runs-on: ubuntu-latest
21+
# Set job outputs to values from filter step
22+
outputs:
23+
changed: ${{ steps.filter.outputs.changed }}
24+
steps:
25+
- uses: actions/checkout@v4
26+
# For pull requests it's not necessary to checkout the code but for the main branch it is
27+
- uses: dorny/paths-filter@v3
28+
id: filter
29+
with:
30+
filters: |
31+
changed:
32+
- backend/**
33+
- frontend/**
34+
- .env
35+
- docker-compose*.yml
36+
- .github/workflows/playwright.yml
1937
20-
test:
38+
test-playwright:
39+
needs:
40+
- changes
41+
if: ${{ needs.changes.outputs.changed == 'true' }}
2142
timeout-minutes: 60
2243
runs-on: ubuntu-latest
44+
strategy:
45+
matrix:
46+
shardIndex: [1, 2, 3, 4]
47+
shardTotal: [4]
48+
fail-fast: false
2349
steps:
2450
- uses: actions/checkout@v4
2551
- uses: actions/setup-node@v4
@@ -33,35 +59,63 @@ jobs:
3359
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
3460
with:
3561
limit-access-to-actor: true
36-
- name: Install dependencies
37-
run: npm ci
38-
working-directory: frontend
39-
- name: Install Playwright Browsers
40-
run: npx playwright install --with-deps
41-
working-directory: frontend
4262
- run: cp .env.example .env
63+
- run: cp frontend/.env.example frontend/.env
4364
- run: docker compose build
4465
- run: docker compose down -v --remove-orphans
45-
- run: docker compose up -d
4666
- name: Run Playwright tests
47-
run: npx playwright test
48-
working-directory: frontend
67+
run: docker compose run --rm playwright npx playwright test --fail-on-flaky-tests --trace=retain-on-failure --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
4968
- run: docker compose down -v --remove-orphans
50-
- uses: actions/upload-artifact@v4
51-
if: always()
69+
- name: Upload blob report to GitHub Actions Artifacts
70+
if: ${{ !cancelled() }}
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: blob-report-${{ matrix.shardIndex }}
74+
path: frontend/blob-report
75+
include-hidden-files: true
76+
retention-days: 1
77+
78+
merge-playwright-reports:
79+
needs:
80+
- test-playwright
81+
- changes
82+
# Merge reports after playwright-tests, even if some shards have failed
83+
if: ${{ !cancelled() && needs.changes.outputs.changed == 'true' }}
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v4
87+
- uses: actions/setup-node@v4
88+
with:
89+
node-version: 20
90+
- name: Install dependencies
91+
run: npm ci
92+
working-directory: frontend
93+
- name: Download blob reports from GitHub Actions Artifacts
94+
uses: actions/download-artifact@v4
95+
with:
96+
path: frontend/all-blob-reports
97+
pattern: blob-report-*
98+
merge-multiple: true
99+
- name: Merge into HTML Report
100+
run: npx playwright merge-reports --reporter html ./all-blob-reports
101+
working-directory: frontend
102+
- name: Upload HTML report
103+
uses: actions/upload-artifact@v4
52104
with:
53-
name: playwright-report
54-
path: frontend/playwright-report/
105+
name: html-report--attempt-${{ github.run_attempt }}
106+
path: frontend/playwright-report
55107
retention-days: 30
108+
include-hidden-files: true
56109

57110
# https://github.com/marketplace/actions/alls-green#why
58-
e2e-alls-green: # This job does nothing and is only used for the branch protection
111+
alls-green-playwright: # This job does nothing and is only used for the branch protection
59112
if: always()
60113
needs:
61-
- test
114+
- test-playwright
62115
runs-on: ubuntu-latest
63116
steps:
64117
- name: Decide whether the needed jobs succeeded or failed
65118
uses: re-actors/alls-green@release/v1
66119
with:
67120
jobs: ${{ toJSON(needs) }}
121+
allowed-skips: test-playwright

.github/workflows/smokeshow.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Smokeshow
22

33
on:
44
workflow_run:
5-
workflows: [Test]
5+
workflows: [Test Backend]
66
types: [completed]
77

88
jobs:
@@ -14,19 +14,17 @@ jobs:
1414
statuses: write
1515

1616
steps:
17+
- uses: actions/checkout@v4
1718
- uses: actions/setup-python@v5
1819
with:
19-
python-version: '3.9'
20-
20+
python-version: "3.10"
2121
- run: pip install smokeshow
22-
2322
- uses: actions/download-artifact@v4
2423
with:
2524
name: coverage-html
2625
path: backend/htmlcov
2726
github-token: ${{ secrets.GITHUB_TOKEN }}
2827
run-id: ${{ github.event.workflow_run.id }}
29-
3028
- run: smokeshow upload backend/htmlcov
3129
env:
3230
SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage}

.github/workflows/test-backend.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test Backend
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
12+
jobs:
13+
test-backend:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.10"
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v3
24+
with:
25+
version: "0.4.15"
26+
enable-cache: true
27+
- run: cp .env.example .env
28+
- run: docker compose down -v --remove-orphans
29+
- run: docker compose up -d db mailcatcher
30+
- name: Migrate DB
31+
run: uv run bash scripts/prestart.sh
32+
working-directory: backend
33+
- name: Run tests
34+
run: uv run bash scripts/tests-start.sh "Coverage for ${{ github.sha }}"
35+
working-directory: backend
36+
- run: docker compose down -v --remove-orphans
37+
- name: Store coverage files
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: coverage-html
41+
path: backend/htmlcov
42+
include-hidden-files: true
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Test Docker Compose
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
12+
jobs:
13+
14+
test-docker-compose:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- run: cp .env.example .env
20+
- run: cp frontend/.env.example frontend/.env
21+
- run: docker compose build
22+
- run: docker compose down -v --remove-orphans
23+
- run: docker compose up -d --wait backend frontend adminer
24+
- name: Test backend is up
25+
run: curl http://localhost:8000/api/v1/utils/health-check
26+
- name: Test frontend is up
27+
run: curl http://localhost:5173
28+
- run: docker compose down -v --remove-orphans

0 commit comments

Comments
 (0)