Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into 29-devops-add-supe…
Browse files Browse the repository at this point in the history
…rlinter
  • Loading branch information
fletort committed Nov 13, 2024
2 parents e2511d9 + f7d5435 commit fa336fc
Show file tree
Hide file tree
Showing 15 changed files with 737 additions and 383 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# top-most EditorConfig file


[*.sh]
indent_style = space
indent_size = 2
4 changes: 2 additions & 2 deletions .github/workflows/tags.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Tags'
name: "Tags"
on:
push:
tags:
Expand All @@ -8,7 +8,7 @@ permissions:
jobs:
tags:
runs-on: ubuntu-latest
name: 'Additional Tags'
name: "Additional Tags"
permissions:
contents: write
actions: write
Expand Down
51 changes: 30 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Continuous Testing'
name: "Continuous Testing"

on:
push:
Expand Down Expand Up @@ -54,25 +54,27 @@ jobs:
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'
thresholds: "60 80"

# As irongut/CodeCoverageSummary does not support file by file mode, add it
# See https://github.com/irongut/CodeCoverageSummary/issues/236
- name: Write Coverage to Job Summary
run: |
cat code-coverage-results.md > my-code-coverage-results.md
echo "\`\`\`" >> my-code-coverage-results.md
coverage report >> my-code-coverage-results.md
echo "\`\`\`" >> my-code-coverage-results.md
cat my-code-coverage-results.md >> $GITHUB_STEP_SUMMARY
{
cat code-coverage-results.md
echo "\`\`\`"
coverage report
echo "\`\`\`"
} > my-code-coverage-results.md
echo my-code-coverage-results.md >> "$GITHUB_STEP_SUMMARY"
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: my-code-coverage-results.md

- name: Testspace client install & config
id: testspace_init
if: always() && hashFiles('report.xml') != ''
Expand All @@ -87,14 +89,14 @@ jobs:
REGEX="(https://[a-z0-9]+.testspace.com/spaces/[0-9]+/result_sets/[0-9]+)"
[[ $output =~ $REGEX ]]
result_set_link="${BASH_REMATCH[1]}"
echo "[TestSpace Test Result set]($result_set_link)" >> $GITHUB_STEP_SUMMARY
echo "[TestSpace Test Result set]($result_set_link)" >> "$GITHUB_STEP_SUMMARY"
- 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'
check_name: "Unit Test Results"

test-action-matrix:
name: Test With Matrix
Expand All @@ -105,7 +107,7 @@ jobs:
strategy:
matrix:
test: [1]
env:
env:
VAR_TEST1_VALUE: mytest
VAR_TEST2_VALUE: isfunny
FILE_KEY_1_VALUE: myfile
Expand Down Expand Up @@ -153,18 +155,29 @@ jobs:
echo "${{ env.FILE_KEY_1_VALUE }}" >> expected
echo "{{ exemple.FILE_KEY_2 }}" >> all_test.j2
echo "${{ env.FILE_KEY_2_VALUE }}" >> expected
echo "{{ url.URL_KEY_1 }}" >> all_test.j2
echo "from_url" >> expected
echo "{{ url.URL_KEY_2 }}" >> all_test.j2
echo "it_is_working" >> expected
echo "" >> all_test.j2
cat all_test.j2
cat expected
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_OUTPUT"
id: extract_branch

- name: Test Local Action
id: test-action
uses: ./
uses: ./
with:
#keep_template: true
data_file: test-data.yml
data_format: yaml
data_url: https://raw.githubusercontent.com/${{ github.repository }}/refs/heads/${{ steps.extract_branch.outputs.branch }}/test/url_data.yml
data_url_format: yaml
variables: |
TEST1=${{ env.VAR_TEST1_VALUE }}
TEST2=${{ env.VAR_TEST2_VALUE }}
Expand All @@ -191,15 +204,15 @@ jobs:
if: always()
with:
files: report.xml
check_name: 'Integ Test Results'
check_name: "Integ Test Results"

test-action-no-matrix:
name: Test Without Matrix
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
env:
env:
VAR_TEST1_VALUE: mytest
VAR_TEST2_VALUE: isfunny
FILE_KEY_1_VALUE: myfile
Expand Down Expand Up @@ -252,7 +265,7 @@ jobs:
- name: Test Local Action
id: test-action
uses: ./
uses: ./
with:
#keep_template: true
data_file: test-data.yml
Expand Down Expand Up @@ -283,8 +296,4 @@ jobs:
if: always()
with:
files: report.xml
check_name: 'Integ Test Results'




check_name: "Integ Test Results"
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ with the jinja2 library.
The new filename is the same filename without the j2 extension.
For exemple, `README.md.j2` becomes `README.md`.

It this version, it can only be used with environment variable, see my [test template file](./test/template.j2).
It this version, it can only be used with environment variable,
see my [test template file](./test/template.j2).

Environement variable as used as with the jinja2 cli, with a _kind_ of `environ` method :
Environement variable as used as with the jinja2 cli,
with a _kind_ of `environ` method :

