Skip to content

End-to-end Tests

End-to-end Tests #400

Workflow file for this run

name: "End-to-end Tests"
on:
workflow_dispatch:
schedule:
- cron: 15 2 * * MON-FRI
env:
MVN_MULTI_THREADED_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version --threads 1C
JAVA_VERSION: 17
jobs:
end-to-end-tests:
permissions:
contents: read
strategy:
fail-fast: false
matrix:
environment: [ canary, production ]
exclude:
- environment: production
# secret-name: AI_CORE_PRODUCTION
include:
- environment: canary
secret-name: AI_CORE_CANARY
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v5
- name: "Setup java"
uses: actions/setup-java@v5
with:
distribution: "sapmachine"
java-version: ${{ env.JAVA_VERSION }}
cache: 'maven'
- name: "Build SDK"
run: |
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} clean install -DskipTests -DskipFormatting"
mvn $MVN_ARGS
- name: "Run tests"
id: run_tests
run: |
if [ "${{ matrix.environment }}" = "canary" ]; then
export AICORE_SERVICE_KEY='${{ secrets.AI_CORE_CANARY }}'
else
export AICORE_SERVICE_KEY='${{ secrets.AI_CORE_PRODUCTION }}'
fi
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} surefire:test -pl :spring-app -DskipTests=false"
mvn $MVN_ARGS "-Daicore.landscape=${{ matrix.environment }}" | tee mvn_output.log # tee writes to both the console and a file
awk '/Results:/, /----/' mvn_output.log > test_error.log || true # true ensures the step doesn't fail if no match is found.
ERROR_MSG=$(cat test_error.log | tail +4 | head -n -4 | awk '{gsub(/"/, "\\\""); printf "%s\\n", $0}') # Slack formatting
echo "$ERROR_MSG"
echo "error_message=$ERROR_MSG" >> $GITHUB_OUTPUT
if grep -q "BUILD FAILURE" mvn_output.log; then
echo "Maven build failed."
exit 1
elif grep -q "BUILD SUCCESS" mvn_output.log; then
echo "Maven build succeeded."
else
echo "Maven build status unknown."
exit 1
fi
env:
# See "End-to-end test application instructions" on the README.md to update the secret
AI_CORE_PRODUCTION: ${{ secrets.production }}
AI_CORE_CANARY: ${{ secrets.canary }}
- name: "Start Application Locally"
run: |
if [ "${{ matrix.environment }}" = "canary" ]; then
export AICORE_SERVICE_KEY='${{ secrets.AI_CORE_CANARY }}'
else
export AICORE_SERVICE_KEY='${{ secrets.AI_CORE_PRODUCTION }}'
fi
cd sample-code/spring-app
mvn spring-boot:run &
timeout=15
while ! nc -z localhost 8080; do
sleep 1
timeout=$((timeout - 1))
if [ $timeout -le 0 ]; then
echo "Server did not start within 15 seconds."
exit 1
fi
done
env:
# See "End-to-end test application instructions" on the README.md to update the secret
AI_CORE_PRODUCTION: ${{ secrets.production }}
AI_CORE_CANARY: ${{ secrets.canary }}
- name: "Health Check"
# print response body with headers to stdout. q:body only O:print -:stdout S:headers
run: wget -qO- -S localhost:8080
- name: "Slack Notification"
if: failure()
uses: slackapi/[email protected]
with:
webhook: ${{ secrets.SLACK_WEBHOOK }}
webhook-type: incoming-webhook
payload: |
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "⚠️ End-to-end tests failed! 😬 Please inspect & fix by clicking <https://github.com/SAP/ai-sdk-java/actions/runs/${{ github.run_id }}|here>"
- type: "section"
text:
type: "plain_text"
text: "${{ steps.run_tests.outputs.error_message }} "