From 496d536081da1e5a7ecbcc13a95dfdd2f330b84a Mon Sep 17 00:00:00 2001 From: Mads Nylund <73914541+MadsNyl@users.noreply.github.com> Date: Sat, 21 Sep 2024 12:02:02 +0200 Subject: [PATCH] Swagger GitHub Action (#860) * added github action for checking if Swagger is up * new action * try another * tried implementing check for container * added curl to docker image * added check if swagger is up * test if swagger does not get status code 200 * added ?format=openai to trigger error * checking that the request is working * updated CHANGELOG.md --- .github/workflows/ci.yaml | 35 +++++++++++++++++++++++++++++++++++ CHANGELOG.md | 3 +++ compose/Dockerfile | 2 ++ 3 files changed, 40 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f6babc08e..4f3389b07 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -74,5 +74,40 @@ jobs: - name: Check for unstaged migrations run: docker compose run --rm web python manage.py makemigrations --check --no-input + - name: Tear down the Stack + run: docker compose down + + swagger: + runs-on: ubuntu-latest + steps: + + - name: Checkout Code Repository + uses: actions/checkout@v4 + + - name: Build the Stack + run: docker compose build + + - name: Run the Stack + run: docker compose up -d + + - name: Wait for Docker container to be up + run: | + retries=10 + until docker compose exec web curl -f http://localhost:8000/ || [ $retries -eq 0 ]; do + echo "Waiting for container to be up..." + retries=$((retries - 1)) + sleep 5 + done + + - name: Make HTTP Request to Swagger + run: | + status_code=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:8000/swagger/?format=openapi) + if [ "$status_code" -eq 200 ]; then + echo "Swagger UI is up" + else + echo "Failed to reach Swagger UI, status code: $status_code" + exit 1 + fi + - name: Tear down the Stack run: docker compose down \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 591e7d997..5ee78df7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + # CHANGELOG ## Tegnforklaring @@ -14,6 +15,8 @@ ## Neste versjon +- ⚡**Swagger**. La til en GitHub Action for å verifisere at Swagger er oppe og går. +- ✨**Swagger**. API dokumentasjon er nå tilgjengelig med Swagger. - ⚡**Profil**. Endret rekkefølge på tidligere arrangementer slik at nyeste kommer først. ## Versjon 2024.09.14 diff --git a/compose/Dockerfile b/compose/Dockerfile index 3e7579d93..f9e738323 100644 --- a/compose/Dockerfile +++ b/compose/Dockerfile @@ -12,6 +12,8 @@ RUN apt-get update \ && apt-get install -y build-essential \ # mysqlclient dependencies && apt-get install -y default-libmysqlclient-dev \ + # curl for making HTTP requests + && apt-get install -y curl \ # cleaning up unused files && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ && rm -rf /var/lib/apt/lists/*