Skip to content

srz-zumix/kamidana-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

kamidana-action

kamidana is yet another jinja2's cli wrapper.

Features

Usage

GitHub Context Example

default-example.j2

{{ github.job }}
{{ github.workflow }}
{{ job.status }}
{{ github.ref_protected | ternary('protected', '') }}
{{ github.ref | regex_replace('refs/.*/(.*)', '\1') }}
{{ github.ref_name | b64encode }}
{{ github.ref | b64encode | b64decode }}
{{ runner.name }} ({{ runner.os }}/{{ runner.arch }})
{% set template_filename = github.workspace + "/testdata/default-example.j2" -%}
{{ template_filename | basename }}
{{ template_filename | read_from_file }}
{%- for url in (github | json_query('[*.url,*.*.url,*.*.*.url] | [] | [] | []')) %}
* {{ url }}
{%- endfor %}

{{ github | to_nice_yaml }}

default-example.yml

name: Default-Example
on:
  pull_request:

jobs:
  default-example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: kamidana
        id: kamidana
        uses: srz-zumix/kamidana-action@main
        with:
          template: testdata/default-example.j2
          output_file: test.txt
          tee: true
      - run: |
          cat << 'EOS' | tee output.txt
          ${{ steps.kamidana.outputs.text }}
          EOS
          diff output.txt test.txt

runs

Variable / Data file Example

variables-and-data-file-example.j2

{{ github.job }}
{{ github.workflow }}
{{ name }}
{{ sample }}
{{ replace_uses_to }}
{{ links.kamidana }}

variables-and-multi-data-file-example.yml

name: Variables-And-Multi-Data-File-Example
on:
  pull_request:

jobs:
  variables-and-multi-data-file-example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: kamidana
        id: kamidana
        uses: srz-zumix/kamidana-action@main
        with:
          template: testdata/variables-and-data-file-example.j2
          output_file: test.txt
          tee: true
          data_files: |
            readme/replace-uses.json
            readme/links.json
          variables: |
            sample: test
            name: srz-zumix
      - run: |
          cat << 'EOS' | tee output.txt
          ${{ steps.kamidana.outputs.text }}
          EOS
          diff output.txt test.txt

runs

Additionals Example

additionals-example.j2

{{ "srz_zumix" | slack_user_id | slack_user_presence | surprised }}

* rust-*
{%- set compilers = wandbox_list() | wandbox_fnmatch_compilers("rust-*") %}
{%- for compiler in compilers %}
  * {{ compiler.name }}
{%- endfor %}

surprised.py

from kamidana import (
    as_filter,
)


@as_filter
def surprised(v):
    return "{}!!".format(v)

additionals-example.yml

name: Additionals-Example
on:
  pull_request:

env:
  SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}

jobs:
  additionals-example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: kamidana
        id: kamidana
        uses: srz-zumix/kamidana-action@main
        with:
          template: testdata/additionals-example.j2
          output_file: test.txt
          tee: true
          requirements: |
            yurumikuji
            amaterasu-j2
          additonals: |
            yurumikuji.yurumikuji
            amaterasu.amaterasu
            testdata/surprised.py
      - run: |
          cat << 'EOS' | tee output.txt
          ${{ steps.kamidana.outputs.text }}
          EOS
          diff output.txt test.txt

runs

IO Example

io-example.j2

{{ "." | abspath }}
{{ "." | abspath | basename }}
{{ "." | listdir }}
{{ "LICENSE" | relativepath }}
{% if ("LICENSE" | path_exists) %}
    {{ "LICENSE" | read_from_file(relative_self=False) }}
{% endif %}

io-example.yml

name: IO-Example
on:
  pull_request:

jobs:
  io-example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: kamidana
        id: kamidana
        uses: srz-zumix/kamidana-action@main
        with:
          template: testdata/io-example.j2
          output_file: test.txt
          tee: true
      - run: |
          cat << 'EOS' | tee output.txt
          ${{ steps.kamidana.outputs.text }}
          EOS
          diff output.txt test.txt

  io-example-wd:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: kamidana
        id: kamidana
        uses: srz-zumix/kamidana-action@main
        with:
          template: io-example.j2
          output_file: test.txt
          tee: true
          working-directory: testdata
      - run: |
          cat << 'EOS' | tee output.txt
          ${{ steps.kamidana.outputs.text }}
          EOS
          diff output.txt testdata/test.txt

runs

Extensions Example

extensions-example.j2

{# with with. with_ extension is used. #}
{%- with msg = "hello"%}
{{msg}}
{%- with msg = "world"%}
  {{msg}}
{%- endwith %}
{{msg}}
{%- endwith %}

## counting
{#- with break and continue. loopcontrolls extension is used. #}

{%- for i in range(10) %}
{%- if i % 3 == 0 %}{% continue %} {% endif %}
{%- if i == 5 %}{% break %} {% endif %}
- {{i}}
{%- endfor %}

## do

{%- set xs = [] %}
{%- for i in range(10) %}
{%- do xs.append(i) %}
{%- endfor %}
{{xs}}

extensions-example.yml

name: Extensions-Example
on:
  pull_request:

jobs:
  extensions-example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: kamidana
        id: kamidana
        uses: srz-zumix/kamidana-action@main
        with:
          template: testdata/extensions-example.j2
          output_file: test.txt
          tee: true
          extensions: |
            i18n
            do
            loopcontrols
            debug
      - run: |
          cat << 'EOS' | tee output.txt
          ${{ steps.kamidana.outputs.text }}
          EOS
          diff output.txt test.txt

runs