From 0f268bb91bdf4d12ec8b0b88eb353bbb7b6685fb Mon Sep 17 00:00:00 2001 From: SimonKonar Date: Sat, 26 Oct 2024 15:00:43 +0200 Subject: [PATCH 1/4] add script that wait till the url is active --- .github/scripts/wait-for-url.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/scripts/wait-for-url.sh diff --git a/.github/scripts/wait-for-url.sh b/.github/scripts/wait-for-url.sh new file mode 100644 index 0000000..8e8570d --- /dev/null +++ b/.github/scripts/wait-for-url.sh @@ -0,0 +1,14 @@ +#!/bin/bash -e + +URL=$1 +START_EPOCH="$(date +"%s")" + +eclipsed() { + EPOCH="$(date +"%s")" + echo $((EPOCH - START_EPOCH)) +} + +# wait at maximum 120 seconds +while [[ ($(eclipsed) -lt 120) && ("$(curl -s -o /dev/null -w '%{response_code}' "$URL")" != "200") ]]; do + sleep 2 +done \ No newline at end of file From b0810466243cfa9faff40a699f5d9a0ca604f07f Mon Sep 17 00:00:00 2001 From: SimonKonar Date: Sat, 26 Oct 2024 15:11:37 +0200 Subject: [PATCH 2/4] feat: add Makefile for testing --- Makefile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3f6b6e2 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +PYTHON_INTERPRETER = python3 +PYTEST_COMMAND = $(PYTHON_INTERPRETER) -m pytest +PYTEST_ARGS = -v -p no:cacheprovider --cov-report=xml --cov=./ + +.PHONY: test setup clean validate +setup: requirements.txt ## Install required packages + pip install -r requirements.txt +test: setup ## Run unit test + $(PYTEST_COMMAND) $(PYTEST_ARGS) test/unit +integration: setup ## Run integration test + docker run --name blaze --rm -d -e JAVA_TOOL_OPTIONS=-Xmx2g -p 8080:8080 samply/blaze:latest + .github/scripts/wait-for-url.sh http://localhost:8080/health + $(PYTEST_COMMAND) $(PYTEST_ARGS) test/service + docker stop blaze +clean: + rm -rf __pycache__ \ No newline at end of file From 01bccfb62e4ff33ccadc2e675bcd6423d9216d05 Mon Sep 17 00:00:00 2001 From: SimonKonar Date: Sat, 26 Oct 2024 15:15:13 +0200 Subject: [PATCH 3/4] feat: add CI for Testing --- .github/workflows/build.yml | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a9d888c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,76 @@ +name: CI build & test + +on: + push: + branches: [ "master" ] + pull_request: + + +jobs: + py-lint: + name: Lint + continue-on-error: true + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + cache: 'pip' + + - name: Install python dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run pylint + run: pylint --recursive=y . + + unit-tests: + name: Unit tests + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + cache: 'pip' + + - name: Run unit tests + run: make test + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + flags: unit + + integration-tests: + needs: unit-tests + name: Integration tests + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + cache: 'pip' + + - name: Run integration tests + run: make integration + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + flags: integration \ No newline at end of file From 57b2c991957389026822698ded0f12391d91639d Mon Sep 17 00:00:00 2001 From: SimonKonar Date: Sat, 26 Oct 2024 15:15:40 +0200 Subject: [PATCH 4/4] rename the file --- .github/workflows/{build.yml => test.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{build.yml => test.yml} (98%) diff --git a/.github/workflows/build.yml b/.github/workflows/test.yml similarity index 98% rename from .github/workflows/build.yml rename to .github/workflows/test.yml index a9d888c..70fa63b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: CI build & test +name: CI test on: push: