-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: use own script for rendering a jinja2 template
It looks like the cuchi/jinja2-action action is currently broken [1]. Since all we need is to render a jinja2 template with string variables, then roll out a simple script Python using the "jinja2" module to do that. The script adds to the render context all the environment variables starting with the prefix "JINJA_", removing it. [1] cuchi/jinja2-action#17 Signed-off-by: Pino Toscano <[email protected]>
- Loading branch information
Showing
2 changed files
with
25 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
import sys | ||
|
||
import jinja2 | ||
|
||
|
||
env = jinja2.Environment() | ||
with open(sys.argv[1]) as f: | ||
tmpl = env.from_string(f.read()) | ||
context = {} | ||
for key, value in os.environ.items(): | ||
if key.startswith("JINJA_"): | ||
context[key[6:]] = value | ||
with open(sys.argv[2], "w") as f: | ||
print(tmpl.render(context), file=f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,16 +93,16 @@ jobs: | |
echo "git_version=$version" >> $GITHUB_OUTPUT | ||
- name: Generate galaxy.yml | ||
uses: cuchi/[email protected] | ||
with: | ||
template: ansible_collections/redhat/insights/galaxy.yml.j2 | ||
output_file: ansible_collections/redhat/insights/galaxy.yml | ||
strict: true | ||
variables: | | ||
collection_name=insights | ||
collection_namespace=${{ github.repository_owner }} | ||
collection_repo=https://github.com/${{ github.repository }} | ||
collection_version=${{ steps.git-version.outputs.git_version }} | ||
run: | | ||
set -euxo pipefail | ||
sudo apt-get --no-install-recommends -y install python3 python3-jinja2 | ||
python3 .github/scripts/jinja2-replace.py galaxy.yml.j2 galaxy.yml | ||
working-directory: ansible_collections/redhat/insights | ||
env: | ||
JINJA_collection_name: insights | ||
JINJA_collection_namespace: ${{ github.repository_owner }} | ||
JINJA_collection_repo: https://github.com/${{ github.repository }} | ||
JINJA_collection_version: ${{ steps.git-version.outputs.git_version }} | ||
|
||
- name: Run sanity tests | ||
uses: ansible-community/ansible-test-gh-action@release/v1 | ||
|