Skip to content

Commit

Permalink
✨ Add support for compiling Jinja-style templates with Nunjucks in sy…
Browse files Browse the repository at this point in the history
…nc process (#271)

* Add `nunjucks` and update `@actions/core`

* Read template info from YAML config file

* Render templates when copying files

* Compile JS files into action

* Add documentation about the templating feature

* update readme

Co-authored-by: Maximilian Schiller <schiller@mxis.ch>
  • Loading branch information
dhruvkb and BetaHuhn authored Nov 17, 2022
1 parent f5e582f commit a2677cb
Show file tree
Hide file tree
Showing 7 changed files with 9,262 additions and 507 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ With [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action)
- Create a pull request in the target repo so you have the last say on what gets merged
- Automatically label pull requests to integrate with other actions like [automerge-action](https://github.com/pascalgn/automerge-action)
- Assign users to the pull request
- Render [Jinja](https://jinja.palletsprojects.com/)-style templates as use variables thanks to [Nunjucks](https://mozilla.github.io/nunjucks/)

## 📚 Usage

Expand Down Expand Up @@ -202,6 +203,54 @@ user/repo:
replace: false
```

### Using templates

You can render templates before syncing by using the [Jinja](https://jinja.palletsprojects.com/)-style template syntax. It will be compiled using [Nunjucks](https://mozilla.github.io/nunjucks/) and the output written to the specific file(s) or folder(s).

Nunjucks supports variables and blocks among other things. To enable, set the `template` field to a context dictionary, or in case of no variables, `true`:

```yml
user/repo:
- source: src/README.md
template:
user:
name: 'Maxi'
handle: '@BetaHuhn'
```

In the source file you can then use these variables like this:

```yml
# README.md
Created by {{ user.name }} ({{ user.handle }})
```

Result:

```yml
# README.md
Created by Maxi (@BetaHuhn)
```

You can also use `extends` with a relative path to inherit other templates. Take a look at Nunjucks [template syntax](https://mozilla.github.io/nunjucks/templating.html) for more info.

```yml
user/repo:
- source: .github/workflows/child.yml
template: true
```

```yml
# child.yml
{% extends './parent.yml' %}
{% block some_block %}
This is some content
{% endblock %}
```

### Delete orphaned files

With the `deleteOrphaned` option you can choose to delete files in the target repository if they are deleted in the source repository. The option defaults to `false` and only works when [syncing entire directories](#sync-entire-directories):
Expand Down
Loading

0 comments on commit a2677cb

Please sign in to comment.