```file
{{ environ('TEST') }}
Expand Down Expand Up @@ -64,7 +66,7 @@ Or as other contextual GitHub information:
data_format: json # can be detected automatically (see below)
```
Possible data type are: env, yaml, json, ini
Possible data type are: `env`, `yaml`, `json`, `ini`

#### 1. env file

Expand All @@ -81,7 +83,7 @@ SMART=yoyo
MY_VAR=True
```

#### 3. yaml
#### 3. YAML

```file
---
Expand Down Expand Up @@ -117,16 +119,16 @@ For previous ENV example, jinja template will be:
{{ EXEMPLE_MY_VAR }}
```

### Using Workflow Github contextual Information
### Using Workflow GitHub contextual Information

Some of the [contextual information about workflow runs](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs)
are available inside your jinja Template:

- github
- job
- runner
- strategy
- matrix
- `github`
- `job`
- `runner`
- `strategy`
- `matrix`

As part of an expression, you can access context information using one of two syntaxes.
Index syntax: `github['sha']`
Expand All @@ -140,7 +142,9 @@ Property dereference syntax: `github.sha`
{{ matrix.your_matrix_variable_name }}
```

Note: All strategy information key contains dashes that must me marked as underscore in jinja expression: `${{ strategy.job-index }}` becomes `{{ strategy.job_index }}`.
Note: All strategy information key contains dashes that must me marked as
underscore in jinja expression: `${{ strategy.job-index }}` becomes
`{{ strategy.job_index }}`.

### Actions inputs

Expand All @@ -150,7 +154,9 @@ Note: All strategy information key contains dashes that must me marked as unders
| `variables` | Variable to substitute in the jinja templates. Must be Key, value pairs in .env file format (key=value). | "" |
| `keep_template` | Put to `true` to keep original template file. | `false` |
| `data_file` | Source file contening inputs variable for the jinja template. | "" |
| `data_format` | Format of the `data_file`. Can be `env`, `ini`, `yaml`, `json` or `automatic` (for automatic detection). The automatic detction is based on the extension then on the content. | `automatic` |
| `data_format` | Format of the `data_file`. Can be `env`, `ini`, `yaml`, `json` or `automatic` (for automatic detection). The automatic detection is based on the extension then on the content. | `automatic` |
| `data_url` | URL Link contening inputs variable for the jinja template. | "" |
| `data_url_format` | Format of the `data_url`. Can be `env`, `ini`, `yaml`, `json` or `automatic` (for automatic detection). The automatic detection is based on the http header content-type then on the content itself. | `automatic` |
<!-- prettier-ignore-end -->

## Code Quality
Expand Down
46 changes: 29 additions & 17 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
name: 'Jinja2 Engine Repo'
description: 'Use the Jinja2 templating engine on multiple files'
author: 'fletort'
name: "Jinja2 Engine Repo"
description: "Use the Jinja2 templating engine on multiple files"
author: "fletort"
branding:
icon: 'sliders'
color: 'red'
icon: "sliders"
color: "red"
inputs:
variables:
description:
'Key, value pairs in .env file format (key=value)'
description: "Key, value pairs in .env file format (key=value)"
required: false
default: ''
default: ""
keep_template:
description:
'Put to `true` to keep original template file.'
description: "Put to `true` to keep original template file."
default: false
data_file:
description:
'Source file contening inputs variable for the jinja template.'
default: ''
description: "Source file contening inputs variable for the jinja template."
default: ""
data_format:
description:
'Format of the `data_file`. Can be `env`, `ini`, `yaml`, `json` or `automatic` (for automatic detection). The automatic detction is based on the extension then on the content.'
description: "Format of the `data_file`. Can be `env`, `ini`, `yaml`, `json` or `automatic` (for automatic detection). The automatic detction is based on the extension then on the content."
default: automatic
data_url:
description: "Link to a file contening inputs variable for the jinja template."
default: ""
data_url_format:
description: "Format of the `url_file`. Can be `env`, `ini`, `yaml`, `json` or `automatic` (for automatic detection). The automatic detction is based on the content-type http header then on the content."
default: automatic
runs:
using: 'composite'
using: "composite"
steps:
- name: "Manage Dynamic Template"
shell: bash
Expand Down Expand Up @@ -53,7 +55,17 @@ runs:
data_format="--data_format=${{inputs.data_format}}"
fi
fi
python3 ${{github.action_path}}/entrypoint.py ${keep_template} ${data_file} ${data_format} \
data_url=""
data_url_format=""
if [[ ! -z "${{inputs.data_url}}" ]];then
data_url="--data_url=${{inputs.data_url}}"
if [[ "${{inputs.data_url_format}}" != "automatic" ]]; then
data_url_format="--data_url_format=${{inputs.data_url_format}}"
fi
fi
python3 ${{github.action_path}}/entrypoint.py ${keep_template} \
${data_file} ${data_format} \
${data_url} ${data_url_format} \
--var_file ${{ runner.temp }}/build_logs/inputs_variables.env \
--context ${{ runner.temp }}/build_logs/github.json \
--context ${{ runner.temp }}/build_logs/job.json \
Expand Down
Loading

0 comments on commit fa336fc

Please sign in to comment.