Skip to content

chore(tests): add 1 auto-generated test files #130

chore(tests): add 1 auto-generated test files

chore(tests): add 1 auto-generated test files #130

name: Run Generated Tests
on:
push:
branches:
- auto-generated-tests
pull_request:
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
run-tests:
name: Execute Test Suite
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect test project type
id: detect
run: |
if compgen -G "tests/*.py" > /dev/null; then
echo "type=python" >> $GITHUB_OUTPUT
echo "Detected Python tests"
elif compgen -G "test/**/*.js" > /dev/null; then
echo "type=node" >> $GITHUB_OUTPUT
echo "Detected Node tests"
else
echo "No recognized tests found"
exit 1
fi
- name: Setup Python
if: steps.detect.outputs.type == 'python'
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Run pytest
if: steps.detect.outputs.type == 'python'
run: |
pip install -r requirements.txt pytest pytest-cov pytest-mock
export PYTHONPATH="${GITHUB_WORKSPACE}:$PYTHONPATH"
pytest -q --maxfail=1 --disable-warnings \
--cov=. \
--cov-report=xml:coverage.xml \
--cov-report=html:coverage_html \
--junitxml=junit.xml
- name: Setup Node
if: steps.detect.outputs.type == 'node'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Run vitest
if: steps.detect.outputs.type == 'node'
run: |
npm install
npx vitest run --coverage
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: test-artifacts-${{ github.run_id }}
path: |
coverage.xml
coverage_html/
junit.xml
if-no-files-found: ignore
ensure-pr:
name: Ensure Pull Request Exists
needs: run-tests
if: github.event_name == 'push' && github.ref == 'refs/heads/auto-generated-tests' && needs.run-tests.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Create or update pull request
uses: actions/github-script@v7
with:
script: |
const branch = 'auto-generated-tests';
const base = 'main';
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:${branch}`,
});
if (pulls.length === 0) {
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: branch,
base,
title: 'Auto-generated tests update',
body: `Automated tests push from workflow run ${runUrl}.`,
});
core.info('Opened new pull request.');
} else {
core.info('Pull request already exists.');
}