Skip to content

Commit 8fb5ea1

Browse files
authored
Merge pull request #1 from cuchi/add-tests
Add simple test case & workflow
2 parents 6b7599b + e07a85a commit 8fb5ea1

File tree

9 files changed

+79
-11
lines changed

9 files changed

+79
-11
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test/
2+
.github

.github/workflows/ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Continuous integration
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout VCS
12+
uses: actions/checkout@v1
13+
14+
- name: '[run] simple'
15+
uses: ./
16+
with:
17+
template: test/simple/template
18+
output_file: test/simple/result
19+
variables: foo=bar
20+
- name: '[test] simple'
21+
run: diff test/simple/result test/simple/expected
22+
23+
- name: '[run] many variables'
24+
uses: ./
25+
with:
26+
template: test/many-variables/template
27+
output_file: test/many-variables/result
28+
variables: |
29+
foo=bar
30+
baz=cux
31+
- name: '[test] many variables'
32+
run: diff test/many-variables/result test/many-variables/expected
33+
34+
- name: '[run] many variables (messy whitespace)'
35+
uses: ./
36+
with:
37+
template: test/many-variables/template
38+
output_file: test/many-variables/result
39+
variables: |
40+
foo=bar
41+
baz=cux
42+
43+
44+
45+
- name: '[test] many variables (messy whitespace)'
46+
run: diff test/many-variables/result test/many-variables/expected

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM dinutac/jinja2docker:2.1.3
22

3-
COPY entrypoint.sh /entrypoint.sh
3+
COPY entrypoint.py /entrypoint.py
44

5-
ENTRYPOINT ["/entrypoint.sh"]
5+
ENTRYPOINT ["/entrypoint.py"]

entrypoint.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import re
5+
import subprocess
6+
7+
params = [os.environ['INPUT_TEMPLATE']]
8+
9+
for variable in os.environ.get('INPUT_VARIABLES', '').split('\n'):
10+
clean_variable = variable.strip()
11+
if clean_variable != '':
12+
params.extend(['-D', clean_variable])
13+
14+
if os.environ.get('INPUT_STRICT') == 'true':
15+
params.append('--strict')
16+
17+
params.extend(['-o', os.environ['INPUT_OUTPUT_FILE']])
18+
19+
subprocess.run(['jinja2'] + params)

entrypoint.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/many-variables/expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
bar
3+
cux

test/many-variables/template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
{{ foo }}
3+
{{ baz }}

test/simple/expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
bar

test/simple/template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
{{ foo }}

0 commit comments

Comments
 (0)