Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
configuration
Commits
425f2f00
Commit
425f2f00
authored
Jan 06, 2015
by
Carson Gee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1767 from edx/cg/jinja2_check
Add a jinja2 syntax checker for Travis
parents
173c8e1a
ffc625ae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
.travis.yml
+10
-0
util/jinja_check.py
+31
-0
No files found.
.travis.yml
View file @
425f2f00
...
@@ -24,6 +24,16 @@ script:
...
@@ -24,6 +24,16 @@ script:
fi
fi
done
done
-
|
-
|
pushd playbooks
for j2 in $(git diff --name-only refs/heads/master..$(git rev-parse --abbrev-ref HEAD) |grep -E '.+\.j2$|.+\.yml'); do
python ../util/jinja_check.py ../$j2
if [[ $? -ne 0 ]]; then
echo "Jinja parsing error on $j2"
exit 1
fi
done
popd
-
|
set -e
set -e
cd playbooks/edx-east
cd playbooks/edx-east
ROLE_DIRS=$(/bin/ls -d roles/*)
ROLE_DIRS=$(/bin/ls -d roles/*)
...
...
util/jinja_check.py
0 → 100755
View file @
425f2f00
#!/usr/bin/env python
import
os
import
sys
from
jinja2
import
FileSystemLoader
from
jinja2
import
Environment
as
j
from
jinja2.exceptions
import
UndefinedError
from
ansible.utils.template
import
_get_filters
,
_get_extensions
from
yaml.representer
import
RepresenterError
input_file
=
sys
.
argv
[
1
]
if
not
os
.
path
.
exists
(
input_file
):
print
(
'{0}: deleted in diff'
.
format
(
input_file
))
sys
.
exit
(
0
)
# Setup jinja to include ansible filters
j_e
=
j
(
trim_blocks
=
True
,
extensions
=
_get_extensions
())
j_e
.
loader
=
FileSystemLoader
([
'.'
,
os
.
path
.
dirname
(
input_file
)])
j_e
.
filters
.
update
(
_get_filters
())
# Go ahead and catch errors for undefined variables and bad yaml
# from `to_nice_yaml` ansible filter
try
:
j_e
.
from_string
(
file
((
input_file
))
.
read
())
.
render
(
func
=
lambda
:
None
)
except
(
UndefinedError
,
RepresenterError
),
ex
:
pass
except
TypeError
,
ex
:
if
ex
.
message
!=
'Undefined is not JSON serializable'
:
raise
Exception
(
ex
.
message
)
pass
print
(
'{}: ok'
.
format
(
input_file
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment