E2E Tests #537
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: E2E Tests | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - swov1/** | |
| schedule: | |
| - cron: '0 2 * * *' # Run at 2 AM UTC every day | |
| workflow_dispatch: | |
| jobs: | |
| e2e-tests: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: golang:1.23-alpine | |
| env: | |
| SWO_STAGE_API_TOKEN: ${{ secrets.SWO_API_TOKEN }} | |
| PUBLIC_SWO_API_STAGE_URL: ${{ secrets.PUBLIC_SWO_API_STAGE_URL }} | |
| SLACK_WEBHOOK_URL: ${{ secrets.SWO_PUBLIC_API_WEBHOOK }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Python | |
| run: | | |
| apk add --no-cache python3 py3-pip | |
| python3 -m venv venv | |
| . venv/bin/activate | |
| pip install pyyaml | |
| - name: Replace query time placeholders in YAML | |
| run: | | |
| . venv/bin/activate | |
| python3 replace_env_in_yaml.py swov1/.speakeasy/tests.arazzo.yaml | |
| - name: Install Speakeasy CLI | |
| run: | | |
| wget -q https://github.com/speakeasy-api/speakeasy/releases/download/v1.631.4/speakeasy_linux_amd64.zip | |
| unzip -o speakeasy_linux_amd64.zip -d /usr/local/bin | |
| chmod +x /usr/local/bin/speakeasy | |
| - name: Install curl | |
| run: apk add --no-cache curl | |
| - name: Install jq | |
| run: apk add --no-cache jq | |
| - name: Install bash | |
| run: apk add --no-cache bash | |
| - name: Run Speakeasy codegen | |
| env: | |
| SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }} | |
| run: | | |
| speakeasy run --minimal | |
| - name: Run E2E tests (non-scheduled) | |
| if: github.event_name != 'schedule' | |
| run: | | |
| cd swov1 | |
| go test -v ./tests | |
| - name: Run E2E tests and notify Slack (scheduled) | |
| if: github.event_name == 'schedule' | |
| shell: bash | |
| run: | | |
| cd swov1 | |
| TEST_OUTPUT_FILE=$(mktemp) | |
| go test -v ./tests 2>&1 | tee "$TEST_OUTPUT_FILE" || true | |
| TEST_SUMMARY=$(awk ' | |
| function trim(s) { | |
| sub(/^[\n]+/, "", s) | |
| sub(/[\n]+$/, "", s) | |
| return s | |
| } | |
| /^=== RUN/ { | |
| testname=$3 | |
| collecting=1 | |
| lines="" | |
| skip_first=1 | |
| next | |
| } | |
| collecting && /^--- PASS:/ { | |
| collecting=0 | |
| lines="" | |
| next | |
| } | |
| collecting && /^--- FAIL:/ { | |
| print testname ": FAILED" | |
| if (lines != "") { | |
| print "> ```\n" trim(lines) "\n```" | |
| } | |
| collecting=0 | |
| lines="" | |
| next | |
| } | |
| collecting && !/^--- PASS:/ && !/^--- FAIL:/ && !/^=== RUN/ { | |
| if (skip_first) { | |
| skip_first=0 | |
| next | |
| } | |
| sub(/^[ \t]+/, "", $0) | |
| lines = lines $0 "\n" | |
| next | |
| } | |
| ' "$TEST_OUTPUT_FILE") | |
| # Extract duration from last FAIL or ok line | |
| DURATION=$(grep -E '^(FAIL|ok)\s' "$TEST_OUTPUT_FILE" | tail -1 | awk '{print $NF}') | |
| if [ -n "$TEST_SUMMARY" ]; then | |
| SUMMARY_TEXT="$TEST_SUMMARY" | |
| else | |
| SUMMARY_TEXT="" | |
| fi | |
| if [ -n "$TEST_SUMMARY" ]; then | |
| STATUS="FAILED" | |
| STATUS_EMOJI=":x:" | |
| else | |
| STATUS="PASSED" | |
| STATUS_EMOJI=":white_check_mark:" | |
| fi | |
| RUN_URL="https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | |
| PAYLOAD=$(jq -n --arg status "$STATUS" --arg emoji "$STATUS_EMOJI" --arg run_url "$RUN_URL" --arg duration "$DURATION" --arg summary "$SUMMARY_TEXT" ' | |
| { | |
| text: "\($emoji) *Nightly SWO SDK GO tests: \($status)*\nDuration: \($duration)\nSee details: \($run_url)\n\($summary)" | |
| } | |
| ') | |
| curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" $SLACK_WEBHOOK_URL | |
| exit 0 |