Skip to content

Commit

Permalink
gh-41: Add SuperLinter Workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fletort committed Nov 14, 2024
1 parent f7d5435 commit 978e77c
Show file tree
Hide file tree
Showing 23 changed files with 787 additions and 819 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# top-most EditorConfig file


[*.sh]
indent_style = space
indent_size = 2

[*.bats]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .github/linters/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[settings]
known_third_party=parameterized
known_first_party=entrypoint,action
23 changes: 23 additions & 0 deletions .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Unordered list style
MD004:
style: dash

# Ordered list item prefix
MD029:
style: one

# Spaces after list markers
MD030:
ul_single: 1
ol_single: 1
ul_multi: 1
ol_multi: 1

# Code block style
MD046:
style: fenced

# MD013/line-length - Line length
MD013:
line_length: 80
tables: false
10 changes: 10 additions & 0 deletions .github/linters/.yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rules:
document-end: disable
document-start:
level: warning
present: false
line-length:
level: warning
max: 80
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true
37 changes: 37 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Lint Codebase

on:
pull_request:
branches:
- main
- develop
push:
branches:
- main
- develop

permissions:
contents: read
packages: read
statuses: write

jobs:
lint:
name: Lint Codebase
runs-on: ubuntu-latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Lint Codebase
id: super-linter
uses: super-linter/super-linter/slim@v7
env:
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: true
VALIDATE_JSCPD: false
6 changes: 4 additions & 2 deletions .github/workflows/tags.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: 'Tags'
name: "Tags"
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
permissions:
contents: read
jobs:
tags:
runs-on: ubuntu-latest
name: 'Additional Tags'
name: "Additional Tags"
permissions:
contents: write
actions: write
Expand Down
42 changes: 20 additions & 22 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 @@ -164,12 +166,12 @@ jobs:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
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
Expand Down Expand Up @@ -202,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 @@ -263,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 @@ -294,8 +296,4 @@ jobs:
if: always()
with:
files: report.xml
check_name: 'Integ Test Results'




check_name: "Integ Test Results"
60 changes: 35 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# jinja2-template-action
Use Jinja2 template engine on multipe files as a GitHub action.

Use Jinja2 template engine on multipe files as a GitHub Action.

[![Continuous Testing](https://github.com/fletort/jinja2-template-action/actions/workflows/test.yml/badge.svg)](https://github.com/fletort/jinja2-template-action/actions/workflows/test.yml)
[![Coverage Status](https://coveralls.io/repos/github/fletort/jinja2-template-action/badge.svg?branch=main)](https://coveralls.io/github/fletort/jinja2-template-action?branch=main)
[![Testspace tests count](https://img.shields.io/testspace/total/fletort/fletort%3Ajinja2-template-action/main)](https://fletort.testspace.com/projects/68162/spaces)

This is a very simple version of the action, that is ok for my first need.
This is a very simple version of the action, that is OK for my first need.
Futur enhancement will come.

The actual "simple" version transform all local j2 files (recursively) ('*.j2')
The actual "simple" version transform all local j2 files (recursively) ('\*.j2')
with the jinja2 library.

The new file name is the same filename without the j2 extension.
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 All @@ -32,11 +36,14 @@ Environement variable as used as with the jinja2 cli, with a _kind_ of `environ`
```
Environment variables are used as with jinja2 cli:
```
```file
{{ environ('TEST') }}
```
Or as other contextual github information:
```

Or as other contextual GitHub information:

```file
{{ env.TEST }}
```

Expand All @@ -59,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 @@ -76,7 +83,7 @@ SMART=yoyo
MY_VAR=True
```

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

```file
---
Expand All @@ -99,47 +106,49 @@ EXEMPLE:
#### Related Jinja Template

For previous INI, YAML, JSON examples, jinja template will be:
```

```file
{{ EXEMPLE.SMART }}
{{ EXEMPLE.MY_VAR }}
```

For previous ENV example, jinja template will be:
```

```file
{{ EXEMPLE_SMART }}
{{ 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']`
Property dereference syntax: `github.sha`

```
```file
{{ github.repository }}
{{ job.status }}
{{ runner.os }}
{{ strategy.job_index }}
{{ 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


<!-- prettier-ignore-start -->
| Name | Description | Default |
| ---- | ----------- | ------- |
| `variables` | Variable to substitute in the jinja templates. Must be Key, value pairs in .env file format (key=value). | "" |
Expand All @@ -148,6 +157,7 @@ Note: All strategy information key contains dashes that must me marked as unders
| `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
Loading

0 comments on commit 978e77c

Please sign in to comment.