Skip to content

Commit

Permalink
Add basic CI (#3)
Browse files Browse the repository at this point in the history
* docs: rename sample
* docs: add logos
* test: fix and add several new tests and examples
* ci: add release CI
* ci: add Homebrew formula and template
* ci: add publishing of the debian package
* ci: add tera itself to the ci
* ci: add template for the changelog
  • Loading branch information
chevdor authored Jun 16, 2021
1 parent 52354f0 commit e3b7185
Show file tree
Hide file tree
Showing 32 changed files with 15,255 additions and 64 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/build-readme.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/quick-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
name: Quick check

on:
push
push:
tags-ignore:
- v*

jobs:
quick_check:
Expand Down
110 changes: 110 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Release

on:
push:
tags:
- "v*"

jobs:
linux:
env:
TARGET_DIR: target/release

runs-on: ubuntu-latest
steps:
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy
- uses: actions/checkout@v2
- name: Install cargo deb
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-deb

- name: Build debian package
shell: bash
run: |
cargo deb -p tera-cli -o "tera-cli_linux_amd64.deb"
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: linux
path: "tera-cli_linux_amd64.deb"

create_draft:
needs: ["linux"]
name: Create Draft
runs-on: ubuntu-latest
outputs:
release_url: ${{ steps.create-release.outputs.html_url }}
asset_upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- uses: actions/checkout@v2
- name: Get Release Version
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
- uses: actions/download-artifact@v2

- name: Install tera v0.1.0
run: |
URL=https://github.com/chevdor/tera-cli/releases/download/v0.1.0-ae9bc49c/tera-cli_linux_amd64.deb
wget $URL
sudo dpkg -i tera-cli_linux_amd64.deb
tera --version
- name: Generate changelog
id: change_log
run: |
LAST_TAG=$(git describe --tags --abbrev=0)
JSON=$(git log $LAST_TAG..HEAD \
--pretty=format:'{ "commit": "%H", "short_sha": "%h", "author": "%an", "date": "%ad", "message": "%s"},' \
$@ | \
perl -pe 'BEGIN{print "{ \"since\": \"'${LAST_TAG}'\", \"commits\": ["}; END{print "]}"}' | \
perl -pe 's/},]/}]/')
CHANGELOG=$(echo $JSON | tera --template templates/changelog.md --stdin)
echo "::set-output name=changes::$CHANGELOG"
- name: Render release notes
run: |
export DEBIAN_URL="https://github.com/chevdor/tera-cli/releases/download/${{ env.RELEASE_VERSION }}/linux/tera-cli_linux_amd64.deb"
export CHANGELOG="${{ steps.change_log.outputs.changes }}"
tera --env --env-only --template templates/release.md > RELEASE_NOTES.md
- name: Create Release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_VERSION }}
release_name: Tera ${{ env.RELEASE_VERSION }} (${{ env.SHORT_SHA }})
body_path: ./RELEASE_NOTES.md
draft: false

publish-binaries:
runs-on: ubuntu-latest
needs: ["create_draft"]
steps:
- uses: actions/checkout@v2
- name: Get Release Version
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
- uses: actions/download-artifact@v2

- name: Upload binaries
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_draft.outputs.asset_upload_url }}
asset_path: "linux/tera-cli_linux_amd64.deb"
asset_name: "tera-cli_linux_amd64.deb"
asset_content_type: application/vnd.debian.binary-package
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ authors = ["chevdor <chevdor@gmail.com>"]
edition = "2018"
name = "tera-cli"
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
description = "A command line utility written in Rust to render templates from json|toml|yaml && ENV, using the tera templating engine"
readme = "README.md"
license = "MIT"

[dependencies]
clap = "3.0.0-beta.2"
Expand All @@ -18,13 +19,21 @@ toml = {version = "0.5.8", optional = false}

[dev-dependencies]
assert_cmd = "1.0.5"

# [features]
# default = ["with_json"]
# with_json = []
# with_toml = ["toml"]
# with_yaml = ["serde_yaml"]
predicates = "1.0.8"

[[bin]]
name = "tera"
path = "src/main.rs"

[package.metadata.deb]
assets = [
["target/release/tera", "usr/bin/", "755"],
]
copyright = "2021, Wilfried Kopp aka. Chevdor <chevdor@gmail.com>"
depends = "$auto"
extended-description = """\
tera-ci offers powerful features related to your environment variables, allowing you to control the output **both** from the context data you pass but also from the ENV variables set on your system."""
license-file = ["LICENSE", "0"]
maintainer = "Wilfried Kopp aka. Chevdor <chevdor@gmail.com>"
priority = "optional"
section = "utility"
9 changes: 9 additions & 0 deletions Formula/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
You may test your template/data with:

c watch -i Formula/tera.rb -s "tera -t Formula/template.tera Formula/data.yaml -o Formula/tera.rb"

and render with:

tera -t Formula/template.tera Formula/data.yaml -o Formula/tera.rb

