Skip to content

Commit

Permalink
Merge pull request #108 from gliderlabs/lint-files
Browse files Browse the repository at this point in the history
feat: add linting to various files
  • Loading branch information
josegonzalez authored May 19, 2024
2 parents 38c4a34 + 0079224 commit 4d055af
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 43 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[Makefile]
insert_final_newline = true
indent_style = tab
indent_size = 4

[*.go]
insert_final_newline = true
indent_style = tab
indent_size = 4
6 changes: 6 additions & 0 deletions .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
default: true

# Line length
# https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md013
MD013: false
5 changes: 5 additions & 0 deletions .github/linters/.yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
extends: default

rules:
line-length: disable
69 changes: 69 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
name: "lint"

# yamllint disable-line rule:truthy
on:
pull_request:
branches:
- "*"
push:
branches:
- "main"

jobs:
hadolint:
name: hadolint
runs-on: ubuntu-22.04
steps:
- name: Clone
uses: actions/checkout@v4
- name: Run hadolint
uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf

markdown-lint:
name: markdown-lint
runs-on: ubuntu-22.04
steps:
- name: Clone
uses: actions/checkout@v4
- name: Run markdown-lint
uses: avto-dev/markdown-lint@04d43ee9191307b50935a753da3b775ab695eceb
with:
config: ".github/linters/.markdown-lint.yml"
args: "./README.md"

shellcheck:
name: shellcheck
runs-on: ubuntu-22.04
steps:
- name: Clone
uses: actions/checkout@v4
- name: Run shellcheck
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38
env:
SHELLCHECK_OPTS: -s bash
shfmt:
name: shfmt
runs-on: ubuntu-22.04
steps:
- name: Clone
uses: actions/checkout@v4
- name: Run shfmt
uses: luizm/action-sh-checker@c6edb3de93e904488b413636d96c6a56e3ad671a
env:
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
SHFMT_OPTS: -l -d -i 2
with:
sh_checker_shellcheck_disable: true
sh_checker_comment: true

yamllint:
name: yamllint
runs-on: ubuntu-22.04
steps:
- name: Clone
uses: actions/checkout@v4
- name: Run yamllint
uses: ibiqlik/action-yamllint@2576378a8e339169678f9939646ee3ee325e845c
with:
config_file: ".github/linters/.yamllint.yml"
File renamed without changes.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ build: prebuild
@$(MAKE) build/deb/$(NAME)_$(VERSION)_arm64.deb

build-docker-image:
docker build --rm -q -f Dockerfile.build -t $(IMAGE_NAME):build .
docker build --rm -q -f Dockerfile -t $(IMAGE_NAME):build .

$(targets): %-in-docker: .env.docker
docker run \
Expand Down
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Sigil

