diff --git a/.github/workflows/robot-tests.yml b/.github/workflows/robot-tests.yml index f0c1ae8..461a434 100644 --- a/.github/workflows/robot-tests.yml +++ b/.github/workflows/robot-tests.yml @@ -4,9 +4,12 @@ on: branches: [main] push: branches: [main] + paths-ignore: + - 'docs/badge.json' permissions: security-events: write + contents: write jobs: lint: @@ -77,3 +80,44 @@ jobs: with: name: robot-results path: results/ + + - name: Generate test result badge + if: always() + run: | + python3 - << 'EOF' + import json + try: + from robot.api import ExecutionResult + result = ExecutionResult('results/output.xml') + stats = result.statistics.total + passed = stats.passed + failed = stats.failed + total = passed + failed + if failed == 0: + color = "brightgreen" + message = f"{passed}/{total} passed" + else: + color = "red" + message = f"{passed}/{total} passed, {failed} failed" + except Exception as e: + print(f"Could not parse test results: {e}") + color = "lightgrey" + message = f"error: {e}" + badge = {"schemaVersion": 1, "label": "tests", "message": message, "color": color} + with open('docs/badge.json', 'w') as f: + json.dump(badge, f) + print(f"Badge written: {badge}") + EOF + + - name: Commit test result badge + if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add docs/badge.json + if git diff --staged --quiet; then + echo "No changes to badge.json" + else + git commit -m "chore: update test result badge" + git push + fi diff --git a/README.md b/README.md index e1cdc2e..4d50b45 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Robot Framework E2E Testing Workshop — 42 Vienna [![Robot Framework Tests](https://github.com/HackXIt/42vienna-robotframework-workshop/actions/workflows/robot-tests.yml/badge.svg)](https://github.com/HackXIt/42vienna-robotframework-workshop/actions/workflows/robot-tests.yml) +[![Test Results](https://img.shields.io/endpoint?url=https://hackxit.github.io/42vienna-robotframework-workshop/badge.json)](https://github.com/HackXIt/42vienna-robotframework-workshop/actions/workflows/robot-tests.yml) +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/HackXIt/42vienna-robotframework-workshop) **Browser Library & Playwright for Web Testing** diff --git a/docs/badge.json b/docs/badge.json new file mode 100644 index 0000000..dc771b3 --- /dev/null +++ b/docs/badge.json @@ -0,0 +1 @@ +{"schemaVersion": 1, "label": "tests", "message": "unknown", "color": "lightgrey"}