Skip to content

Commit e8b7e00

Browse files
authored
ci(openapi): fix drf-spectacular job DEV-1177 (#6386)
### 💭 Notes #6287 never worked (see [logs](https://github.com/kobotoolbox/kpi/actions/runs/17979532426/job/51141577133#step:9:31)) for two reasons: - `/dev/tty` doesn't exist in GHAs -> add a workaround - run script through `kobo-install` like locally makes no sense on GHA -> revert to run script directly Also - add bash flags to fail on errors within piping - simplify the job one-value-matrix - run job on manual schema changes ### 👀 Preview steps 1. see the GHA job 2. 🟢 notice that schema is generated normally successfully 3. 🟢 notice that diff check fails, because `main` contains outdated schema file.
1 parent bba7d24 commit e8b7e00

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

.github/filters.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ biome:
2020
- '.github/workflows/biome.yml' # ci
2121

2222
openapi:
23-
- '{kpi,kobo,hub}/**/*.!(md)' # backend
24-
- 'dependencies/**/*.!(md)' # pip
25-
- 'pyproject.toml' # (can affect build/tests)
26-
- '.github/workflows/openapi.yml' # ci
23+
- '{kpi,kobo,hub}/**/*.!(md)' # backend
24+
- 'dependencies/**/*.!(md)' # pip
25+
- 'pyproject.toml' # (can affect build/tests)
26+
- 'static/openapi/*' # output
27+
- 'jsapp/js/api/{models,react-query}/*' # output
28+
- '.github/workflows/openapi.yml' # ci
2729

2830
pytest:
2931
- '{kpi,kobo,hub}/**/*.!(md)' # backend

.github/workflows/openapi.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ jobs:
2323
KOBOFORM_URL: http://kpi
2424
SKIP_TESTS_WITH_CONCURRENCY: 'True'
2525
KPI_SRC_DIR: '.'
26-
strategy:
27-
matrix:
28-
python-version: ['3.10']
2926
services:
3027
postgres:
3128
image: postgis/postgis:14-3.4
@@ -44,10 +41,10 @@ jobs:
4441

4542
- uses: actions/checkout@v5
4643

47-
- name: Set up Python ${{ matrix.python-version }}
44+
- name: Set up Python 3.10
4845
uses: actions/setup-python@v6
4946
with:
50-
python-version: ${{ matrix.python-version }}
47+
python-version: '3.10'
5148

5249
- name: Install pip-tools
5350
run: python -m pip install pip-tools==7.\*
@@ -66,8 +63,12 @@ jobs:
6663
run: pip-sync dependencies/pip/dev_requirements.txt
6764

6865
- name: Generate OpenAPI with drf-spectacular
66+
# GitHub Actions run without a TTY device. This is a workaround to get one,
67+
# based on https://github.com/actions/runner/issues/241#issuecomment-2019042651
68+
# and https://github.com/actions/runner/issues/241#issuecomment-842566950
69+
shell: 'script --return --quiet --log-out /dev/null --command "bash --noprofile --norc -eo pipefail {0}"'
6970
run: |
70-
if ./run.py -cf run --rm kpi ./scripts/generate_api.sh --skip-orval 2>&1 | tee /dev/tty | grep -q "Warning"; then
71+
if ./scripts/generate_api.sh --skip-orval 2>&1 | tee /dev/tty | grep -q "Warning"; then
7172
echo ""
7273
echo "A warning found, aborted! Please treat drf-spectacular warnings as errors and resolve them."
7374
echo "P.S. This is only the first warning. You may want to run the script locally to see all warnings at once."

scripts/generate_api.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WHOAMI=$(whoami)
1212
OWNER=$(ls -ld . | awk '{print $3}')
1313
DESTINATION_FOLDER="${KPI_SRC_DIR}/static/openapi"
1414

15-
# For example, `bash -c`` will run on CI, while `gosu` will run in docker.
15+
# For example, `bash -c` will run on CI, while `gosu` will run in docker.
1616
function run () { bash -c "$*"; }
1717
if [ "$WHOAMI" != "$OWNER" ]; then
1818
echo "FYI: Applied gosu!"

0 commit comments

Comments
 (0)