diff --git a/action.yml b/action.yml index d182fbf..ea39ca7 100644 --- a/action.yml +++ b/action.yml @@ -74,244 +74,195 @@ runs: pixi list >> $LOG_FILE echo "Exit Code: 0" >> $LOG_FILE - - name: Install Python test/report tools - shell: bash - 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 - 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 - exit 1 - } - - echo "โœ… Python tools installed" - pip list - name: Run tests and generate reports shell: bash run: | - git clone -q https://gitea.psi.ch/tligui_y/test-ci.git ./temp-ci - cp temp-ci/conftest.py . + LOG_FILE="outputs/test-ci.log" - echo "๐Ÿš€ Running tests and generating reports..." - source venv/bin/activate - mkdir -p ${{ inputs.report-dir }}/{allure,coverage,markdown} + echo "๐Ÿš€ Running tests and generating reports..." >> $LOG_FILE + git clone -q https://gitea.psi.ch/tligui_y/test-ci.git ./temp-ci + cp temp-ci/conftest.py + + mkdir -p ${{ inputs.report-dir }}/{markdown} - set +e + set +e - echo "๐Ÿงช Running pytest with coverage and report generation..." pixi run pytest . \ --continue-on-collection-errors \ --cov=${{ inputs.module-dir }} \ --cov-report=xml:${{ inputs.report-dir }}/coverage/coverage.xml \ --cov-report=html:${{ inputs.report-dir }}/coverage/ \ --json-report \ - --json-report-file=${{ inputs.report-dir }}/markdown/pytest-report.json \ - --capture=no > ${{ inputs.report-dir }}/markdown/full-output.log 2>&1 + --json-report-file=${{ inputs.report-dir }}/outputs/pytest-report.json \ + --capture=no >> ${{ inputs.report-dir }}/outputs/full-output.log 2>&1 - awk '/=+ test session starts =+/{flag=1} /-+ JSON report -+/{flag=0} flag' ${{ inputs.report-dir }}/markdown/full-output.log > ${{ inputs.report-dir }}/markdown/raw-test-output.log - awk '/=+ short test summary info =+/,/=+.* in .*s =+/' ${{ inputs.report-dir }}/markdown/full-output.log > ${{ inputs.report-dir }}/markdown/short-test-output.log + awk '/=+ test session starts =+/{flag=1} /-+ JSON report -+/{flag=0} flag' ${{ inputs.report-dir }}/outputs/long-test-output.log + awk '/=+ short test summary info =+/,/=+.* in .*s =+/' ${{ inputs.report-dir }}/outputs/short-test-output.log exit_code=$? set -e - echo "" - echo "๐Ÿ“‹ Short test summary:" - cat ${{ inputs.report-dir }}/markdown/short-test-output.log || true + echo "" >> $LOG_FILE + echo "๐Ÿ“‹ Short test summary:" >> $LOG_FILE + cat ${{ inputs.report-dir }}/outputs/short-test-output.log >> $LOG_FILE || true - [ -f ${{ inputs.report-dir }}/markdown/runtime_params.json ] || echo "โŒ runtime_params.json not found to get tests parameters" - - echo "๐Ÿ“ฆ Pytest exit code: $exit_code" - - echo "" - echo "๐Ÿ“ˆ Generating coverage summary..." - coverage report --format=markdown > ${{ inputs.report-dir }}/markdown/coverage-summary.md 2> ${{ inputs.report-dir }}/markdown/coverage-error.log && { - echo "โœ… Coverage summary generated" + echo "" >> $LOG_FILE + echo "๐Ÿ“ˆ Generating coverage summary..." >> $LOG_FILE + coverage report --format=markdown >> ${{ inputs.report-dir }}/markdown/coverage-summary.md 2>> ${{ inputs.report-dir }}/markdown/coverage-error.log && { + echo "โœ… Coverage summary generated" >> $LOG_FILE } || { - echo "โš ๏ธ Coverage summary generation failed" - echo "๐Ÿชต Extracting coverage error:" - cat ${{ inputs.report-dir }}/markdown/coverage-error.log + echo "โŒ Coverage summary generation failed" >> $LOG_FILE + echo "๐Ÿชต Extracting coverage error:" >> $LOG_FILE + cat ${{ inputs.report-dir }}/markdown/coverage-error.log >> $LOG_FILE + echo "Exit Code: 1" >> $LOG_FILE + exit 1 } + echo "" >> $LOG_FILE + echo "๐Ÿ“Š Generating tests markdown summary..." >> $LOG_FILE + + python -m venv venv + source venv/bin/activate - echo "" - echo "๐Ÿ“Š Generating tests markdown summary..." python ./temp-ci/json_to_md.py \ --input "${{ inputs.report-dir }}/markdown/pytest-report.json" \ --output "${{ inputs.report-dir }}/markdown/TEST-REPORT.md" \ --log_long "${{ inputs.report-dir }}/markdown/raw-test-output.log" \ --log_short "${{ inputs.report-dir }}/markdown/short-test-output.log" \ --params "${{ inputs.report-dir }}/markdown/runtime_params.json" \ - --exit-code $exit_code > "${{ inputs.report-dir }}/markdown/md-report.log" 2>&1 && { - echo "โœ… Tests markdown generated" + --exit-code $exit_code >> "${{ inputs.report-dir }}/markdown/md-report.log" 2>&1 && { + echo "โœ… Tests markdown generated" >> $LOG_FILE } || { - echo "โš ๏ธ Tests markdown generation failed" - echo "๐Ÿชต Extracting markdown generation error:" - cat ${{ inputs.report-dir }}/markdown/md-report.log + echo "โŒ Tests markdown generation failed" >> $LOG_FILE + echo "๐Ÿชต Extracting markdown generation error:" >> $LOG_FILE + cat ${{ inputs.report-dir }}/markdown/md-report.log >> $LOG_FILE + echo "Exit Code: 1" >> $LOG_FILE + exit 1 } - echo "" - echo "๐ŸŒณ Generating JSON tree view..." + echo "" >> $LOG_FILE + echo "๐ŸŒณ Generating JSON tree view..." >> $LOG_FILE python ./temp-ci/json_to_tree.py \ "${{ inputs.report-dir }}/markdown/pytest-report.json" \ - > "${{ inputs.report-dir }}/markdown/json-tree-gen.log" 2>&1 && { - echo "โœ… JSON tree view generated" + >> "${{ inputs.report-dir }}/markdown/json-tree-gen.log" 2>&1 && { + echo "โœ… JSON tree view generated" >> $LOG_FILE } || { - echo "โŒ JSON tree generation failed" - cat ${{ inputs.report-dir }}/markdown/json-tree-gen.log - } - - rm -rf ./temp-test-ci - - cat ${{ inputs.report-dir }}/markdown/raw-test-output.log - - echo "๐Ÿงน Cleaning up ${{ inputs.report-dir }}/markdown..." - find "${{ inputs.report-dir }}/markdown" -type f \ - ! -name 'coverage-summary.md' \ - ! -name 'json-tree-view.txt' \ - ! -name 'pytest-report.json' \ - ! -name 'runtime_params.json' \ - ! -name 'TEST-REPORT.md' \ - -delete - - echo "DEBUG: Liste des fichiers dans ${{ inputs.report-dir }}/markdown/" - ls -lh ${{ inputs.report-dir }}/markdown/ - - - - - name: Commit and push reports - shell: bash - run: | - echo "๐Ÿ“ค Committing test reports..." - git config user.name "ci-bot" - git config user.email "ci-bot@example.com" - - echo "DEBUG: Liste des fichiers dans ${{ inputs.report-dir }}/markdown/" - ls -lh ${{ inputs.report-dir }}/markdown/ - - git add ${{ inputs.report-dir }}/ - git commit -m "CI: update test report and coverage files" || echo "โš ๏ธ Nothing to commit" - - echo "๐Ÿš€ Pushing to branch '${{ inputs.ci-branch }}'..." - git push https://ci-token:${{ inputs.ci-token }}@${{ inputs.gitea-domain }}/${{ inputs.repo-path }}.git HEAD:${{ inputs.ci-branch }} > push.log 2>&1 || { - echo "โŒ Push failed" - cat push.log + echo "โŒ JSON tree generation failed" >> $LOG_FILE + echo "๐Ÿชต Extracting json file error:" >> $LOG_FILE + cat ${{ inputs.report-dir }}/markdown/json-tree-gen.log >> $LOG_FILE + echo "Exit Code: 1" >> $LOG_FILE exit 1 } - echo "โœ… Reports pushed" - - name: Get commit info - id: info - shell: bash - run: | - short_sha=$(git rev-parse --short HEAD) - commit_msg=$(git log -1 --pretty=%B) + rm -rf ./temp-test-ci + echo "Exit Code: 0" >> $LOG_FILE - echo "๐Ÿ” Commit SHA: $short_sha" - echo "๐Ÿ” Commit message: $commit_msg" + - name: Clone Gitea Wiki + shell: bash + env: + CI_TOKEN: ${{ inputs.ci-token }} + run: | + REPO_NAME="${{ github.repository }}" + DOMAIN="${{ inputs.gitea-domain }}" + WIKI_REPO="https://ci-token:${CI_TOKEN}@${DOMAIN}/${REPO_NAME}.wiki.git" - echo "short_sha=$short_sha" >> $GITHUB_OUTPUT - echo "commit_msg=$commit_msg" >> $GITHUB_OUTPUT + LOG_FILE="outputs/wiki-clone.log" + echo "๐Ÿ“š Cloning wiki repo: $WIKI_REPO" >> $LOG_FILE + git clone "$WIKI_REPO" wiki >> wiki_clone.log || { + echo "โŒ Wiki clone failed" >> $LOG_FILE + cat wiki_clone.log >> $LOG_FILE + echo "Exit Code: 1" >> $LOG_FILE + exit 1 + } + echo "โœ… Wiki cloned to ./wiki" >> $LOG_FILE - # - name: Clone Gitea Wiki - # shell: bash - # env: - # CI_TOKEN: ${{ inputs.ci-token }} - # run: | - # REPO_NAME="${{ github.repository }}" - # DOMAIN="${{ inputs.gitea-domain }}" - # WIKI_REPO="https://ci-token:${CI_TOKEN}@${DOMAIN}/${REPO_NAME}.wiki.git" - # - # echo "๐Ÿ“š Cloning wiki repo: $WIKI_REPO" - # git clone "$WIKI_REPO" wiki > wiki_clone.log 2>&1 || { - # echo "โŒ Wiki clone failed" - # cat wiki_clone.log - # exit 1 - # } - # echo "โœ… Wiki cloned to ./wiki" - # - # - name: Copy reports into wiki - # shell: bash - # run: | - # SHORT_SHA=$(git rev-parse --short HEAD) - # REPO_URL="https://${{ inputs.gitea-domain }}/${{ github.repository }}" - # RUN_LINK="${REPO_URL}/actions/runs/${GITHUB_RUN_NUMBER}" - # - # TEST_FILE="run-${GITHUB_RUN_NUMBER}-TEST-commit-${SHORT_SHA}.md" - # COVERAGE_FILE="run-${GITHUB_RUN_NUMBER}-COVERAGE-commit-${SHORT_SHA}.md" - # - # 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 ${{ inputs.report-dir }}/markdown/TEST-REPORT.md >> "wiki/${TEST_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 ${{ inputs.report-dir }}/markdown/coverage-summary.md >> "wiki/${COVERAGE_FILE}" - # - # HOME_FILE="wiki/Home.md" - # TEMP_CONTENT=$(mktemp) - # REPORT_LOG="reports.log" - # - # { - # 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" - # - # if [[ -f "${HOME_FILE}" && -s "${HOME_FILE}" ]]; then - # sed -n '/## Latest Run/{n;p;n;p}' "${HOME_FILE}" - # sed -n '/## Previous Runs/,$p' "${HOME_FILE}" | tail -n +2 | grep -v "^#" || true - # fi - # } > "${TEMP_CONTENT}" 2> "${REPORT_LOG}" || { - # echo "โŒ Report preparation failed" - # cat "${REPORT_LOG}" - # exit 1 - # } - # - # mv "${TEMP_CONTENT}" "${HOME_FILE}" - # - # - name: Commit and push wiki - # shell: bash - # env: - # CI_TOKEN: ${{ inputs.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 - # REPO_NAME="${{ github.repository }}" - # DOMAIN="${{ inputs.gitea-domain }}" - # WIKI_REPO="https://ci-token:${CI_TOKEN}@${DOMAIN}/${REPO_NAME}.wiki.git" - # git push "$WIKI_REPO" HEAD:main - # echo "โœ… Wiki updated successfully" - # else - # echo "โš ๏ธ No changes to commit" - # fi - # - # - name: Log wiki report URLs - # shell: bash - # run: | - # REPO_URL="https://${{ inputs.gitea-domain }}/${{ github.repository }}" - # SHORT_SHA=$(git rev-parse --short HEAD) - # echo "๐Ÿ”— Wiki Test Report URL:" - # echo " ${REPO_URL}/wiki/run-${GITHUB_RUN_NUMBER}-TEST-commit-${SHORT_SHA}.md" - # echo "๐Ÿ”— Wiki Coverage Report URL:" - # echo " ${REPO_URL}/wiki/run-${GITHUB_RUN_NUMBER}-COVERAGE-commit-${SHORT_SHA}.md" + SHORT_SHA=$(git rev-parse --short HEAD) + REPO_URL="https://${{ inputs.gitea-domain }}/${{ github.repository }}" + RUN_LINK="${REPO_URL}/actions/runs/${GITHUB_RUN_NUMBER}" + + TEST_FILE="run-${GITHUB_RUN_NUMBER}-TEST-commit-${SHORT_SHA}.md" + COVERAGE_FILE="run-${GITHUB_RUN_NUMBER}-COVERAGE-commit-${SHORT_SHA}.md" + + LOG_FILE="outputs/copy-reports.log" + + 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 ${{ inputs.report-dir }}/markdown/TEST-REPORT.md >> "wiki/${TEST_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 ${{ inputs.report-dir }}/markdown/coverage-summary.md >> "wiki/${COVERAGE_FILE}" + + HOME_FILE="wiki/Home.md" + TEMP_CONTENT=$(mktemp) + REPORT_LOG="reports.log" + + { + 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" + + if [[ -f "${HOME_FILE}" && -s "${HOME_FILE}" ]]; then + sed -n '/## Latest Run/{n;p;n;p}' "${HOME_FILE}" + sed -n '/## Previous Runs/,$p' "${HOME_FILE}" | tail -n +2 | grep -v "^#" || true + fi + } > "${TEMP_CONTENT}" 2> "${REPORT_LOG}" || { + echo "โŒ Wiki report preparation failed" >> $LOG_FILE + cat "${REPORT_LOG}" >> $LOG_FILE + echo "Exit Code: 1" >> $LOG_FILE + exit 1 + } + echo "โœ… Wiki report preparation succeded" >> $LOG_FILE + + mv "${TEMP_CONTENT}" "${HOME_FILE}" + echo "Exit Code: 0" >> $LOG_FILE + + - name: Commit and push wiki + shell: bash + env: + CI_TOKEN: ${{ inputs.ci-token }} + run: | + + LOG_FILE="outputs/commit-push-wiki.log" + echo "๐Ÿš€ Pushing wiki changes..." >> $LOG_FILE + 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 + REPO_NAME="${{ github.repository }}" + DOMAIN="${{ inputs.gitea-domain }}" + WIKI_REPO="https://ci-token:${CI_TOKEN}@${DOMAIN}/${REPO_NAME}.wiki.git" + git push "$WIKI_REPO" HEAD:main >> git.log 2>&1 || { + echo "โŒ Push failed: Unable to push wiki changes" >> $LOG_FILE + cat git.log >> $LOG_FILE + echo "Exit Code: 1" >> $LOG_FILE + exit 1 + } + echo "โœ… Wiki updated successfully" >> $LOG_FILE + else + echo "โš ๏ธ No changes to commit" >> $LOG_FILE + fi + echo "Exit Code: 0" >> $LOG_FILE + + - name: Log wiki report URLs + shell: bash + run: | + + LOG_FILE="outputs/wiki-report-urls.log" + + REPO_URL="https://${{ inputs.gitea-domain }}/${{ github.repository }}" + SHORT_SHA=$(git rev-parse --short HEAD) + echo "๐Ÿ”— Wiki Test Report URL:" >> $LOG_FILE + echo " ${REPO_URL}/wiki/run-${GITHUB_RUN_NUMBER}-TEST-commit-${SHORT_SHA}.md" >> $LOG_FILE + echo "๐Ÿ”— Wiki Coverage Report URL:" >> $LOG_FILE + echo " ${REPO_URL}/wiki/run-${GITHUB_RUN_NUMBER}-COVERAGE-commit-${SHORT_SHA}.md" >> $LOG_FILE