From bd6fbf8bb415e0cb9447a27dec3c6e4c2aa43174 Mon Sep 17 00:00:00 2001 From: Hartmut Obendorf Date: Wed, 10 Jun 2026 14:34:14 +0200 Subject: [PATCH] small gh action improvement --- .../workflows/cli-skill-review-reusable.yml | 42 +---------------- scripts/build-pr-report.py | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 41 deletions(-) create mode 100644 scripts/build-pr-report.py diff --git a/.github/workflows/cli-skill-review-reusable.yml b/.github/workflows/cli-skill-review-reusable.yml index a6e2f0f..9638b35 100644 --- a/.github/workflows/cli-skill-review-reusable.yml +++ b/.github/workflows/cli-skill-review-reusable.yml @@ -167,47 +167,7 @@ jobs: COMMAND: ${{ inputs.command }} run: | set -euo pipefail - - python3 - << 'PY' - import os - from pathlib import Path - - marker = os.environ.get('MARKER', '') - command = os.environ.get('COMMAND', '/cli-review') - success = os.environ.get('PI_SUCCESS', '') - cost = os.environ.get('PI_COST', '') - duration = os.environ.get('PI_DURATION', '') - input_tokens = os.environ.get('PI_INPUT_TOKENS', '') - output_tokens = os.environ.get('PI_OUTPUT_TOKENS', '') - run_url = os.environ.get('RUN_URL', '') - response = os.environ.get('PI_RESPONSE', '') - - if not response.strip(): - response = '_No response was returned by Pi._' - - # Keep body safely below GitHub comment max size. - max_response_len = 50000 - if len(response) > max_response_len: - response = response[:max_response_len] + "\n\n... _truncated_" - - body = f"""{marker} - ## CLI Skill Report ({command}) - - | Metric | Value | - |---|---| - | Success | {success or 'unknown'} | - | Duration (s) | {duration or 'n/a'} | - | Cost (USD) | {cost or 'n/a'} | - | Tokens (in/out) | {input_tokens or 'n/a'} / {output_tokens or 'n/a'} | - | Workflow run | [view run]({run_url}) | - - {response} - """ - - p = Path('pi-report-comment.md') - p.write_text(body.strip() + "\n", encoding='utf-8') - print(f"Wrote {p}") - PY + python3 scripts/build-pr-report.py - name: Fail when agent run is unsuccessful if: ${{ steps.cli_scope.outputs.proceed == 'true' && inputs.fail_on_agent_error && steps.pi.outputs.success != 'true' }} diff --git a/scripts/build-pr-report.py b/scripts/build-pr-report.py new file mode 100644 index 0000000..0b1ee86 --- /dev/null +++ b/scripts/build-pr-report.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +import os +from pathlib import Path + + +def main() -> None: + marker = os.environ.get("MARKER", "") + command = os.environ.get("COMMAND", "/cli-review") + success = os.environ.get("PI_SUCCESS", "") + cost = os.environ.get("PI_COST", "") + duration = os.environ.get("PI_DURATION", "") + input_tokens = os.environ.get("PI_INPUT_TOKENS", "") + output_tokens = os.environ.get("PI_OUTPUT_TOKENS", "") + run_url = os.environ.get("RUN_URL", "") + response = os.environ.get("PI_RESPONSE", "") + + if not response.strip(): + response = "_No response was returned by Pi._" + + # Keep body safely below GitHub comment max size. + max_response_len = 50000 + if len(response) > max_response_len: + response = response[:max_response_len] + "\n\n... _truncated_" + + body = f"""{marker} +## CLI Skill Report ({command}) + +| Metric | Value | +|---|---| +| Success | {success or 'unknown'} | +| Duration (s) | {duration or 'n/a'} | +| Cost (USD) | {cost or 'n/a'} | +| Tokens (in/out) | {input_tokens or 'n/a'} / {output_tokens or 'n/a'} | +| Workflow run | [view run]({run_url}) | + +{response} +""" + + report_path = Path("pi-report-comment.md") + report_path.write_text(body.strip() + "\n", encoding="utf-8") + print(f"Wrote {report_path}") + + +if __name__ == "__main__": + main()