NOTE: The template covers a few default values so you don't need to pass everything.
7 changes: 7 additions & 0 deletions Formula/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Tera
site: https://github.com
repo: chevdor/tera-cli
archive: "{{ name }}-mac-v1.2.3.tar.gz"
description: A command line utility written in Rust to render templates from json|toml|yaml && ENV, using the tera templating engine
version: 1.2.3
sha256: 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
11 changes: 11 additions & 0 deletions Formula/tera.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Tera < Formula
desc "A command line utility written in Rust to render templates using the tera templating engine"
homepage "https://github.com/chevdor/tera-cli"
url "https://github.com/chevdor/tera-cli/releases/download/v1.2.3/{{ name }}-mac-v1.2.3.tar.gz.tar.gz "
sha256 "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"
version "1.2.3"

def install
bin.install "tera"
end
end
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2021 - Wilfried Kopp aka. Chevdor <chevdor@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Tera cli
# tera-cli

[tera](https://github.com/Keats/tera) is a template engine written in Rust and inspired by Jinja2. It allows merging some data called `context data` into a template and produces a new output.
## Intro

This project is a command line for the [tera template engine](https://github.com/Keats/tera). This project is called `tera-cli` but the command installed on your system is simply `tera`.
![tera cli logo 256](resources/logo/tera-cli-logo_256.png)

[tera](https://github.com/Keats/tera) is a template engine written in Rust and inspired by Jinja2. It allows merging some data called `context data` into a template and produces a new output. This project, `tera-cli`, is a command line for the [tera template engine](https://github.com/Keats/tera).

This project is called `tera-cli` but the command installed on your system is simply `tera`.

`tera-ci` offers powerful features related to your environment variables, allowing you to control the output **both** from the context data you pass but also from the ENV variables set on your system.

## Example

Here is a basic example. For instance, you will pass data such as:

Expand Down Expand Up @@ -30,13 +38,13 @@ as well as a template such as:

<ul>
{% for user in users -%}
<li><a href="{{ user.url }}">{{ user.username }}
<li><a href="{{ user.url }}">{{ user.username }}
{{ user.username }} likes {% for color in user.fav_colors -%}{{ color }} {% endfor %}
</a></li>
{% endfor %}
</ul>

and a call such as `tera --template data/template.tmpl data/data.json` will produce:
and a call such as `tera --template template.tera data.json` will produce:

.result
<title> Demo </title>
Expand Down
22 changes: 15 additions & 7 deletions README_src.adoc
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
= Tera cli
= tera-cli
:toc: right
:proj: tera-cli
:cmd: cmd
:lib:
:lib: tera

https://github.com/Keats/tera[tera] is a template engine written in Rust and inspired by Jinja2. It allows merging some data called `context data` into a template and produces a new output.
== Intro
image::resources/logo/tera-cli-logo_256.png[width=256px, align=center]

This project is a command line for the https://github.com/Keats/tera[tera template engine]. This project is called `tera-cli` but the command installed on your system is simply `tera`.
https://github.com/Keats/tera[tera] is a template engine written in Rust and inspired by Jinja2. It allows merging some data called `context data` into a template and produces a new output. This project, `tera-cli`, is a command line for the https://github.com/Keats/tera[tera template engine].

This project is called `tera-cli` but the command installed on your system is simply `tera`.

`tera-ci` offers powerful features related to your environment variables, allowing you to control the output **both** from the context data you pass but also from the ENV variables set on your system.


== Example

Here is a basic example. For instance, you will pass data such as:

----
.data.json:
include::data/data.json[]
include::data/basic/basic.json[]
----

as well as a template such as:

----
.template.tmpl
include::data/template.tmpl[]
include::data/basic/basic.tera[]
----

and a call such as `tera --template data/template.tmpl data/data.json` will produce:
and a call such as `tera --template template.tera data.json` will produce:
----
.result
<title> Demo </title>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion data/template.tmpl → data/basic/basic.tera
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<ul>
{% for user in users -%}
<li><a href="{{ user.url }}">{{ user.username }}
<li><a href="{{ user.url }}">{{ user.username }}
{{ user.username }} likes {% for color in user.fav_colors -%}{{ color }} {% endfor %}
</a></li>
{% endfor %}
Expand Down
2 changes: 2 additions & 0 deletions data/data.toml → data/basic/basic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ title = "Demo"
[[users]]
username = "Alice"
url = "http://example.org/alice"
fav_colors = ["red", "green", "yellow"]

[[users]]
username = "Bob"
url = "http://example.org/bob"
fav_colors = ["orange"]
6 changes: 6 additions & 0 deletions data/data.yaml → data/basic/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ title: "Demo"
users:
- username: "Alice"
url: "http://example.org/alice"
fav_colors:
- red
- green
- yellow

- username: "Bob"
url: "http://example.org/bob"
fav_colors:
- orange
Loading

0 comments on commit e3b7185

Please sign in to comment.