-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (127 loc) · 4.59 KB
/
api.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# This is a matrix GitHub Action workflow for running CI tests on a Django
# project.
#
# Based on https://github.com/snok/install-poetry?tab=readme-ov-file
#
# See:
# https://docs.github.com/en/actions/guides/building-and-testing-python#building-and-testing-python-with-multiple-versions
# https://devguide.python.org/versions/
#
name: API - Tests
on:
# Trigger the workflow during API PRs and when this file changes
pull_request:
paths:
- apps/api/**
- .github/workflows/api.yml
# Allow running the workflow manually
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: Enable tmate debugging (see mxschmitt/action-tmate@v3)
required: false
default: false
jobs:
install-and-cache:
strategy:
fail-fast: true
max-parallel: 4
matrix:
os: [ ubuntu-latest ] # ubuntu-latest, macos-latest
python-version: [ "3.11" ] # "3.10", "3.11", "3.12" or simply ">=3.9,<4.0"
django-version: [ "5" ] # "4", "5"
runs-on: ${{ matrix.os }}
# Service containers to run with `build` job
services:
# Label used to access the service container which is
# running a postgres image from Docker Hub.
postgres:
image: postgres:16.2-bookworm
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: bronco
POSTGRES_DB: postgres
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DB_NAME: postgres
DB_USER: postgres
DB_HOST: postgres
DB_PASSWORD: bronco
DB_PORT: 5432
DB_ENGINE: django.db.backends.postgresql
# All steps should run in the Django app
# subdirectory by default.
defaults:
run:
working-directory: ./apps/api
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: true
- name: Set up python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Debug
run: env | sort
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true
# Enable tmate debugging of manually-triggered workflows if the input option was provided
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction
#----------------------------------------------
# add matrix specifics and run test suite
#----------------------------------------------
- name: Install django ${{ matrix.django-version }}
run: |
poetry add Django@${{ matrix.django-version }}
#--------------------------------------------
# run tests
#--------------------------------------------
- name: Run tests
run: |
# Install the default environment settings. This includes
# the database config for the CI environment (sqlite3).
cp -p .env.example .env
poetry run pytest