From f1852c12ee1d0c85bcd902a5162850e9e124e04b Mon Sep 17 00:00:00 2001 From: sgorsh <25081285+sgorsh@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:14:18 +0100 Subject: [PATCH] wireviz_kroki.py and runner fixes Fix error code, better reporting. Runner: remove ARM64 --- .github/workflows/native-image-on-demand.yml | 11 +------ wireviz_kroki.py | 30 ++++++++++++++------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.github/workflows/native-image-on-demand.yml b/.github/workflows/native-image-on-demand.yml index f64182e2..4d239c4c 100644 --- a/.github/workflows/native-image-on-demand.yml +++ b/.github/workflows/native-image-on-demand.yml @@ -17,8 +17,6 @@ jobs: include: - os: 'ubuntu-latest' platform: 'linux-amd64' - - os: 'ARM64' # self-hosted - platform: 'linux-arm64' runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -79,17 +77,10 @@ jobs: key: "native-image-linux-amd64-${{ github.run_id }}" fail-on-cache-miss: true enableCrossOsArchive: true - - name: Restore Native-image-linux-arm64 cache - uses: actions/cache/restore@v3 - with: - path: "wireviz-linux-arm64.bin" - key: "native-image-linux-arm64-${{ github.run_id }}" - fail-on-cache-miss: true - enableCrossOsArchive: true - name: Create release run: | gh release view "v$RELEASE_VERSION" || gh release create "v$RELEASE_VERSION" - gh release upload "v$RELEASE_VERSION" ./wireviz-linux-amd64.bin ./wireviz-linux-arm64.bin --clobber + gh release upload "v$RELEASE_VERSION" ./wireviz-linux-amd64.bin --clobber env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_VERSION: ${{ env.release_version }} diff --git a/wireviz_kroki.py b/wireviz_kroki.py index ad6dfa08..5158b829 100644 --- a/wireviz_kroki.py +++ b/wireviz_kroki.py @@ -1,27 +1,37 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import sys +import sys, io import argparse +import traceback import wireviz.wireviz as wv +from wireviz import __version__ if __name__ == "__main__": parser = argparse.ArgumentParser(description= """Wireviz Kroki wrapper. Reads YAML data from stdin and writes output to stdout. Errors and messages from WireViz are printed to stderr.""") - + output_formats = ["svg", "png", "harness"] - parser.add_argument("--format", type=str, required=True, choices=output_formats, + parser.add_argument("--format", "-f", type=str, required=True, choices=output_formats, help=f"Supported output formats.") - parser.add_argument("output", type=str, choices=["-"], help="'-' for stdout") + parser.add_argument("input", type=str, choices=["-"], help="'-' for stdin") + parser.add_argument("-o", type=str, choices=["-"], help="'-' for stdout") + parser.add_argument("--version", "-v", action="version", version=__version__, help="print WireViz version") + args = parser.parse_args() - + try: + # Capture stdout + old_stdout = sys.stdout + sys.stdout = io.StringIO() + data = wv.parse(inp = sys.stdin.read(), return_types=args.format) - if not args.output == "-": - raise ValueError("Only stdout output is supported") + + # Restore stdout + sys.stdout = old_stdout if isinstance(data, str): sys.stdout.write(data) @@ -29,6 +39,10 @@ sys.stdout.buffer.write(data) else: raise ValueError("Unsupported data format") + sys.exit(0) except Exception as e: - sys.stderr.write(str(e)) \ No newline at end of file + sys.stderr.write(str(e)) + sys.stderr.write("\n-----------\n") + sys.stderr.write(traceback.format_exc()) + sys.exit(1)