Skip to content

Commit 11ba984

Browse files
authored
Merge pull request #86 from octue/fix-test-matrix
Fix test matrix and update stack
2 parents bd571d7 + 5299b77 commit 11ba984

Some content is hidden

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

52 files changed

+1800
-526
lines changed

.devcontainer/devcontainer.json

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,27 @@
1212
"vscode": {
1313
"settings": {
1414
"[python]": {
15-
"editor.defaultFormatter": "ms-python.black-formatter",
1615
"editor.formatOnSave": true,
1716
"editor.codeActionsOnSave": {
1817
"source.organizeImports": "always",
1918
"source.fixAll": "always"
20-
}
19+
},
20+
"editor.defaultFormatter": "charliermarsh.ruff"
2121
},
22-
"black-formatter.args": ["--line-length", "120"],
23-
"black-formatter.importStrategy": "fromEnvironment",
24-
"isort.args": ["--profile", "black"],
25-
"isort.importStrategy": "fromEnvironment",
2622
"austin.mode": "Wall time",
2723
"editor.defaultFormatter": "esbenp.prettier-vscode",
2824
"editor.formatOnSave": true,
29-
"jupyter.widgetScriptSources": ["jsdelivr.com", "unpkg.com"],
30-
// Line length to match black settings
31-
// Disable specific messages:
32-
// - To find the details do: /usr/local/py-utils/bin/pylint --list-msgs
33-
// - Disable missing-module-docstring (C0114) because we don't document modules routinely, just their members
34-
// - Disable invalid-name (C0103) because pylint thinks that eg 'x', 'df', 'np' are invalid due to their lengths
35-
"pylint.args": [
36-
"--max-line-length=120",
37-
"--disable=missing-module-docstring,invalid-name",
38-
"--load-plugins=pylint_django"
39-
],
25+
"python.locator": "native",
4026
"python.testing.pytestEnabled": true,
4127
"python.testing.unittestEnabled": false,
4228
"terminal.integrated.defaultProfile.linux": "zsh",
43-
// Handle this: https://github.com/microsoft/vscode-python/issues/693
44-
"python.testing.pytestArgs": ["--no-cov"]
29+
"ruff.importStrategy": "fromEnvironment"
4530
},
46-
// Add the IDs of extensions you want installed when the container is created.
31+
32+
// IN ALPHABETIC ORDER: Add the IDs of extensions you want installed when the container is created.
4733
"extensions": [
34+
"4ops.terraform",
35+
"charliermarsh.ruff",
4836
"erikphansen.vscode-toggle-column-selection",
4937
"esbenp.prettier-vscode",
5038
"GitHub.copilot",
@@ -53,38 +41,17 @@
5341
"irongeek.vscode-env",
5442
"ms-python.python",
5543
"ms-python.vscode-pylance",
56-
"ms-python.pylint",
57-
"ms-python.black-formatter",
58-
"ms-python.flake8",
59-
"ms-python.isort",
60-
"ms-toolsai.jupyter",
61-
"ms-toolsai.jupyter-renderers",
62-
"ms-toolsai.jupyter-keymap",
6344
"ms-vsliveshare.vsliveshare",
45+
"ninoseki.vscode-mogami",
6446
"p403n1x87.austin-vscode",
6547
"ritwickdey.liveserver",
66-
"shamanu4.django-intellisense",
67-
"thebarkman.vscode-djaneiro",
68-
"trond-snekvik.simple-rst",
69-
"4ops.terraform"
48+
"tamasfe.even-better-toml"
7049
]
7150
}
7251
},
7352

7453
// Use 'forwardPorts' to make a list of ports inside the container available locally.
75-
"forwardPorts": [
76-
80,
77-
443,
78-
5000,
79-
7045,
80-
7046,
81-
7047,
82-
7048,
83-
7049,
84-
8000,
85-
8001,
86-
8080
87-
],
54+
"forwardPorts": [80, 443, 5000, 7045, 7046, 7047, 7048, 7049, 8000, 8080],
8855

