Skip to content

Commit

Permalink
First Version
Browse files Browse the repository at this point in the history
  • Loading branch information
fletort committed Jul 15, 2024
1 parent 228779c commit b25cdca
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 0 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: 'Continuous Testing'

on:
pull_request:
branches:
- main
push:

permissions:
contents: read

jobs:
test-script:
name: Script Tests
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Install bats
id: install-bats
run: ./test/install_bats.sh

- name: Install Jinja2-cli
id: install-jinja2
run: pip install jinja2-cli

- name: Test
id: script-test
run: ./test/bats/bin/bats --report-formatter junit test/test_process_file.bats

- name: Testspace client install & config
id: testspace_init
if: always() && hashFiles('report.xml') != ''
uses: testspace-com/setup-testspace@v1
with:
domain: ${{github.repository_owner}}

- name: Testspace push test content
if: always() && (steps.testspace_init.outcome == 'success')
run: |
testspace "[Unit Tests]report.xml"
- name: Publish Test Results in GitHub
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: report.xml
check_name: 'Unit Test Results'

- name: TEMP
uses: actions/upload-artifact@v4
with:
name: unit
path: report.xml

test-action:
name: GitHub Actions Test
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
if: (github.event_name == 'pull_request') && (github.base_ref == 'main')
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Install bats
id: install-bats
run: ./test/install_bats.sh

- name: Test Local Action
id: test-action
uses: ./
env:
TEST: integ

- name: Check If Template file is managed
id: test-action-result
run: ./test/bats/bin/bats --report-formatter junit test/test_action.bats

- name: Testspace client install & config
id: testspace_init
if: always() && hashFiles('report.xml') != ''
uses: testspace-com/setup-testspace@v1
with:
domain: ${{github.repository_owner}}

- name: Testspace push test content
if: always() && (steps.test-action-result.outcome == 'success')
run: |
testspace "[Integ Tests]report.xml"
- name: Publish Test Results in GitHub
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: report.xml
check_name: 'Integ Test Results'

- name: TEMP
uses: actions/upload-artifact@v4
with:
name: integ
path: report.xml




2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# bats junit test result file
report.xml
19 changes: 19 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Jinja2 Engine Repo'
description: 'Use the Jinja2 templating engine on multiple files'
author: 'fletort'
branding:
icon: 'sliders'
color: 'red'
# inputs:
# templates_mask:
# description:
# 'Mask Used to detect templates files'
# default: '*.j2'
runs:
using: 'composite'
steps:
- name: "Manage Dynamic Template"
shell: bash
run: |
pip install jinja2-cli
find . -name '*.j2' -exec ./process_file.sh {} \;
6 changes: 6 additions & 0 deletions process_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
template_file=$1
# remove j2 extension
final_file="${template_file%.*}"
jinja2 $template_file > $final_file
rm $template_file
2 changes: 2 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bats
test_helper
4 changes: 4 additions & 0 deletions test/install_bats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
git -c advice.detachedHead=false clone --depth 1 --branch v1.11.0 https://github.com/bats-core/bats-core.git test/bats
git -c advice.detachedHead=false clone --depth 1 --branch v2.1.0 https://github.com/bats-core/bats-assert.git test/test_helper/bats-assert
git -c advice.detachedHead=false clone --depth 1 --branch v0.4.0 https://github.com/bats-core/bats-file.git test/test_helper/bats-file
1 change: 1 addition & 0 deletions test/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ environ('TEST') }}
13 changes: 13 additions & 0 deletions test/test_action.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bats

setup() {
load 'test_helper/bats-assert/load'
load 'test_helper/bats-file/load'
}

@test "action result" {
assert_file_not_exist test/template.j2
assert_file_exist test/template
content=$(cat test/template)
assert_equal $content 'integ'
}
22 changes: 22 additions & 0 deletions test/test_process_file.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bats

setup() {
load 'test_helper/bats-assert/load'
load 'test_helper/bats-file/load'
}

@test "rename template file" {
cp test/template.j2 test.txt.j2
./process_file.sh test.txt.j2
assert_file_exist test.txt
rm test.txt
}

@test "process template file" {
cp test/template.j2 test.txt.j2
export TEST=toto
./process_file.sh test.txt.j2
content=$(cat test.txt)
assert_equal $content 'toto'
rm test.txt
}

0 comments on commit b25cdca

Please sign in to comment.