test: overhaul unit and e2e testing #10
This file contains 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: Pull Request Tests | |
env: | |
PYTHON_VERSION: "3.10" | |
on: | |
pull_request: | |
branches: [ main ] | |
push: | |
branches: [ main ] | |
permissions: | |
pull-requests: write | |
contents: write | |
actions: read | |
checks: write | |
jobs: | |
test_unit: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
- name: Run tests | |
id: run_tests | |
continue-on-error: true | |
run: | | |
uv run pytest test/ > pytest-results.txt | |
- name: Comment PR with test results | |
if: github.event_name == 'pull_request' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const testResults = fs.readFileSync('pytest-results.txt', 'utf8'); | |
const body = `### Test Results | |
\`\`\` | |
${testResults} | |
\`\`\``; | |
// Get existing comments | |
const comments = await github.rest.issues.listComments({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
// Look for an existing test results comment | |
const existingComment = comments.data.find(comment => | |
comment.body.includes('### Test Results') | |
); | |
if (existingComment) { | |
// Update existing comment | |
await github.rest.issues.updateComment({ | |
comment_id: existingComment.id, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}); | |
} else { | |
// Create new comment | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}); | |
} | |
test_e2e: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
- name: install jq | |
run: | | |
sudo apt-get install jq -y | |
- name: build | |
run: | | |
uv build | |
- name: install cli | |
run: | | |
uv run pip install dist/crx_analyzer-0.1.0a3-py3-none-any.whl | |
- name: Run E2E tests | |
run: | | |
uv run pytest -v -m e2e test/test_cli.py | |