ci(tests): retry transient platform errors (#39) #23
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: Test Documentation Code Snippets | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'text-to-speech/*.py' | |
| - 'text-to-speech/*.js' | |
| - 'text-to-speech/*.sh' | |
| - 'speech-to-text/*.py' | |
| - 'speech-to-text/*.js' | |
| - 'speech-to-text/*.sh' | |
| - 'speech-to-text/getting-started/samples/**' | |
| - 'docs/tests/**' | |
| - '.github/workflows/test-docs-snippets.yml' | |
| pull_request: | |
| paths: | |
| - 'text-to-speech/*.py' | |
| - 'text-to-speech/*.js' | |
| - 'text-to-speech/*.sh' | |
| - 'speech-to-text/*.py' | |
| - 'speech-to-text/*.js' | |
| - 'speech-to-text/*.sh' | |
| - 'docs/tests/**' | |
| - '.github/workflows/test-docs-snippets.yml' | |
| schedule: | |
| # Weekly Monday 9am UTC — catch API breaking changes | |
| - cron: '0 9 * * 1' | |
| workflow_dispatch: | |
| jobs: | |
| test-snippets: | |
| name: Run docs snippet tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: pip install requests pytest websockets | |
| - name: Run test suite | |
| env: | |
| SMALLEST_API_KEY: ${{ secrets.SMALLEST_API_KEY }} | |
| run: pytest docs/tests/test_snippets.py -v --tb=short | |
| - name: Run TTS quickstart script | |
| env: | |
| SMALLEST_API_KEY: ${{ secrets.SMALLEST_API_KEY }} | |
| run: | | |
| python text-to-speech/quickstart-python.py | |
| [ -f output.wav ] && echo "TTS quickstart: OK ($(stat -c%s output.wav) bytes)" || exit 1 | |
| - name: Run STT quickstart script | |
| env: | |
| SMALLEST_API_KEY: ${{ secrets.SMALLEST_API_KEY }} | |
| run: | | |
| python speech-to-text/transcribe-python.py | |
| # WebSocket STT was previously not exercised by CI — that's how the | |
| # finalize-vs-close_stream bug (PR #35) hid for so long. The script | |
| # downloads a sample WAV, streams it, and prints the assembled | |
| # full transcript on is_last=true. Bounded by the 90s timeout in | |
| # case close_stream fails to trigger is_last. | |
| - name: Run STT WebSocket script | |
| timeout-minutes: 2 | |
| env: | |
| SMALLEST_API_KEY: ${{ secrets.SMALLEST_API_KEY }} | |
| run: | | |
| out=$(python speech-to-text/websocket-python.py) | |
| echo "$out" | |
| echo "$out" | grep -q "Full Transcript:" || { echo "missing Full Transcript line"; exit 1; } | |
| echo "$out" | grep -q "Pulse API" || { echo "transcript content missing"; exit 1; } | |
| # mic-input-python.py needs microphone hardware which CI runners | |
| # do not have. We at least verify the script imports and parses, | |
| # so a syntax error or stale import surface gets caught. | |
| - name: Syntax-check STT mic script | |
| run: python -c "import ast; ast.parse(open('speech-to-text/mic-input-python.py').read())" | |
| - name: Notify Slack on failure | |
| if: failure() | |
| uses: slackapi/slack-github-action@v2.0.0 | |
| with: | |
| webhook: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| webhook-type: incoming-webhook | |
| payload: | | |
| { | |
| "text": "Cookbook docs snippet tests failed — cc <!subteam^S0A79T4QPJT>", | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "*Cookbook Code Snippet Tests Failed* :x:\n\nOne or more documentation code snippets in the cookbook are broken.\n\n*Trigger:* `${{ github.event_name }}` on `${{ github.ref_name }}`\n*Run:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View logs>\n\ncc <!subteam^S0A79T4QPJT>" | |
| } | |
| } | |
| ] | |
| } |