Skip to content

E2E Tests

E2E Tests #11

Workflow file for this run

name: E2E Tests
on:
# Run on demand via workflow_dispatch
workflow_dispatch:
inputs:
test_username:
description: "Twitter username for testing (without @)"
required: false
default: "X"
test_user_id:
description: "Twitter user ID for testing"
required: false
default: "783214"
# Run on schedule (e.g., daily at midnight UTC)
schedule:
- cron: "0 0 * * *"
# Run on push to main (optional - can be removed if too expensive)
push:
branches: [main]
paths:
- "src/**"
- "tests/e2e/**"
- ".github/workflows/e2e-tests.yml"
concurrency:
group: e2e-${{ github.ref }}
cancel-in-progress: true
env:
SCRAPEBADGER_API_KEY: ${{ secrets.SCRAPEBADGER_API_KEY }}
SCRAPEBADGER_BASE_URL: ${{ secrets.SCRAPEBADGER_BASE_URL || 'https://scrapebadger.com' }}
jobs:
e2e:
name: E2E Tests
runs-on: ubuntu-latest
# Only run if we have the API key secret
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || (github.event_name == 'push' && github.repository == 'scrapebadger/scrapebadger-python') }}
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Set up Python 3.12
run: uv python install 3.12
- name: Install dependencies
run: uv sync --extra dev
- name: Check API key is set
run: |
if [ -z "$SCRAPEBADGER_API_KEY" ]; then
echo "::error::SCRAPEBADGER_API_KEY secret is not set"
exit 1
fi
echo "API key is configured"
- name: Run E2E tests
env:
TEST_USERNAME: ${{ github.event.inputs.test_username || 'X' }}
TEST_USER_ID: ${{ github.event.inputs.test_user_id || '783214' }}
# Optional: Additional test data can be configured here
# TEST_TWEET_ID: ${{ secrets.TEST_TWEET_ID }}
# TEST_LIST_ID: ${{ secrets.TEST_LIST_ID }}
# TEST_COMMUNITY_ID: ${{ secrets.TEST_COMMUNITY_ID }}
run: |
uv run --frozen pytest tests/e2e -v --tb=short -x
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-test-results
path: |
.pytest_cache/
retention-days: 7
notify:
name: Notify on failure
needs: e2e
runs-on: ubuntu-latest
if: failure() && github.event_name == 'schedule'
steps:
- name: Create issue on failure
uses: actions/github-script@v7
with:
script: |
const title = `E2E Tests Failed - ${new Date().toISOString().split('T')[0]}`;
const body = `
## E2E Test Failure
The scheduled E2E tests have failed.
**Workflow Run:** [View Run](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})
Please investigate and fix any issues.
`;
// Check if an issue with this title already exists (to avoid duplicates)
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'e2e-failure'
});
const existingIssue = issues.data.find(issue => issue.title === title);
if (!existingIssue) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['e2e-failure', 'bug']
});
}