-
Notifications
You must be signed in to change notification settings - Fork 9
178 lines (145 loc) · 4.5 KB
/
ci_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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: CI (API)
env:
VENV_PATH: "~/.venv-api"
on:
push:
paths:
- api/**
- .github/workflows/ci_api.yml
pull_request:
paths:
- api/**
- .github/workflows/ci_api.yml
defaults:
run:
working-directory: api
jobs:
code_quality:
name: Code Quality
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11.3'
- name: Cache poetry install
uses: actions/cache@v4
with:
path: ~/.local
key: poetry
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: false
virtualenvs-path: ${{ env.VENV_PATH }}
- name: Cache deps
id: cache-deps
uses: actions/cache@v4
with:
path: ${{ env.VENV_PATH }}
key: venv-api-${{ hashFiles('**/poetry.lock') }}
- name: Install confluent-kafka prerequisites
run: |
sudo apt-get install --yes librdkafka-dev python3-dev
- name: Install psycopg2 prerequisites
run: |
sudo apt-get install --yes build-essential libpq-dev
- name: Install dependencies
run: |
poetry install --no-interaction --no-root
- uses: taiki-e/install-action@just
- uses: taiki-e/install-action@dprint
- name: Lint
# currently cli is not-maintained
run: |
just fmt-check
just lint
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ['3.11.3']
# container operations are only supported on Linux runners
os: [ubuntu-22.04]
services:
# it is hard to setup locally installed postgres,
# such as setting the password.
# TravisCI and build.sr.ht use empty password as default
# but that doesn't work with Github action.
# you need to work with `pg_hba.conf` or using `sudo -u postgres`
# but the latter force you to install every dependency in in root PATH.
postgres:
image: postgres:11
env:
POSTGRES_USER: postgres
# set the password without messing with `pg_hba.conf`
POSTGRES_PASSWORD: postgres
# create default db
POSTGRES_DB: knotdb
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache poetry install
uses: actions/cache@v4
with:
path: ~/.local
key: poetry
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: ${{ env.VENV_PATH }}
- name: Cache deps
id: cache-deps
uses: actions/cache@v4
with:
path: ${{ env.VENV_PATH }}
key: venv-api-${{ hashFiles('**/poetry.lock') }}
- name: Install confluent-kafka prerequisites
run: |
sudo apt-get install --yes librdkafka-dev python3-dev
- name: Install psycopg2 prerequisites
run: |
sudo apt-get install --yes build-essential libpq-dev
- name: Install dependencies
run: |
poetry install --no-interaction --no-root
- uses: taiki-e/install-action@just
- name: Unit tests
run: |
just test-unit
- name: Check DB version
# pass `-h localhost` to use TCP connection. Otherwise, it will talk to locally installed postgres
run: psql -h localhost -p ${{ job.services.postgres.ports[5432] }} -U postgres --version
env:
# to avoid having password prompt
PGPASSWORD: postgres
- name: Create DB schema
run: |
psql -h localhost -p ${{ job.services.postgres.ports[5432] }} -U postgres knotdb < tests/integration/test_schema.sql
env:
PGPASSWORD: postgres
- name: Prepare for Integration tests
run: |
# use default location, instead setting the `RESTKNOT_CONFIG_FILE`
cp config.example.yml config.yml
- name: Integration tests
run: |
just test