-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (166 loc) Β· 6.84 KB
/
test-services-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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Do not edit! This file was generated via the /lib/py_monorepo_manager
# Any manual changes to this file will eventually be overwritten by CI
#
# This CI workflow will run on every push to a branch that has an open pull request
# not in draft mode.
name: "test-services/api"
# cancel previous runs if the branch is updated.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, review_requested]
paths:
- .github/workflows/test-services-api.yml
- services/api/**
- lib/py_carlos_database/**
- lib/py_edge_interface/**
- lib/py_edge_device/**
- lib/py_edge_server/**
- lib/py_dev_dependencies/**
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
useCache:
description: 'Activate caching'
required: true
default: 'yes'
type: choice
options:
- yes
- no
jobs:
test:
timeout-minutes: 8
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Set up - Checkout services/api
with:
ref: ${{ github.head_ref }}
- name: Set up - Set git credentials
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Cache the installation of Poetry itself, e.g. the next step. This prevents the workflow
# from installing Poetry every time, which can be slow. Note the use of the Poetry version
# number in the cache key, and the "-0" suffix: this allows you to invalidate the cache
# manually if/when you want to upgrade Poetry, or if something goes wrong. This could be
# mildly cleaner by using an environment variable, but I don't really care.
- name: Set up - Cache Poetry 1.7.1
uses: actions/cache@v4
with:
path: ~/.local
key: python-3.11-poetry-1.7.1
# If you wanted to use multiple Python versions, you'd have specify a matrix in the job and
# reference the matrix python version here.
- uses: actions/setup-python@v5
name: Set up - Install Python 3.11
with:
python-version: 3.11
# Install Poetry. You could do this manually, or there are several actions that do this.
# `snok/install-poetry` seems to be minimal yet complete, and really just calls out to
# Poetry's default install script, which feels correct. I pin the Poetry version here
# because Poetry does occasionally change APIs between versions and I don't want my
# actions to break if it does.
#
# The key configuration value here is `virtualenvs-in-project: true`: this creates the
# venv as a `.venv` in your testing directory, which allows the next step to easily
# cache it.
- name: Set up - Install Poetry 1.7.1
uses: snok/install-poetry@v1
with:
version: 1.7.1
virtualenvs-create: true
virtualenvs-in-project: true
# Cache your dependencies (i.e. all the stuff in your `pyproject.toml`). Note the cache
# key: if you're using multiple Python versions, or multiple OSes, you'd need to include
# them in the cache key. I'm not, so it can be simple and just depend on the poetry.lock.
- name: Set up - Cache services/api dependencies
id: cache-deps
uses: actions/cache@v4
with:
path: ./services/api/.venv
key: api-${{ hashFiles('./services/api/poetry.lock', './lib/py_carlos_database/**/*.py', './lib/py_edge_interface/**/*.py', './lib/py_edge_device/**/*.py', './lib/py_edge_server/**/*.py', './lib/py_dev_dependencies/**/*.py', './lib/py_carlos_database/**/*.sql', './lib/py_edge_interface/**/*.sql', './lib/py_edge_device/**/*.sql', './lib/py_edge_server/**/*.sql', './lib/py_dev_dependencies/**/*.sql', './lib/py_carlos_database/poetry.lock', './lib/py_edge_interface/poetry.lock', './lib/py_edge_device/poetry.lock', './lib/py_edge_server/poetry.lock', './lib/py_dev_dependencies/poetry.lock')}}-3.11-1.7.1
# Install dependencies. `--no-root` means "install all dependencies but not the project
# itself", which is what you want to avoid caching _your_ code. The `if` statement
# ensures this only runs on a cache miss.
- name: Set up - Install services/api dependencies
run: poetry install --no-interaction --no-root --all-extras
working-directory: ./services/api
- name: Set up - Get changed files
if: ${{ !cancelled() }}
id: detect-changed-files
uses: tj-actions/changed-files@v42
with:
files_yaml: |
pyproject_toml:
- services/api/pyproject.toml
poetry_lock:
- services/api/poetry.lock
python_files:
- services/api/carlos/**/*.py
# installing the repository is required to register any pytest plugins
# that are defined by the repository
- name: Set up - Install project
run: poetry install --no-interaction --all-extras
working-directory: ./services/api
- name: Auto - format
run: make format
working-directory: ./services/api
- name: Lint - ruff
if: ${{ !cancelled() }}
run: make ruff
working-directory: ./services/api
- name: Type checking - mypy
if: ${{ !cancelled() }}
run: make mypy
working-directory: ./services/api
- name: Test - pytest
if: ${{ !cancelled() }}
run: make pytest
working-directory: ./services/api
- name: Test - coverage
if: ${{ !cancelled() }}
run: make coverage
working-directory: ./services/api
- if: ${{ !cancelled() }}
name: Set up - Install node
uses: actions/setup-node@v4
with:
node-version: 18
- if: ${{ !cancelled() }}
name: Set up - Install yarn
run: corepack enable && yarn set version classic
- if: ${{ !cancelled() }}
name: Set up - Cache dependencies
uses: actions/cache@v4
with:
key: backend-codegen-lock-${{ hashFiles('./yarn.lock') }}
path: ./**/node_modules/*
- if: ${{ !cancelled() }}
name: Set up - Install codegen dependencies
run: yarn install --immutable
- if: ${{ !cancelled() }}
name: Generate - backend openapi spec and client code
run: make api-openapi
- name: Auto - commit pending changes
if: ${{ !cancelled() }}
run: |
git add -A
git commit -m "update services/api" $_EMPTY || exit 0
- name: Auto - push changes
if: ${{ !cancelled() }}
run: |
git pull --rebase
git push origin HEAD:refs/heads/${{ github.head_ref }} || exit 01