- moved git actions to gitea actions
- removed sonarqube - added report for junit tests
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
name: Publish JUnit Report (Short Names)
|
||||
description: Normalize JUnit XML report names and publish a test report to the repo.
|
||||
inputs:
|
||||
token:
|
||||
description: Gitea token with write access to the repository.
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Normalize JUnit report names
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p junit-short
|
||||
shopt -s globstar nullglob
|
||||
for f in **/target/*-reports/TEST-*.xml; do
|
||||
base="$(basename "$f")"
|
||||
short="${base#TEST-}"
|
||||
cp "$f" "junit-short/${short}"
|
||||
done
|
||||
|
||||
- name: Generate Markdown Test Report
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p reports
|
||||
python3 - <<'EOF'
|
||||
import glob, xml.etree.ElementTree as ET
|
||||
|
||||
# --- JUnit ---
|
||||
files = glob.glob("junit-short/*.xml")
|
||||
total_tests = total_failures = total_errors = total_skipped = 0
|
||||
test_rows = []
|
||||
|
||||
for f in sorted(files):
|
||||
tree = ET.parse(f)
|
||||
r = tree.getroot()
|
||||
suites = r.findall("testsuite") if r.tag == "testsuites" else [r]
|
||||
for ts in suites:
|
||||
name = ts.get("name", f)
|
||||
tests = int(ts.get("tests", 0))
|
||||
failures = int(ts.get("failures", 0))
|
||||
errors = int(ts.get("errors", 0))
|
||||
skipped = int(ts.get("skipped", 0))
|
||||
passed = tests - failures - errors - skipped
|
||||
status = "✅" if (failures + errors) == 0 else "❌"
|
||||
total_tests += tests
|
||||
total_failures += failures
|
||||
total_errors += errors
|
||||
total_skipped += skipped
|
||||
test_rows.append(f"| {status} | {name} | {tests} | {passed} | {failures + errors} | {skipped} |")
|
||||
|
||||
total_passed = total_tests - total_failures - total_errors - total_skipped
|
||||
overall = "✅ All tests passed" if (total_failures + total_errors) == 0 else "❌ Some tests failed"
|
||||
|
||||
# --- JaCoCo ---
|
||||
def counter(el, type_):
|
||||
c = next((x for x in el.findall("counter") if x.get("type") == type_), None)
|
||||
if c is None:
|
||||
return 0, 0
|
||||
covered = int(c.get("covered", 0))
|
||||
missed = int(c.get("missed", 0))
|
||||
return covered, covered + missed
|
||||
|
||||
cov_rows = []
|
||||
jacoco_files = glob.glob("**/target/site/jacoco/jacoco.xml", recursive=True)
|
||||
|
||||
for jf in sorted(jacoco_files):
|
||||
tree = ET.parse(jf)
|
||||
root = tree.getroot()
|
||||
for pkg in root.findall("package"):
|
||||
name = pkg.get("name", "").replace("/", ".")
|
||||
line_cov, line_total = counter(pkg, "LINE")
|
||||
branch_cov, branch_total = counter(pkg, "BRANCH")
|
||||
line_pct = f"{100 * line_cov / line_total:.0f}%" if line_total else "n/a"
|
||||
branch_pct = f"{100 * branch_cov / branch_total:.0f}%" if branch_total else "n/a"
|
||||
cov_rows.append(f"| {name} | {line_pct} ({line_cov}/{line_total}) | {branch_pct} ({branch_cov}/{branch_total}) |")
|
||||
|
||||
# --- Markdown zusammenbauen ---
|
||||
md = (
|
||||
"# Test Report\n\n"
|
||||
f"**{overall}**\n\n"
|
||||
"## Test Results\n\n"
|
||||
"| | Tests | Passed | Failed | Skipped |\n"
|
||||
"|---|---|---|---|---|\n"
|
||||
f"| **Total** | {total_tests} | {total_passed} | {total_failures + total_errors} | {total_skipped} |\n\n"
|
||||
"### Details\n\n"
|
||||
"| Status | Suite | Tests | Passed | Failed | Skipped |\n"
|
||||
"|---|---|---|---|---|---|\n"
|
||||
) + "\n".join(test_rows) + "\n\n"
|
||||
|
||||
if cov_rows:
|
||||
md += (
|
||||
"## Coverage\n\n"
|
||||
"| Package | Line Coverage | Branch Coverage |\n"
|
||||
"|---|---|---|\n"
|
||||
) + "\n".join(cov_rows) + "\n"
|
||||
else:
|
||||
md += "_No JaCoCo report found._\n"
|
||||
|
||||
with open("reports/test.md", "w") as out:
|
||||
out.write(md)
|
||||
print(md)
|
||||
EOF
|
||||
|
||||
- name: Commit Test-Report to Repo
|
||||
shell: bash
|
||||
env:
|
||||
GIT_USER: gitea-actions-bot
|
||||
GIT_EMAIL: bot@mein-gateway.de
|
||||
GITEA_TOKEN: ${{ inputs.token }}
|
||||
run: |
|
||||
git config user.name "$GIT_USER"
|
||||
git config user.email "$GIT_EMAIL"
|
||||
git remote set-url origin https://$GIT_USER:$GITEA_TOKEN@git.mein-gateway.de/${{ github.repository }}.git
|
||||
git fetch origin
|
||||
git checkout ${{ github.ref_name }}
|
||||
git add reports/
|
||||
git diff --cached --quiet && echo "No changes" && exit 0
|
||||
git commit -m "ci: update test report [skip ci]"
|
||||
git push origin ${{ github.ref_name }}
|
||||
@@ -0,0 +1,21 @@
|
||||
name: "Setup Maven with GitHub Packages"
|
||||
|
||||
description: "Sets up JDK and caches Maven dependencies."
|
||||
|
||||
inputs:
|
||||
java-version:
|
||||
description: "Java version to install"
|
||||
default: "17"
|
||||
required: true
|
||||
java-distribution:
|
||||
description: "Java distribution to use"
|
||||
default: "corretto"
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Set up JDK
|
||||
with:
|
||||
distribution: ${{ inputs.java-distribution }}
|
||||
java-version: ${{ inputs.java-version }}
|
||||
uses: actions/setup-java@v5
|
||||
@@ -0,0 +1,34 @@
|
||||
name: Build and Analyse
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
- feature*
|
||||
pull_request:
|
||||
types: [ opened, synchronize, reopened ]
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
jobs:
|
||||
|
||||
build-and-analyse:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||
|
||||
- name: Setup Java and Maven
|
||||
uses: ./.gitea/actions/setup-java-maven
|
||||
|
||||
- name: Build and test
|
||||
run: mvn -B verify
|
||||
|
||||
- name: Publish Test Report
|
||||
uses: ./.gitea/actions/publish-report
|
||||
if: ${{ always() }}
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
Reference in New Issue
Block a user