From 885956462edf824e18e2177f64b222508066ad7f Mon Sep 17 00:00:00 2001
From: Konrad Mohrfeldt <konrad.mohrfeldt@farbdev.org>
Date: Wed, 23 Mar 2022 01:34:42 +0100
Subject: [PATCH] CI: add autogenerated openapi.yaml file

The CI should now automatically build an openapi.yaml file of the API
schema that is stored as an artifact.
---
 .gitlab-ci.yml | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 479d3083..5ce2cb1e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -7,8 +7,29 @@
       - Dockerfile
 
 stages:
+  - build
   - release
 
+build-openapi-scheme:
+  stage: build
+  image: python:3.9-alpine
+  variables:
+    SECRET_KEY: not-a-very-secret-key
+    DJANGO_SETTINGS_MODULE: steering.settings
+    # steering.settings switches to sqlite if the VIRTUAL_ENV environment
+    # variable is present. It’s probably a good idea to refactor this to
+    # something more explicit.
+    VIRTUAL_ENV: 1
+  before_script:
+    - apk add gcc musl-dev zlib-dev jpeg-dev libmagic
+    - pip install -r requirements.txt
+  script:
+    - python3 -m django spectacular --validate --lang en --file openapi.yaml
+  artifacts:
+    paths:
+      - openapi.yaml
+
+
 docker-push:
   # Use the official docker image.
   image: docker:latest
@@ -32,16 +53,16 @@ docker-push:
       fi
     # TODO: maybe isolate docker build and docker push
     - docker push "$AURA_IMAGE_NAME" --all-tags
-  rules: 
+  rules:
     - *release-rules
     # every commit on master/main branch should trigger a push to docker-hub as unstable without a release
-    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH 
+    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
       exists:
         - Dockerfile
 
 release_job:
   stage: release
-  needs: 
+  needs:
     - docker-push
   image: registry.gitlab.com/gitlab-org/release-cli:latest
   rules: *release-rules
-- 
GitLab