chuhlomin / render-template

GitHub Action to render file based on template and passed variables
Apache License 2.0
27 stars 12 forks source link

Multiple Outputs Support #15

Open vz250049 opened 11 months ago

vz250049 commented 11 months ago

First off, this is really good stuff here.

Tried code with multiple outputs and it seems to negate both when I do it. 2 places where I call writeOutput hoping to set outputs and I get errors. See below.

outputs:
  result1:
    description: Rendered file content1
 result2:
   description: Rendered file content2

Changed function to: func writeOutput(name string, output string) error {...}

"Error! {\"statusCode\":200,\"statusMessage\":\"OK\",\"ok\":false,\"result\":\"{\\\"ok\\\":false,\\\"error\\\":\\\"invalid_blocks\\\",\\\"errors\\\":[\\\"failed to match all allowed schemas [json-pointer:/blocks/2/text]\\\",\\\"must be more than 0 characters [json-pointer:/blocks/2/text/text]\\\"],\\\"response_metadata\\\":{\\\"messages\\\":[\\\"[ERROR] failed to match all allowed schemas [json-pointer:/blocks/2/text]\\\",\\\"[ERROR] must be more than 0 characters [json-pointer:/blocks/2/text/text]\\\"]}}\",\"response\":{\"ok\":false,\"error\":\"invalid_blocks\",\"errors\":[\"failed to match all allowed schemas [json-pointer:/blocks/2/text]\",\"must be more than 0 characters [json-pointer:/blocks/2/text/text]\"],\"response_metadata\":{\"messages\":[\"[ERROR] failed to match all allowed schemas [json-pointer:/blocks/2/text]\",\"[ERROR] must be more than 0 characters [json-pointer:/blocks/2/text/text]\"]}}} (response)"Show less
--
build-and-push-to-gcrUnable to process file command 'output' successfully.
build-and-push-to-gcrInvalid value. EOF marker missing new line.

"Error! {\"statusCode\":200,\"statusMessage\":\"OK\",\"ok\":false,\"result\":\"{\\\"ok\\\":false,\\\"error\\\":\\\"invalid_blocks\\\",\\\"errors\\\":[\\\"failed to match all allowed schemas [json-pointer:/blocks/2/text]\\\",\\\"must be more than 0 characters [json-pointer:/blocks/2/text/text]\\\"],\\\"response_metadata\\\":{\\\"messages\\\":[\\\"[ERROR] failed to match all allowed schemas [json-pointer:/blocks/2/text]\\\",\\\"[ERROR] must be more than 0 characters [json-pointer:/blocks/2/text/text]\\\"]}}\",\"response\":{\"ok\":false,\"error\":\"invalid_blocks\",\"errors\":[\"failed to match all allowed schemas [json-pointer:/blocks/2/text]\",\"must be more than 0 characters [json-pointer:/blocks/2/text/text]\"],\"response_metadata\":{\"messages\":[\"[ERROR] failed to match all allowed schemas [json-pointer:/blocks/2/text]\",\"[ERROR] must be more than 0 characters [json-pointer:/blocks/2/text/text]\"]}}} (response)"
[build-and-push-to-gcr](https://github.com/ncr-bsp/docker-java/actions/runs/6513226036/job/17692415054#step:7:28)
Unable to process file command 'output' successfully.
[build-and-push-to-gcr](https://github.com/ncr-bsp/docker-java/actions/runs/6513226036/job/17692415054#step:7:29)
Invalid value. EOF marker missing new line.

can you help?

chuhlomin commented 11 months ago

Hey @vz250049,

I'm not sure I understand the problem you're trying to solve in the first place. I can suggest a few things that might help you:

  1. Run this step multiple times with different inputs. The overhead of this will be small.
  2. Make the template to look like a JSON string, then split it in a different step using jq.
  3. Use a template with some separator (like ---) and then split it using csplit or awk.

If you still want to do it in a single step, writeOutput function signature may look like this to accept a map of outputs:

func writeOutput(outputs map[string]string) error

Then, for each key in the map, call formatOutput with the key and value and join the strings with a newline separator before writing to the file.

Alternative solution is to use list of outputs, depending on how you want to generate them, and generate output names automatically (result, result2, result3, ...):

func writeOutput(outputs []string) error

Also, update action.yml; otherwise some linters will complain about unknown outputs.