Skip to content

Commit 3d8cbba

Browse files
🔨 Add composite action for Django (backend) setups
0 parents  commit 3d8cbba

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.{yml,yaml}]
11+
indent_size = 2

action.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
3+
name: 'Setup Django backend'
4+
description: 'Set up prerequisites for a Maykin Django backend'
5+
6+
inputs:
7+
apt-packages:
8+
description: Any apt packages to install, space-separated
9+
required: false
10+
default: 'gettext postgresql-client'
11+
12+
python-version:
13+
description: Python version, passed to actions/setup-python
14+
required: true
15+
default: '3.10'
16+
17+
optimize-postgres:
18+
description: >
19+
Tune postgres for non-durable but faster tests. Requires 'pg-service' name. Set
20+
to string 'yes' to enable (the default).
21+
required: false
22+
default: 'yes'
23+
24+
pg-service:
25+
description: >
26+
Name of the postgres service. If not specified (the default), no optimization is
27+
done. See 'optimize-postgres'.
28+
required: false
29+
default: ''
30+
31+
npm-ci-flags:
32+
description: Additional arguments for the 'npm ci' command.
33+
required: false
34+
default: ''
35+
36+
runs:
37+
using: 'composite'
38+
steps:
39+
- name: Install OS dependencies
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install --yes ${{ inputs.apt-packages }}
43+
44+
- name: Tune PostgreSQL for test performance
45+
if: ${{ inputs.pg-service != '' && inputs.optimize-postgres == 'yes' }}
46+
run: |
47+
docker exec -i ${{ inputs.pg-service }} bash << EOF
48+
sed -i -e 's/#fsync = on/fsync = off/' /var/lib/postgresql/data/postgresql.conf
49+
sed -i -e 's/#full_page_writes = on/full_page_writes = off/' /var/lib/postgresql/data/postgresql.conf
50+
sed -i -e 's/#synchronous_commit = on/synchronous_commit = off/' /var/lib/postgresql/data/postgresql.conf
51+
sed -i -e 's/shared_buffers = 128MB/shared_buffers = 2GB/' /var/lib/postgresql/data/postgresql.conf
52+
sed -i -e 's/max_wal_size = 1GB/max_wal_size = 4GB/' /var/lib/postgresql/data/postgresql.conf
53+
EOF
54+
55+
docker restart --time=0 ${{ inputs.pg-service }}
56+
57+
# block until container is up and running again
58+
until pg_isready -h 127.0.0.1; do
59+
echo "Waiting for DB to be up again..."
60+
sleep 1
61+
done
62+
63+
echo "Done configuring PostgreSQL for faster tests."
64+
65+
- uses: actions/setup-python@v4
66+
with:
67+
python-version: ${{ inputs.python-version }}
68+
cache: 'pip'
69+
cache-dependency-path: 'requirements/*.txt'
70+
71+
- name: Install backend dependencies
72+
run: |
73+
pip install -r requirements/ci.txt \
74+
--use-pep517 \
75+
--use-feature=no-binary-enable-wheel-cache
76+
77+
# TODO: enable cache
78+
- uses: actions/setup-node@v3
79+
with:
80+
node-version-file: '.nvmrc'
81+
82+
- name: Build frontend
83+
run: |
84+
npm ci ${{ inputs.npm-ci-flags }}
85+
npm run build
86+

0 commit comments

Comments
 (0)