From 8a99753db50a7418bbe9a268775ef18ed2b5c496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Richez?= Date: Wed, 4 Oct 2023 12:38:20 +0200 Subject: [PATCH] Add a smoke test for the application --- .github/workflows/scala.yml | 4 ++++ .github/workflows/smoke_test.sh | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 .github/workflows/smoke_test.sh diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml index e3e9b28..89a9c48 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/scala.yml @@ -20,3 +20,7 @@ jobs: distribution: 'adopt' - name: Run tests run: sbt test + - name: Smoke test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: .github/workflows/smoke_test.sh diff --git a/.github/workflows/smoke_test.sh b/.github/workflows/smoke_test.sh new file mode 100755 index 0000000..b220b47 --- /dev/null +++ b/.github/workflows/smoke_test.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -euo pipefail + +TRY_COUNT=30 +sbt stage + +cd target/universal/stage + +APPLICATION_SECRET="9w/DBOjdTE?65hO5IzGu_XL5^AiK^>iUZgIF?mYVUbPNjNU[ver>zw[V@zlbb0wu" access_token=$GITHUB_TOKEN bin/lunatech-blog-engine & + +PID=$! +trap "kill $! 2> /dev/null" EXIT + +is_running() { + kill -0 $PID 2> /dev/null +} + +is_responding() { + curl localhost:9000 -s -o /dev/null +} + +for (( count=0; count < $TRY_COUNT; count++ )); do + if ! is_running; then + echo "::error::The application stopped before it could serve a page." + exit 1 + fi + + if is_responding; then + exit 0 + fi + + sleep 3 +done + +echo "::error::Timeout: the application did not serve a page in time." +exit 2