Files
slic/.gitea/workflows/test.yml
T
tligui_y 2a6a237e4e
Run Pytest with Allure and Coverage Reports / tests (push) Successful in 38s
Update .gitea/workflows/test.yml
2025-07-14 15:42:04 +02:00

162 lines
5.6 KiB
YAML

name: Run Pytest with Allure and Coverage Reports
on:
push:
branches: [testing_json]
pull_request:
jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Show checked out files
run: |
echo "📂 Files in repo root:"
ls -1 | head -n 20
- name: Install Pixi & project dependencies
run: |
echo "🔧 Installing Pixi..."
curl -fsSL https://pixi.sh/install.sh | bash > pixi.log 2>&1 || {
echo "❌ Pixi download failed"
cat pixi.log | grep -i 'error\|fatal'
exit 1
}
echo "$HOME/.pixi/bin" >> $GITHUB_PATH
export PATH="$HOME/.pixi/bin:$PATH"
pixi install > pixi-install.log 2>&1 || {
echo "❌ Pixi project dependencies failed"
cat pixi-install.log | grep -i 'error\|fatal'
exit 1
}
echo "✅ Pixi installed"
pixi list
- name: Install Python test/report tools
run: |
echo "🐍 Setting up Python environment..."
python -m venv venv
source venv/bin/activate
pip install -U pip > pip.log 2>&1 || {
echo "❌ pip upgrade failed"
cat pip.log | grep -i 'error\|fatal'
exit 1
}
pip install pytest pytest-cov coverage pytest-md-report > pip.log 2>&1 || {
echo "❌ Python testing tools install failed"
cat pip.log | grep -i 'error\|fatal'
exit 1
}
echo "✅ Python tools installed"
pip list
- name: Install Java
run: |
echo "☕ Installing Java..."
sudo apt update > java.log 2>&1 && sudo apt install -y openjdk-11-jdk >> java.log 2>&1 || {
echo "❌ Java installation failed"
cat java.log | grep -i 'error\|fatal'
exit 1
}
echo "✅ Java installed"
java -version
- name: Install Allure CLI
run: |
echo "📊 Installing Allure..."
curl -sL https://github.com/allure-framework/allure2/releases/download/2.27.0/allure-2.27.0.tgz | tar -xz > allure.log 2>&1 || {
echo "❌ Allure download failed"
cat allure.log | grep -i 'error\|fatal'
exit 1
}
sudo mv allure-2.27.0 /opt/allure
sudo ln -s /opt/allure/bin/allure /usr/local/bin/allure
echo "✅ Allure installed"
allure --version
- name: Run tests and generate reports
run: |
echo "🚀 Running tests and generating reports..."
source venv/bin/activate
mkdir -p ci-reports/{allure,coverage,markdown}
echo "🧪 Running pytest with coverage and report generation..."
pixi run pytest . \
--continue-on-collection-errors \
--cov=slic \
--cov-report=xml:ci-reports/coverage/coverage.xml \
--cov-report=html:ci-reports/coverage/ \
--alluredir=allure-results \
--json-report \
--json-report-file=ci-reports/markdown/pytest-report.json \
--capture=no > ci-reports/markdown/raw-test-output.log 2>&1 && {
echo "✅ Pytest completed"
echo ""
echo "📄 Markdown: ci-reports/markdown/test-report.md"
echo ""
echo "📦 JSON: ci-reports/markdown/pytest.json"
} || {
echo ""
echo "⚠️ Some tests failed"
grep -E '^(FAILED|ERROR|XFAIL|XPASS|SKIPPED) tests[\\/]' ci-reports/markdown/raw-test-output.log || true
}
echo ""
echo "📊 Generating Allure report..."
allure generate allure-results -o ci-reports/allure --clean > /dev/null 2>&1 && {
echo "✅ Allure report generated"
} || {
echo "⚠️ Allure generation failed"
}
echo ""
echo "📈 Generating coverage summary..."
coverage report --format=markdown > ci-reports/markdown/coverage-summary.md && {
echo "✅ Coverage summary generated"
} || {
echo "⚠️ Coverage generation failed"
}
{
echo ""
echo "📊 Generating tests markdown summary..."
python json_to_md.py \
--input ci-reports/markdown/pytest-report.json \
--output ci-reports/markdown/TEST-REPORT.md \
--allure-dir ci-reports/allure/data/test-cases
echo "✅ Tests markdown generated"
} || {
echo "⚠️ Tests markdown generation failed"
}
- name: Commit and push reports
run: |
echo "📤 Committing test & coverage reports to slic.git..."
git config user.name "ci-bot"
git config user.email "ci-bot@example.com"
git add ci-reports/markdown/TEST-REPORT.md ci-reports/markdown/pytest-report.json
git commit -m "CI: update test and coverage reports" || echo "⚠️ Nothing to commit"
echo "🚀 Pushing to branch 'testing_json' on slic.git..."
git push https://ci-token:${{ secrets.CI_TOKEN }}@gitea.psi.ch/tligui_y/slic.git HEAD:testing_json > push_main.log 2>&1 || {
echo "❌ Push to main repo failed"
cat push_main.log | grep -i 'error\|fatal\|refused'
exit 1
}
echo "✅ Reports pushed to https://gitea.psi.ch/tligui_y/slic/ci-reports/"
env:
CI_TOKEN: ${{ secrets.CI_TOKEN }}