mikepenz/release-changelog-builder-action

Question: Ability to format markdown inside configurationJson

Aetherinox opened this issue ยท 7 comments

I was poking around, and I even searched for other Github repos using your script and I couldn't seem to find an example, so I thought I'd ask here.

From our last discussion on being able to use variables in a template; you recommended I just throw template inside configurationJson within my github action yml.

The question: Is their any possibility for me to be able to format this code? Adding line breaks within the template code but it still being rendered in its normal way? I'm just looking for a way to present it in a nicer fashion within my yml file. Because currently, all of the template code is on a single line, and I've had a lot of heavy modifications to the template, and it's making it a royal pain to move the changes between the two different yml files I use this github action on, since they're both not identical and I can't just copy/paste.

My template is as follows:

configurationJson: |
  {
    "template": "## Release Info \n- <sub>**Version began on**: <sub>........</sub>`#{{FROM_TAG_DATE}}`</sub>\n- <sub>**SHA256**: <sub>................................</sub>`${{ env.SHA256SUM }} ๐Ÿ”บ ${{ env.FILE_ZIP }}`</sub>\n- <sub>**GUID**: <sub>.......................................</sub>`${{ steps.dotenv.outputs.GUID }}`</sub>\n- <sub>**UUID**: <sub>.......................................</sub>`${{ steps.dotenv.outputs.UUID }}</sub>`\n- <sub>**Stamp**: <sub>....................................</sub>`#{{FROM_TAG}}-#{{FROM_TAG_DATE}} ๐Ÿ”บ #{{TO_TAG}}-#{{TO_TAG_DATE}}`</sub>\n- <sub>**Last Release**: <sub>......................</sub>`#{{DAYS_SINCE}} days ago`\n</sup>\n\n<br>\n\n---\n\n<br>\n\n### What's New\nThis release contains the following changes:\n\n<br>\n\n---\n\n<br>\n\n### Statistics\nHow the files have changed:\n<ul><li><a href='#{{RELEASE_DIFF}}'>Changed files</a>  : <b>#{{CHANGED_FILES}}</b> </li><li>Commits : <b>#{{COMMITS}}</b> </li><li>Additions : <b>#{{ADDITIONS}}</b></li><li>Deletions : <b>#{{DELETIONS}}</b></li>\n<br />\n</ul>\n\n<br>\n\n---\n\n<br>\n\n### Commits (#{{UNCATEGORIZED_COUNT}})\n#{{UNCATEGORIZED}}\n\n<br>\n\n---\n\n<br>\n\n### Pull Requests\n#{{CHANGELOG}}\n\n<br>\n\n---\n\n<br>\n\n"
  }

There's a lot of \n and <br> in the template so that I can format it in a nice way. And it's all just jumbled together.

Between Google and Github, I can't seem to find a way to format this, and maybe join the lines together, but it still look the same.

Unfortunately, I don't have an answer on this either, the only requirement from the action is that it is a valid json in the end.

If you find a solution, I'd be more than curious to see how :D given I had the same question myself in the past

Interesting, appreciate it.
I'm going to go throw it on a test repo and see if there's a way to join lines in json so that I can format this. I know json is picky as hell much like python, except json is limited since it's not a real programming language, just a formatting style / data representation, but there has to be some way to concat lines.

I'll let you know if I find it.

Probably yaml has some functionality to do that. as it's less about json allowing for it, but about yaml allowing you to structure the text somehow

Yeah I'm reading up on github's yml functionality + json. There "might" be a way with \. I've tried adding newlines with \ appended at the end, and the weird thing is that the action still executes without error, but it's ignoring those lines.

It looks like we might be out of luck with this task. JSON is very limited, and only meant for data transfer. It has zero logic at all, so to support multi-line json, it would have to be built into Github's yml foundation, and I'm not seeing any type of functionality being outlined.

Not unless the github action itself can have support for yml configurations, but I'd imagine that's a lot of damn work, just for the ability to have formatted code, which just seems like a ridiuclous amount of work for such a small perk.

I mean what you could theoretically do: Have a step before the one of running the action, where you construct the json in a more readable fashion, and then pass it on as output from that step to the action as input.

As long as it is a valid json, the action doesn't care how it was constructed.

So something like this:

#!/bin/bash

template='## Release Info
- <sub>**Version began on**: <sub>........</sub>`#{{FROM_TAG_DATE}}`</sub>
- <sub>**SHA256**: <sub>................................</sub>`${{ env.SHA256SUM }} ๐Ÿ”บ ${{ env.FILE_ZIP }}`</sub>
- <sub>**GUID**: <sub>.......................................</sub>`${{ steps.dotenv.outputs.GUID }}`</sub>
- <sub>**UUID**: <sub>.......................................</sub>`${{ steps.dotenv.outputs.UUID }}</sub>`
- <sub>**Stamp**: <sub>....................................</sub>`#{{FROM_TAG}}-#{{FROM_TAG_DATE}} ๐Ÿ”บ #{{TO_TAG}}-#{{TO_TAG_DATE}}`</sub>
- <sub>**Last Release**: <sub>......................</sub>`#{{DAYS_SINCE}} days ago`
</sup>

<br>

---

<br>

### What'\''s New
This release contains the following changes:

<br>

---

<br>

### Statistics
How the files have changed:
<ul><li><a href='\''#{{RELEASE_DIFF}}'\''>Changed files</a>  : <b>#{{CHANGED_FILES}}</b> </li><li>Commits : <b>#{{COMMITS}}</b> </li><li>Additions : <b>#{{ADDITIONS}}</b></li><li>Deletions : <b>#{{DELETIONS}}</b></li>
<br />
</ul>

<br>

---

<br>

### Commits (#{{UNCATEGORIZED_COUNT}})
#{{UNCATEGORIZED}}

<br>

---

<br>

### Pull Requests
#{{CHANGELOG}}

<br>

---

<br>

'

ESCAPED_TEMPLATE=${template//$'\n'/\n}
BUILT_JSON='{ "template": "'"$ESCAPED_TEMPLATE"'" }'

# to file
echo $BUILT_JSON > result.json

# to output for the step
echo "TEMPLATE_JSON=${BUILT_JSON}" >> "$GITHUB_OUTPUT"

(untested, but using the TEMPLATE_JSONshould work then theoretically)

That's an interesting work-around. Didn't even think about that.
I'll save this for tomorrow and try it out. I've been cleaning up my github actions all day, and I don't have the energy to rip one apart right now and start a new task lol

Luckily, this github action works great. I had to create a new action today which automatically builds a python script, pushes it to pypi, generates a changelog, and then issues a release on github. It sounds easy, but then there's 5 different inputs; which turns the damn action into a "Choose your own Adventure" with conditions all over the damn place. That drained my energy today lol. But it's fully automated now, and that's nice as hell to have instead of doing all those steps manually.

Cleaning out my list, so I'll close this for now. Appreciate the help. Need to find 5 minutes to try your method. Hopefully tomorrow.