Skip to content

Commit

Permalink
wireviz_kroki.py and runner fixes
Browse files Browse the repository at this point in the history
Fix error code, better reporting.
Runner: remove ARM64
  • Loading branch information
sgorsh committed Oct 31, 2024
1 parent f7056cc commit f1852c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/native-image-on-demand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
30 changes: 22 additions & 8 deletions wireviz_kroki.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
#!/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)
elif isinstance(data, bytes):
sys.stdout.buffer.write(data)
else:
raise ValueError("Unsupported data format")
sys.exit(0)

except Exception as e:
sys.stderr.write(str(e))
sys.stderr.write(str(e))
sys.stderr.write("\n-----------\n")
sys.stderr.write(traceback.format_exc())
sys.exit(1)

0 comments on commit f1852c1

Please sign in to comment.