[![IRC Channel](https://img.shields.io/badge/irc-%23gliderlabs-blue.svg)](https://kiwiirc.com/client/irc.freenode.net/#gliderlabs)

Standalone string interpolator and template processor

```shell
echo '${name} is{{ range seq ${count:-3} }} cool{{ end }}!' | sigil -p name=Sigil
```
$ echo '${name} is{{ range seq ${count:-3} }} cool{{ end }}!' | sigil -p name=Sigil

```text
Sigil is cool cool cool!
```

Expand All @@ -28,8 +29,8 @@ Template text can be provided via STDIN or from a file if provided with the `-f`
flag. Any other arguments are key-values in the form `<key>=<value>`. They are
used as variables.

* `echo 'Hello, $name' | sigil -p name=Jeff`
* `sigil -p -f config.tmpl var1=foo "var2=Hello world"`
* `echo 'Hello, $name' | sigil -p name=Jeff`
* `sigil -p -f config.tmpl var1=foo "var2=Hello world"`

### Variables

Expand All @@ -38,9 +39,9 @@ used as variables.
There are two forms of variable syntax in Sigil. The first is POSIX style, which
among other features allows default values or enforces required values:

* `$variable` - normal POSIX style
* `${variable:-"default"}` - expansion with default value
* `${variable:?}` - fails when not set
* `$variable` - normal POSIX style
* `${variable:-"default"}` - expansion with default value
* `${variable:?}` - fails when not set

Environment variables are also available as POSIX style variables. This makes
Sigil great for quick and simple string interpolation.
Expand All @@ -51,7 +52,7 @@ The other syntax to use variables is consistent with the rest of the templating
syntax. It uses `{{` and `}}` to define template expressions. Variable expansion
in this form is simply used as:

* `{{ $variable }}`
* `{{ $variable }}`

You can do much more with this syntax, such as modifier pipelines. All of which
is explained below.
Expand All @@ -66,7 +67,7 @@ Instead of replacing all `{{` with `{{“{{”}}`, you can change the delimiters
by setting the `SIGIL_DELIMS` environment variable. It is the left and right
delimiter strings, separated by a coma.

```
```shell
SIGIL_DELIMS={{{,}}} sigil -i 'hello {{{ $name }}}' name=packer
```

Expand All @@ -76,26 +77,26 @@ There are a number of builtin functions that can be used as modifiers,
conditional tests, expansion data sources, and more. There are two references
for functions available:

* [Sigil builtins](http://godoc.org/github.com/gliderlabs/sigil/builtin)
* [Go template builtins](http://golang.org/pkg/text/template/#hdr-Functions)
* [Sigil builtins](http://godoc.org/github.com/gliderlabs/sigil/builtin)
* [Go template builtins](http://golang.org/pkg/text/template/#hdr-Functions)

Here are a few examples:

* `{{ $variable | capitalize }}`
* `{{ include "file.tmpl" "var1=foo" "var2=bar" }}`
* `{{ file "example.txt" | replace "old" "new" }}`
* `{{ json "file.json" | pointer "/Widgets/0/Name" }}`
* `{{ $variable | capitalize }}`
* `{{ include "file.tmpl" "var1=foo" "var2=bar" }}`
* `{{ file "example.txt" | replace "old" "new" }}`
* `{{ json "file.json" | pointer "/Widgets/0/Name" }}`

### Conditionals

* `{{ if expr }} true {{ end }}`
* `{{ if expr }} true {{ else }} false {{ end }}`
* `{{ if expr }} true {{ else if expr }} also true {{ end }}`
* `{{ if expr }} true {{ end }}`
* `{{ if expr }} true {{ else }} false {{ end }}`
* `{{ if expr }} true {{ else if expr }} also true {{ end }}`

### Loops / Iteration

* `{{ range expr }} element: {{.}} {{ end }}`
* `{{ range expr }} elements {{ else }} no elements {{ end }}`
* `{{ range expr }} element: {{.}} {{ end }}`
* `{{ range expr }} elements {{ else }} no elements {{ end }}`

### Full Syntax

Expand All @@ -106,4 +107,4 @@ documentation there.
## License

BSD
<img src="https://ga-beacon.appspot.com/UA-58928488-2/sigil/readme?pixel" />
![beacon](https://ga-beacon.appspot.com/UA-58928488-2/sigil/readme?pixel "beacon")
42 changes: 22 additions & 20 deletions tests/sigil.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck disable=all
GOOS=$(go env GOOS)
export SIGIL="${SIGIL:-build/${GOOS}/gliderlabs-sigil}-amd64"

Expand All @@ -17,7 +18,7 @@ T_posix_var_check() {
}

T_posix_var_check_unset() {
echo 'Hello, ${name:?}' | $SIGIL -p &> /dev/null
echo 'Hello, ${name:?}' | $SIGIL -p &>/dev/null
[[ $? -ne 0 ]]
}

Expand Down Expand Up @@ -87,52 +88,53 @@ T_splitkv_joinkv() {
}

T_json() {
result=$(echo '{"one": "two"}' | $SIGIL -i '{{ stdin | json | tojson }}')
[[ "$result" == "{\"one\":\"two\"}" ]]
result=$(echo '{"one": "two"}' | $SIGIL -i '{{ stdin | json | tojson }}')
[[ "$result" == "{\"one\":\"two\"}" ]]
}

T_json_deep() {
result=$(echo '{"foo": {"one": "two"}}' | $SIGIL -i '{{ stdin | json | tojson }}')
[[ "$result" == '{"foo":{"one":"two"}}' ]]
result=$(echo '{"foo": {"one": "two"}}' | $SIGIL -i '{{ stdin | json | tojson }}')
[[ "$result" == '{"foo":{"one":"two"}}' ]]
}

T_yaml() {
yaml="$(echo -e "one: two\nthree:\n- four\n- five")"
result="$(echo -e "$yaml" | $SIGIL -i '{{ stdin | yaml | toyaml }}')"
[[ "$result" == "$yaml" ]]
yaml="$(echo -e "one: two\nthree:\n- four\n- five")"
result="$(echo -e "$yaml" | $SIGIL -i '{{ stdin | yaml | toyaml }}')"
[[ "$result" == "$yaml" ]]
}

T_shell() {
result="$($SIGIL -i '{{ sh "date +%m-%d-%Y" }}')"
[[ "$result" == "$(date +%m-%d-%Y)" ]]
[[ "$result" == "$(date +%m-%d-%Y)" ]]
}

T_httpget() {
result="$($SIGIL -i '{{ httpget "https://httpbin.org/get" | json | pointer "/url" }}')"
[[ "$result" == "https://httpbin.org/get" ]]
[[ "$result" == "https://httpbin.org/get" ]]
}

T_custom_delim() {
result="$(SIGIL_DELIMS={{{,}}} $SIGIL -i '{{ hello {{{ $name }}} }}' name=packer)"
[[ "$result" == "{{ hello packer }}" ]]
[[ "$result" == "{{ hello packer }}" ]]
}

T_substr() {
result="$($SIGIL -i '{{ "abcdefgh" | substr "1:4" }}')"
[[ "$result" == "bcd" ]]
[[ "$result" == "bcd" ]]
}
T_substr_single_index() {
result="$($SIGIL -i '{{ "abcdefgh" | substr ":4" }}')"
[[ "$result" == "abcd" ]]
[[ "$result" == "abcd" ]]
}

T_yamltojson() {
result="$(printf 'joe:\n age: 32\n color: red' | $SIGIL -i '{{ stdin | yaml | tojson }}')"
[[ "$result" == '{"joe":{"age":32,"color":"red"}}' ]]
[[ "$result" == '{"joe":{"age":32,"color":"red"}}' ]]
}

T_yamltojsondeep() {
result="$( $SIGIL -i '{{ stdin | yaml | tojson }}' <<EOF
result="$(
$SIGIL -i '{{ stdin | yaml | tojson }}' <<EOF
a: Easy!
b:
c: 2
Expand All @@ -145,21 +147,21 @@ c:
- two
- tree
EOF
)"
[[ "$result" == '{"a":"Easy!","b":{"c":2,"d":[3,4]},"c":{"list":["one","two","tree"]}}' ]]
)"
[[ "$result" == '{"a":"Easy!","b":{"c":2,"d":[3,4]},"c":{"list":["one","two","tree"]}}' ]]
}

T_jmespath() {
result="$(echo '[{"name":"bob","age":20},{"name":"jim","age":30},{"name":"joe","age":40}]' | $SIGIL -i '{{stdin | json | jmespath "[? age >= `30`].name | reverse(@)" | join ","}}')"
[[ "$result" == 'joe,jim' ]]
[[ "$result" == 'joe,jim' ]]
}

T_base64enc() {
result="$(echo 'happybirthday' | $SIGIL -i '{{ stdin | base64enc }}')"
[[ "$result" == "aGFwcHliaXJ0aGRheQo=" ]]
[[ "$result" == "aGFwcHliaXJ0aGRheQo=" ]]
}

T_base64dec() {
result="$(echo 'aGFwcHliaXJ0aGRheQo=' | $SIGIL -i '{{ stdin | base64dec }}')"
[[ "$result" == "happybirthday" ]]
[[ "$result" == "happybirthday" ]]
}

0 comments on commit 4d055af

Please sign in to comment.