Skip to content

Commit

Permalink
Merge pull request #9 from CubicrootXYZ/jinja-validator
Browse files Browse the repository at this point in the history
add jinja validate workflow
  • Loading branch information
CubicrootXYZ authored Sep 2, 2024
2 parents bcd608c + 9d1fd70 commit 9c304f0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/jinja.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
workflow_call:
inputs:
workdir:
required: false
default: "./"
type: string

jobs:
validate:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
container:
image: cubicrootxyz/jinja:v0.0.3
options: --user root
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Run tests
run: (cd ${{ inputs.workdir }} && makejinja)
- name: Check for diffs
run: git diff --exit-code
7 changes: 7 additions & 0 deletions .github/workflows/jinja_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
on: push

jobs:
jinja:
uses: ./.github/workflows/jinja.yaml
with:
workdir: "tests/jinja/"
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,18 @@ jobs:
workdir: "tests/golang_test/"
services: '{"database": {"image": "mysql:8.0", "ports": ["3306:3306"]}}'
env: '{"TESTENV": "value"}'
```

## Jinja

### Validate generates are up to date

Add the following job to your CI to ensure `jinja` generated files are always up to date. Uses `makejinja` for templating.

```yaml
jobs:
jinja:
uses: CubicrootXYZ/Workflows/.github/workflows/[email protected]
with:
workdir: "tests/jinja/"
```
3 changes: 3 additions & 0 deletions tests/jinja/generated/testfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- a
- b
- c
3 changes: 3 additions & 0 deletions tests/jinja/makejinja.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[makejinja]
inputs = ["./templates"]
output = "./generated"
3 changes: 3 additions & 0 deletions tests/jinja/templates/testfile.yml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for item in ["a", "b", "c"] %}
- {{ item }}
{% endfor %}

0 comments on commit 9c304f0

Please sign in to comment.