From 3cf367828bf87f797d65c0d6b305966ea02b65cc Mon Sep 17 00:00:00 2001 From: tligui_y Date: Mon, 21 Jul 2025 11:48:23 +0200 Subject: [PATCH] Update .gitea/workflows/test.yml --- .gitea/workflows/test.yml | 269 ++------------------------------------ 1 file changed, 13 insertions(+), 256 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index c2b49372..52cf11bf 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -1,262 +1,19 @@ -name: Run Pytest with HTML and XML Test Reports +name: Run CI Tests on: push: - branches: [utils_testing] - pull_request: - + branches: [test_actions_on_utils] + pull_request: + jobs: - tests: + test: 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 - - - 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 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 - } - - echo "โœ… Python tools installed" - pip list - - - name: ๐Ÿงช Extract Pytest Parameters - run: | - python log_all_test_params.py - - - name: Run tests and generate reports - run: | - echo "๐Ÿš€ Running tests and generating reports..." - source venv/bin/activate - mkdir -p ci-reports/{allure,coverage,markdown} - - set +e - - 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/ \ - --json-report \ - --json-report-file=ci-reports/markdown/pytest-report.json \ - --capture=no > ci-reports/markdown/raw-test-output.log 2>&1 - - 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 2> ci-reports/markdown/coverage-error.log && { - echo "โœ… Coverage summary generated" - } || { - 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 \ - --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 "๐Ÿชต 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 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 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 "โŒ 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 }} - - - name: Get wiki commit info - id: info - run: | - short_sha=$(git rev-parse --short HEAD) - commit_msg=$(git log -1 --pretty=%B) - - echo "๐Ÿ” Commit SHA: $short_sha" - echo "๐Ÿ” Commit message: $commit_msg" - - echo "short_sha=$short_sha" >> $GITHUB_OUTPUT - echo "commit_num=$commit_num" >> $GITHUB_OUTPUT - - - name: Clone Gitea Wiki - run: | - echo "๐Ÿ“š Cloning wiki repo: https://gitea.psi.ch/tligui_y/slic.wiki.git" - git clone https://ci-token:${{ secrets.CI_TOKEN }}@gitea.psi.ch/tligui_y/slic.wiki.git wiki > wiki_clone.log 2>&1 || { - echo "โŒ Wiki clone failed" - cat wiki_clone.log | grep -i 'error\|fatal' - exit 1 - } - echo "โœ… Wiki cloned to ./wiki" - - - name: Copy reports into wiki - run: | - # Variables communes - SHORT_SHA=$(git rev-parse --short HEAD) - REPO_URL="https://gitea.psi.ch/tligui_y/slic" - RUN_LINK="${REPO_URL}/actions/runs/${GITHUB_RUN_NUMBER}" - - # 1. Dรฉfinir les noms de fichiers (structure fixe) - TEST_FILE="run-${GITHUB_RUN_NUMBER}-TEST-commit-${SHORT_SHA}.md" - COVERAGE_FILE="run-${GITHUB_RUN_NUMBER}-COVERAGE-commit-${SHORT_SHA}.md" - - # 2. Crรฉer les fichiers de rapports - echo "Creating ${TEST_FILE}..." - echo "## Test Report" > "wiki/${TEST_FILE}" - echo "[View CI Run ${GITHUB_RUN_NUMBER}](${RUN_LINK}) | [Commit ${SHORT_SHA}](${REPO_URL}/commit/${SHORT_SHA})" >> "wiki/${TEST_FILE}" - cat ci-reports/markdown/TEST-REPORT.md >> "wiki/${TEST_FILE}" - - echo "Creating ${COVERAGE_FILE}..." - echo "## Coverage Report" > "wiki/${COVERAGE_FILE}" - echo "[View CI Run ${GITHUB_RUN_NUMBER}](${RUN_LINK}) | [Commit ${SHORT_SHA}](${REPO_URL}/commit/${SHORT_SHA})" >> "wiki/${COVERAGE_FILE}" - cat ci-reports/markdown/coverage-summary.md >> "wiki/${COVERAGE_FILE}" - - HOME_FILE="wiki/Home.md" - TEMP_CONTENT=$(mktemp) - REPORT_LOG="reports.log" - - # Crรฉation du contenu - { - echo "# Test Reports History" - echo "" - echo "## Latest Run" - echo "- [run ${GITHUB_RUN_NUMBER} TEST commit ${SHORT_SHA}](${TEST_FILE})" - echo "- [run ${GITHUB_RUN_NUMBER} COVERAGE commit ${SHORT_SHA}](${COVERAGE_FILE})" - echo "" - echo "## Previous Runs" - - # Si Home.md existe et contient des donnรฉes - if [[ -f "${HOME_FILE}" && -s "${HOME_FILE}" ]]; then - # Capture l'ancien Latest Run (2 lignes aprรจs le titre) - sed -n '/## Latest Run/{n;p;n;p}' "${HOME_FILE}" - - # Capture tous les Previous Runs existants - sed -n '/## Previous Runs/,$p' "${HOME_FILE}" | tail -n +2 | grep -v "^#" || true - fi - } > "${TEMP_CONTENT}" 2> "${REPORT_LOG}" || { - echo "โŒ Report preparation failed" - echo "๐Ÿ” Errors found (filtered):" - grep -i 'error\|fatal\|refused' "${REPORT_LOG}" || echo "No obvious error found." - cat "${REPORT_LOG}" - exit 1 - } - - # ร‰criture atomique (รฉvite la corruption) - mkdir -p wiki/ - mv "${TEMP_CONTENT}" "${HOME_FILE}" - - - name: Commit and push wiki - env: - CI_TOKEN: ${{ secrets.CI_TOKEN }} - run: | - echo "๐Ÿš€ Pushing wiki changes..." - cd wiki - - git config user.name "ci-bot" - git config user.email "ci-bot@example.com" - - git add . - - if git commit -m "Update wiki with run ${GITHUB_RUN_NUMBER}"; then - git push https://ci-token:${CI_TOKEN}@gitea.psi.ch/tligui_y/slic.wiki.git HEAD:main - echo "โœ… Wiki updated successfully" - else - echo "No changes to commit" - fi - - - name: Log wiki report URLs - run: | - REPO_URL="https://gitea.psi.ch/tligui_y/slic" - TEST_MD_PATH="run-${GITHUB_RUN_NUMBER}-TEST-REPORT-commit:-$(git rev-parse --short HEAD).md" - COVERAGE_MD_PATH="run-${GITHUB_RUN_NUMBER}-COVERAGE-FILE-commit:-$(git rev-parse --short HEAD).md" - - echo "๐Ÿ”— Wiki Test Report URL:" - echo " $REPO_URL/wiki/${TEST_MD_PATH}" - - echo "๐Ÿ”— Wiki Coverage Report URL:" - echo " $REPO_URL/wiki/${COVERAGE_MD_PATH}" \ No newline at end of file + - uses: tligui_y/slic/.gitea/workflows/pytest-ci@tests-ci + with: + ci-branch: test_actions_on_utils + module-dir: slic + report-dir: ci-reports + gitea-domain: gitea.psi.ch + repo-path: tligui_y/slic + ci-token: ${{ secrets.CI_TOKEN }}