Update action.yml

This commit is contained in:
2025-07-23 15:51:00 +02:00
parent ed3fd67e94
commit 4d946e28bb
+149 -198
View File
@@ -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