This commit is contained in:
+13
-256
@@ -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}"
|
||||
- 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 }}
|
||||
|
||||
Reference in New Issue
Block a user