Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

add template engine functionality to support generic templates #262

Merged
merged 48 commits into from
Feb 1, 2023

Conversation

galargh
Copy link
Contributor

@galargh galargh commented Dec 22, 2021

Template engine

I created a README.md that describes the template engine from the end user perspective i.e. what the syntax is, what objects are available, etc.

On the backend, I use perl to:

  1. perform a regex match on \${{{(.?*)}}};
  2. execute jq with the matched group as a filter and context JSON object;
  3. replace the match with jq output

Extra files

The newly added extra_files config field can be used to request copying of extra files while not modifying the files value from defaults.

Use-case example

See #434

Testing

@galargh galargh marked this pull request as ready for review January 10, 2022 09:34
Copy link
Contributor

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the sync-release-assets the only use case for this?
It seems like this could be easier accomplished by just publishing a GH Actions Workflow and manually calling this workflow from the two (?) repos that care about it, no?

templates/README.md Outdated Show resolved Hide resolved
# replace $default-branch with this repo's GitHub default branch
sed -i "s:\$default-branch:${{ env.DEFAULTBRANCH }}:g" $tmp
# replace template contexts with values from the JSON context object
perl -pi -e "s#$regexp#$replacement#ge" $tmp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

templates/README.md Outdated Show resolved Hide resolved
Co-authored-by: Marten Seemann <[email protected]>
@galargh
Copy link
Contributor Author

galargh commented Jan 10, 2022

Is the sync-release-assets the only use case for this?

It is a concrete example that I decided to use when working on templating functionality but it is not the only use case. Deploying issue templates is another example that was mentioned here #57

It seems like this could be easier accomplished by just publishing a GH Actions Workflow and manually calling this workflow from the two (?) repos that care about it, no?

Yes, it is possible to manually copy the workflow file to interested repositories to achieve the same but I believe it is a pretty good fit for this repository to be the one distributing it. At the moment there are only 2 but I think there might be more to come. @lidel might be able to elaborate on this.

@galargh

This comment was marked as outdated.

@galargh galargh requested a review from a team as a code owner January 3, 2023 08:29
@laurentsenta
Copy link
Contributor

laurentsenta commented Jan 12, 2023

2 notes:

  • I couldn't get an exit code != 0 if the templated variable was missing, could be my env when I tested, the expansion was "just" null without error.
  • Do we have a complexity threshold when we want to move these to "something other than shell scripts"?

@galargh
Copy link
Contributor Author

galargh commented Feb 1, 2023

  • I couldn't get an exit code != 0 if the templated variable was missing, could be my env when I tested, the expansion was "just" null without error.

That's expected and that's fine for what it's trying to be right now.

  • Do we have a complexity threshold when we want to move these to "something other than shell scripts"?

I think if we ever need to develop the functionality further, we should consider alternatives.

I've been able to simplify the setup by moving the config to env section of the step. Tested: https://github.com/protocol/.github/actions/runs/4064327038

@galargh galargh merged commit 0ca23d6 into master Feb 1, 2023
@galargh galargh deleted the sync-release-assets branch February 1, 2023 12:36
@galargh galargh mentioned this pull request Feb 1, 2023
10 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Templating
3 participants