From cac29fe6f76fa9393620f2adebfb498db076089d Mon Sep 17 00:00:00 2001 From: tligui_y Date: Wed, 16 Jul 2025 15:44:13 +0200 Subject: [PATCH] Update .gitea/workflows/test.yml --- .gitea/workflows/test.yml | 119 ++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 63 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 9afadf1c1..3f8084d16 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -1,10 +1,10 @@ -name: Run Pytest with Allure and Coverage Reports +name: Run Pytest with HTML and XML Test Reports on: push: - branches: [utils_testing] + branches: [testing_json] pull_request: - + jobs: tests: runs-on: ubuntu-latest @@ -18,7 +18,7 @@ jobs: - name: Show checked out files run: | echo "๐Ÿ“‚ Files in repo root:" - ls -1 | head -n 20 + ls -1 - name: Install Pixi & project dependencies run: | @@ -53,7 +53,7 @@ jobs: exit 1 } - pip install pytest pytest-cov coverage pytest-md-report > pip.log 2>&1 || { + pip install pytest pytest-cov pytest-html pytest-md-report rich > pip.log 2>&1 || { echo "โŒ Python testing tools install failed" cat pip.log | grep -i 'error\|fatal' exit 1 @@ -62,30 +62,9 @@ jobs: echo "โœ… Python tools installed" pip list - - name: Install Java + - name: ๐Ÿงช Extract Pytest Parameters 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 + python log_all_test_params.py - name: Run tests and generate reports run: | @@ -93,64 +72,78 @@ jobs: source venv/bin/activate mkdir -p ci-reports/{allure,coverage,markdown} + set +e + echo "๐Ÿงช Running pytest with coverage and report generation..." pixi run pytest . \ - --cov=slic \ + --continue-on-collection-errors \ + --cov=functions \ --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" - tail -n 20 ci-reports/markdown/raw-test-output.log | grep -i 'error\|fail' || true - } + --capture=no > ci-reports/markdown/raw-test-output.log 2>&1 - 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" - } + exit_code=$? + + set -e + + echo "๐Ÿ“ฆ Pytest exit code: $exit_code" echo "" echo "๐Ÿ“ˆ Generating coverage summary..." - coverage report --format=markdown > ci-reports/markdown/coverage-summary.md && { + coverage report --format=markdown > ci-reports/markdown/coverage-summary.md 2> ci-reports/markdown/coverage-error.log && { echo "โœ… Coverage summary generated" } || { - echo "โš ๏ธ Coverage generation failed" + echo "โš ๏ธ Coverage summary generation failed" + echo "๐Ÿชต Extracting coverage error:" + cat ci-reports/markdown/coverage-error.log | grep -i 'error\|fatal' || echo "No matching error lines" } - { - 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 "" + echo "๐Ÿ“Š Generating tests markdown summary..." + python json_to_md.py \ + --input ci-reports/markdown/pytest-report.json \ + --output ci-reports/markdown/TEST-REPORT.md \ + --log ci-reports/markdown/raw-test-output.log \ + --json ci-reports/markdown/pytest-report.json \ + --exit-code $exit_code > ci-reports/markdown/md-report.log 2>&1 && { + echo "โœ… Tests markdown generated" } || { - echo "โš ๏ธ Tests markdown generation failed" + echo "โš ๏ธ Tests markdown generation failed" + echo "๐Ÿชต Extracting markdown generation error:" + cat ci-reports/markdown/md-report.log | grep -i 'error\|fatal\|traceback' || echo "No matching error lines" } + echo "" + echo "๐ŸŒณ Generating JSON tree view..." + python json_to_tree.py ci-reports/markdown/pytest-report.json > ci-reports/markdown/json-tree-gen.log 2>&1 && { + echo "โœ… JSON tree view generated" + } || { + echo "โŒ JSON tree generation failed" + cat ci-reports/markdown/json-tree-gen.log | grep -i 'error\|fatal\|traceback' || echo "No matching error lines" + } + + echo "๐Ÿงน Cleaning up ci-reports/markdown..." + find ci-reports/markdown -type f ! \( \ + -name 'coverage-summary.md' -o \ + -name 'json-tree-view.txt' -o \ + -name 'pytest-report.json' -o \ + -name 'TEST-REPORT.md' \ + \) -delete + + echo "โœ… Kept only coverage-summary.md, json-tree-view.txt, pytest-report.json, TEST-REPORT.md" + - name: Commit and push reports run: | - echo "๐Ÿ“ค Committing test & coverage reports to slic.git..." + echo "๐Ÿ“ค Committing all test reports to slic.git..." git config user.name "ci-bot" git config user.email "ci-bot@example.com" git add ci-reports/ - git commit -m "CI: update test and coverage reports" || echo "โš ๏ธ Nothing to commit" + git commit -m "CI: update test report and coverage files" || echo "โš ๏ธ Nothing to commit" - echo "๐Ÿš€ Pushing to branch 'utils_testing' on slic.git..." - git push https://ci-token:${{ secrets.CI_TOKEN }}@gitea.psi.ch/tligui_y/slic.git HEAD:utils_testing > push_main.log 2>&1 || { + 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