|
| 1 | +name: mb3r-report |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + discovery-artifact-name: |
| 7 | + type: string |
| 8 | + default: "mb3r-bering-discovery" |
| 9 | + gate-artifact-name: |
| 10 | + type: string |
| 11 | + default: "mb3r-sheaft-gate" |
| 12 | + discovery-report-path: |
| 13 | + type: string |
| 14 | + default: ".mb3r/bering/bering-discovery.json" |
| 15 | + gate-report-path: |
| 16 | + type: string |
| 17 | + default: ".mb3r/sheaft/sheaft-gate.json" |
| 18 | + output-dir: |
| 19 | + type: string |
| 20 | + default: ".mb3r/report" |
| 21 | + artifact-name: |
| 22 | + type: string |
| 23 | + default: "mb3r-report" |
| 24 | + upload-artifact: |
| 25 | + type: boolean |
| 26 | + default: true |
| 27 | + outputs: |
| 28 | + report-json: |
| 29 | + description: Combined report JSON path within the artifact. |
| 30 | + value: ${{ jobs.mb3r-report.outputs.report-json }} |
| 31 | + report-markdown: |
| 32 | + description: Combined report markdown path within the artifact. |
| 33 | + value: ${{ jobs.mb3r-report.outputs.report-markdown }} |
| 34 | + artifact-name: |
| 35 | + description: Uploaded artifact name. |
| 36 | + value: ${{ jobs.mb3r-report.outputs.artifact-name }} |
| 37 | + overall-decision: |
| 38 | + description: Overall stack decision from the merged report. |
| 39 | + value: ${{ jobs.mb3r-report.outputs.overall-decision }} |
| 40 | + |
| 41 | +jobs: |
| 42 | + mb3r-report: |
| 43 | + runs-on: ubuntu-latest |
| 44 | + outputs: |
| 45 | + report-json: ${{ steps.report.outputs.report-json }} |
| 46 | + report-markdown: ${{ steps.report.outputs.report-markdown }} |
| 47 | + artifact-name: ${{ steps.report.outputs.artifact-name }} |
| 48 | + overall-decision: ${{ steps.report.outputs.overall-decision }} |
| 49 | + steps: |
| 50 | + - if: ${{ inputs.discovery-artifact-name != '' }} |
| 51 | + uses: actions/download-artifact@v4 |
| 52 | + with: |
| 53 | + name: ${{ inputs.discovery-artifact-name }} |
| 54 | + path: .mb3r/input-discovery |
| 55 | + |
| 56 | + - if: ${{ inputs.gate-artifact-name != '' }} |
| 57 | + uses: actions/download-artifact@v4 |
| 58 | + with: |
| 59 | + name: ${{ inputs.gate-artifact-name }} |
| 60 | + path: .mb3r/input-gate |
| 61 | + |
| 62 | + - uses: actions/setup-python@v5 |
| 63 | + with: |
| 64 | + python-version: "3.13" |
| 65 | + |
| 66 | + - name: Build combined report |
| 67 | + id: report |
| 68 | + shell: bash |
| 69 | + env: |
| 70 | + DISCOVERY_REPORT_PATH: ${{ inputs.discovery-report-path }} |
| 71 | + GATE_REPORT_PATH: ${{ inputs.gate-report-path }} |
| 72 | + OUTPUT_DIR: ${{ inputs.output-dir }} |
| 73 | + ARTIFACT_NAME: ${{ inputs.artifact-name }} |
| 74 | + run: | |
| 75 | + python - <<'PY' |
| 76 | + import json |
| 77 | + import os |
| 78 | + from datetime import datetime, timezone |
| 79 | + from pathlib import Path |
| 80 | +
|
| 81 | + output_dir = Path(os.environ["OUTPUT_DIR"]) |
| 82 | + output_dir.mkdir(parents=True, exist_ok=True) |
| 83 | +
|
| 84 | + discovery_report = Path(".mb3r/input-discovery") / Path(os.environ["DISCOVERY_REPORT_PATH"]).name |
| 85 | + gate_report = Path(".mb3r/input-gate") / Path(os.environ["GATE_REPORT_PATH"]).name |
| 86 | + report_json = output_dir / "mb3r-report.json" |
| 87 | + report_md = output_dir / "mb3r-report.md" |
| 88 | +
|
| 89 | + discovery = json.loads(discovery_report.read_text(encoding="utf-8")) |
| 90 | + gate = json.loads(gate_report.read_text(encoding="utf-8")) |
| 91 | +
|
| 92 | + overall_decision = gate.get("decision", "review") |
| 93 | + combined = { |
| 94 | + "schemaVersion": "v1alpha1", |
| 95 | + "kind": "mb3r.stack.report", |
| 96 | + "adapter": "github-reusable-workflow", |
| 97 | + "generatedAt": datetime.now(timezone.utc).replace(microsecond=0).isoformat(), |
| 98 | + "overallDecision": overall_decision, |
| 99 | + "discovery": { |
| 100 | + "status": discovery.get("status"), |
| 101 | + "path": discovery_report.as_posix(), |
| 102 | + "artifactName": discovery.get("artifactName"), |
| 103 | + }, |
| 104 | + "gate": { |
| 105 | + "decision": gate.get("decision"), |
| 106 | + "status": gate.get("status"), |
| 107 | + "path": gate_report.as_posix(), |
| 108 | + "artifactName": gate.get("artifactName"), |
| 109 | + }, |
| 110 | + } |
| 111 | + report_json.write_text(json.dumps(combined, indent=2) + "\n", encoding="utf-8") |
| 112 | +
|
| 113 | + markdown = "\n".join( |
| 114 | + [ |
| 115 | + "# MB3R Report", |
| 116 | + "", |
| 117 | + f"- Generated at: {combined['generatedAt']}", |
| 118 | + f"- Discovery status: {combined['discovery']['status']}", |
| 119 | + f"- Gate status: {combined['gate']['status']}", |
| 120 | + f"- Overall decision: {combined['overallDecision']}", |
| 121 | + ] |
| 122 | + ) |
| 123 | + report_md.write_text(markdown + "\n", encoding="utf-8") |
| 124 | +
|
| 125 | + with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as handle: |
| 126 | + handle.write(f"report-json={report_json.as_posix()}\n") |
| 127 | + handle.write(f"report-markdown={report_md.as_posix()}\n") |
| 128 | + handle.write(f"artifact-name={os.environ['ARTIFACT_NAME']}\n") |
| 129 | + handle.write(f"overall-decision={overall_decision}\n") |
| 130 | + PY |
| 131 | +
|
| 132 | + - if: ${{ inputs.upload-artifact }} |
| 133 | + uses: actions/upload-artifact@v4 |
| 134 | + with: |
| 135 | + name: ${{ steps.report.outputs.artifact-name }} |
| 136 | + path: ${{ inputs.output-dir }} |
0 commit comments