From b1900ff522c05e5c7fb57c66a0924c89fb8b3bde Mon Sep 17 00:00:00 2001 From: James Gregory Date: Thu, 9 Dec 2021 20:30:18 +1100 Subject: [PATCH] ci: run a server smoke test in the pipeline This verifies the server can launch with all the default settings. --- .github/workflows/main.yml | 21 +++++++++++++++++++++ scripts/smoke-test | 30 ++++++++++++++++++++++++++++++ src/server/server.ts | 4 ++++ 3 files changed, 55 insertions(+) create mode 100755 scripts/smoke-test diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 15bb22cf..ba2a7205 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,6 +10,7 @@ jobs: lint: runs-on: ubuntu-latest name: Lint + timeout-minutes: 5 steps: - uses: actions/checkout@v2 @@ -27,6 +28,7 @@ jobs: unit_test: runs-on: ubuntu-latest name: Unit Test + timeout-minutes: 5 steps: - uses: actions/checkout@v2 @@ -41,9 +43,28 @@ jobs: - run: yarn install - run: yarn test + smoke_test: + runs-on: ubuntu-latest + name: Smoke Test + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v2 + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + - uses: actions/cache@v1 + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: ${{ runner.os }}-yarn- + - run: yarn install + - run: scripts/smoke-test + integration_test: runs-on: ubuntu-latest name: Integration Test + timeout-minutes: 5 steps: - uses: actions/checkout@v2 diff --git a/scripts/smoke-test b/scripts/smoke-test new file mode 100755 index 00000000..576c54f6 --- /dev/null +++ b/scripts/smoke-test @@ -0,0 +1,30 @@ +#!/bin/bash + +# This script launches the Cognito Local server, then polls the server until the /health endpoint +# responds with a 200. If the server doesn't respond in time, or exits with a non-zero code, the +# script will fail. +# +# We run this in CI to prove the actual server can start. This catches some edge-cases where +# everything else passes, but something in the compile produced invalid JavaScript. + +export PORT=59232 +yarn start & +PID=$! + +trap "kill $PID" SIGINT + +PORT=$PORT timeout --foreground -s TERM 30 bash -c \ +'while [[ ${STATUS_RECEIVED} != 200 ]];\ + do STATUS_RECEIVED=$(curl -s -o /dev/null -L -w ''%{http_code}'' http://localhost:$PORT/health) && \ + echo "received status: $STATUS_RECEIVED" && \ + sleep 1;\ +done; +echo success with status: $STATUS_RECEIVED' +CURL_EXIT_CODE=$? + +kill $PID + +if [[ $CURL_EXIT_CODE -ne 0 ]]; then + echo Failed to start in time >&2 + exit 1 +fi \ No newline at end of file diff --git a/src/server/server.ts b/src/server/server.ts index 5dd98601..833e8149 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -55,6 +55,10 @@ export const createServer = ( }); }); + app.get("/health", (req, res) => { + res.status(200).json({ ok: true }); + }); + app.post("/", (req, res) => { const xAmzTarget = req.headers["x-amz-target"];