8956
// Use 'postAttachCommand' to run commands after the container is created and attached (ie git is available).
9057
// This is preferential to postCreateCommand as invoking git (eg for private poetry installs or addition of
@@ -112,6 +79,13 @@
11279
"ppa": true,
11380
"version": "os-provided"
11481
},
82+
"ghcr.io/devcontainers/features/git-lfs:1": {
83+
"version": "latest"
84+
},
85+
"ghcr.io/devcontainers/features/github-cli:1": {
86+
"installDirectlyFromGitHubRelease": true,
87+
"version": "latest"
88+
},
11589
"ghcr.io/devcontainers/features/node:1": {
11690
"nodeGypDependencies": false,
11791
"version": "latest"

.devcontainer/docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ services:
1818
environment:
1919
- DATABASE_URL=postgres://postgres_user:postgres_password@localhost/postgres_db
2020
- DJANGO_SETTINGS_MODULE=tests.server.settings
21+
- DATABASE_ENGINE=postgres
2122

2223
# Map the current directory containing code
2324
volumes:
@@ -50,9 +51,15 @@ services:
5051
- POSTGRES_DB=postgres_db
5152
- POSTGRES_USER=postgres_user
5253
- POSTGRES_PASSWORD=postgres_password
54+
volumes:
55+
- postgres_data:/var/lib/postgresql
5356
restart: unless-stopped
5457
healthcheck:
5558
test: ["CMD-SHELL", "pg_isready -U postgres"]
5659
interval: 10s
5760
timeout: 5s
5861
retries: 5
62+
63+
volumes:
64+
postgres_data:
65+
driver: local

.devcontainer/postattach.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/zsh
22

3-
# Install dependencies
3+
4+
# Install dependencies to a cache that persists across devcontainer builds
5+
poetry config cache-dir /workspace/.poetry_cache
46
poetry install
57

68
# Auto set up remote when pushing new branches
@@ -32,5 +34,7 @@ echo 'alias djmm="python manage.py makemigrations"' >> ~/.zshrc
3234
echo 'alias djm="python manage.py migrate"' >> ~/.zshrc
3335
echo 'alias djr="python manage.py runserver"' >> ~/.zshrc
3436
echo 'alias djreset="python manage.py reset_db -c"' >> ~/.zshrc
35-
echo 'alias djs="python manage.py shell_plus"' >> ~/.zshrc
37+
echo 'alias djsh="python manage.py shell_plus"' >> ~/.zshrc
38+
echo 'alias djsm="python manage.py showmigrations"' >> ~/.zshrc
39+
echo 'alias djt="pytest backend/test"' >> ~/.zshrc
3640
echo 'alias dju="python manage.py show_urls"' >> ~/.zshrc

.github/workflows/ci.yml

Lines changed: 98 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,70 @@ on:
2323
default: false
2424

2525
jobs:
26-
run-tests:
26+
check-ahead-of-main:
27+
if: github.ref != 'refs/heads/main'
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Check branch is ahead of main
36+
run: |
37+
if ! git merge-base --is-ancestor origin/main ${{ github.event.pull_request.head.sha }};
38+
then echo "::error::This branch is not up-to-date with the latest main branch commit.";
39+
exit 1; fi
40+
41+
lint:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
47+
- name: Setup python
48+
uses: actions/setup-python@v5
49+
with:
50+
python-version: "3.11"
51+
52+
- name: Install and configure poetry
53+
uses: snok/install-poetry@v1
54+
with:
55+
virtualenvs-create: true
56+
virtualenvs-in-project: true
57+
58+
- name: Setup virtual environment cache
59+
id: cached-poetry-dependencies
60+
uses: actions/cache@v4
61+
with:
62+
path: .venv
63+
key: venv-${{ runner.os }}-3.11-${{ hashFiles('**/poetry.lock') }}
64+
65+
- name: Install dependencies (if not cached)
66+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
67+
run: poetry install --only dev --no-interaction --no-root
68+
69+
- name: Install root project
70+
run: poetry install --no-interaction
71+
72+
- name: Run precommit
73+
run: SKIP=build-docs,check-branch-name poetry run pre-commit run --all-files
74+
75+
test:
2776
if: github.event.pull_request.draft == false
2877
strategy:
29-
fail-fast: true
78+
fail-fast: false
3079
matrix:
31-
python: ["3.11", "3.12", "3.13"]
80+
python-version: ["3.10", "3.11", "3.12"]
81+
django-version: [">=4.2,<4.3", ">=5.0,<5.1"]
3282
os: [ubuntu-latest] # [ubuntu-latest, windows-latest, macos-latest] for full coverage but this gets expensive quickly
33-
runs-on: ${{ matrix.os }}
83+
84+
permissions:
85+
id-token: write
86+
contents: read
87+
88+
env:
89+
DJANGO_SETTINGS_MODULE: tests.server.settings
3490

3591
services:
3692
postgres:
@@ -48,50 +104,71 @@ jobs:
48104
--health-timeout 5s
49105
--health-retries 5
50106
107+
runs-on: ${{ matrix.os }}
108+
51109
steps:
52-
- name: Checkout Repository
53-
uses: actions/checkout@v3
110+
- name: Check out repository
111+
uses: actions/checkout@v4
54112

55-
- name: Setup Python ${{ matrix.python }}
56-
uses: actions/setup-python@v3
113+
- name: Set up python ${{ matrix.python-version }}
114+
id: setup-python
115+
uses: actions/setup-python@v5
57116
with:
58-
python-version: ${{ matrix.python }}
117+
python-version: ${{ matrix.python-version }}
59118

60-
# See the repo of this action for way more advanced caching strategies than used here
61119
- name: Install Poetry
62120
uses: snok/install-poetry@v1
121+
with:
122+
virtualenvs-create: true
123+
virtualenvs-in-project: true
124+
125+
- name: Setup virtual environment cache
126+
id: cached-poetry-dependencies
127+
uses: actions/cache@v4
128+
with:
129+
path: .venv
130+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
63131

64-
# For more advanced configuration see https://github.com/ymyzk/tox-gh-actions
65-
- name: Install tox and plugins
132+
- name: Install dependencies (if not cached)
133+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
134+
run: poetry install --no-interaction --no-root
135+
136+
- name: Install root project
137+
run: poetry install --no-interaction
138+
139+
- name: Install django ${{ matrix.django-version }}
66140
run: |
67-
python -m pip install --upgrade pip
68-
python -m pip install tox==3.24.5 tox-gh-actions==2.9.1 tox-poetry==0.4.1
141+
source .venv/bin/activate
142+
pip install "django${{ matrix.django-version }}"
69143
70144
- name: Setup tmate session [DEBUG]
71145
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true'}}
72146
uses: mxschmitt/action-tmate@v3
73147

74-
# For more advanced configuration see https://github.com/ymyzk/tox-gh-actions
75-
- name: Run tests using tox
76-
run: tox
148+
- name: Run tests
149+
run: poetry run pytest --cov=django_gcp --cov-report=xml
77150

78151
- name: Upload coverage to Codecov
79152
# This seems redundant inside the test matrix but actually isn't, since different
80153
# dependency combinations may cause different lines of code to be hit (e.g. backports)
81-
uses: codecov/codecov-action@v3
154+
uses: codecov/codecov-action@v4
82155
with:
83156
files: coverage.xml
84157
fail_ci_if_error: false
85-
# Token is not required for public repos, but see:
158+
# Token is not strictly required for public repos, but see:
86159
# https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
87160
token: ${{ secrets.CODECOV_TOKEN }}
88161

89-
test-publish:
162+
publish-test:
90163
runs-on: ubuntu-latest
91-
needs: run-tests
164+
needs:
165+
- lint
166+
- check-ahead-of-main
167+
92168
permissions:
93169
id-token: write
94170
contents: read
171+
95172
steps:
96173
- name: Checkout repository
97174
uses: actions/checkout@v4

0 commit comments

Comments
 (0)