diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index e8ba6a0..293bb8e 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -34,7 +34,7 @@ jobs: run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - name: Cache dependencies installed with composer - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ env.COMPOSER_CACHE_DIR }} key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/.github/workflows/curl-tester.yml b/.github/workflows/curl-tester.yml new file mode 100644 index 0000000..7b4232b --- /dev/null +++ b/.github/workflows/curl-tester.yml @@ -0,0 +1,21 @@ +name: Run curl tester + +on: + pull_request: + push: + branches: + - 4.0 + +jobs: + run-bash: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Make curl tester executable + run: chmod +x ./test/tester.sh + + - name: Run curl tester + run: ./test/tester.sh diff --git a/test/curl-tester.sh b/test/curl-tester.sh new file mode 100755 index 0000000..40b2246 --- /dev/null +++ b/test/curl-tester.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Bootstrap + +OK='✅' +KO='❌' + +if ! command -v curl > /dev/null 2>&1; then + echo "$KO curl is not installed" + exit 1 +fi + +# Define globals + +body="" +status_code=0 + +# Functions + +send_request() { + response=$(curl -s -w "\n%{http_code}" $1) + + body=$(echo "$response" | sed '$d') + status_code=$(echo "$response" | tail -n 1) +} + +get() { + send_request $1 +} + +post() { + send_request $1 +} + +# Endpoints + +endpoint_home="https://api.dotkernel.net" + +# Tests + +get $endpoint_home + +if echo "$body" | grep -q '{"message":"Welcome to DotKernel API!" }'; then + echo "$OK $endpoint_home: SUCCESS ($status_code)" +else + echo "$KO $endpoint_home: FAILED ($status_code)" + exit 1 +fi