-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,992 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: "Build" | ||
on: | ||
push: {} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: Set-up OCaml 4.14.0 | ||
uses: ocaml/setup-ocaml@v2 | ||
with: | ||
ocaml-compiler: 4.14.0 | ||
- run: opam install . --deps-only --with-test | ||
- run: make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*~ | ||
_build | ||
.merlin | ||
*.install | ||
_opam | ||
.ligo | ||
report.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version=0.25.1 | ||
profile=janestreet | ||
let-binding-spacing=sparse | ||
margin=90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Frontend to dune. | ||
|
||
.PHONY: default build install uninstall test clean fmt | ||
.IGNORE: fmt | ||
|
||
default: build | ||
|
||
init: | ||
opam switch list | grep ocaml-base-compiler.4.14.0 || opam switch create . ocaml-base-compiler.4.14.0 -y | ||
eval $(opam env) | ||
|
||
build: | ||
opam exec -- dune build | ||
|
||
test: | ||
opam exec -- dune runtest -f | ||
|
||
install: | ||
opam exec -- dune install | ||
|
||
uninstall: | ||
opam exec -- dune uninstall | ||
|
||
clean: | ||
opam exec -- dune clean | ||
# Optionally, remove all files/folders ignored by git as defined | ||
# in .gitignore (-X). | ||
git clean -dfXq | ||
|
||
fmt: | ||
opam exec -- dune build @fmt | ||
opam exec -- dune promote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# ligo-mdx | ||
|
||
## Goal | ||
The project goal is to test ligo code contained in markdown file. For example it'll help to test your documentation or training through a CICD. | ||
|
||
It'll generate a report file named report.html | ||
|
||
## Try it | ||
|
||
You can try now it by running : | ||
|
||
```zsh | ||
make && ./ligo-mdx/_build/default/src/bin/main.exe run ./examples/docs/tutorials/taco-shop/tezos-taco-shop-smart-contract.md ligo | ||
``` | ||
|
||
It'll generate a report.html file. | ||
## How to use | ||
|
||
The script is able to read 3 keywords in header and the declared language. | ||
|
||
Language can be jsligo, cameligo or zsh (in case of shell script) | ||
|
||
- group : used to regroup multiple snippets, it'll also be used as a nameFile | ||
- compilation : The way to test your code | ||
- Interpret : Use `ligo interpret` to test your code | ||
- Contract : Use `ligo compile contract` to test your code | ||
- Test : Use `ligo run test` to test your code | ||
- Command : Use directly command inside snippet | ||
- None : Skip this snippet | ||
- syntax: If the language does not match with the syntax, you can override the syntax with syntax attribute | ||
- cameligo | ||
- jsligo | ||
- interpretation-type : interpretation-type=declaration | ||
- Expression : Default value, nothing happen | ||
- Declaration : When the snippet is interpreted, it'll be transformed to an expression, surrounding the code with `module ASFJNISFX = struct` and `end in ()` | ||
|
||
## Examples | ||
|
||
### Group snippets | ||
|
||
(ommit \ which has been introduced to be able to insert markdown code) | ||
```markdown | ||
|
||
```jsligo group=taco-shop | ||
type taco_supply is record [current_stock : nat; max_price : tez] | ||
|
||
type taco_shop_storage is map (nat, taco_supply) | ||
|
||
type return_ = [list <operation>, taco_shop_storage]; | ||
|
||
\``` | ||
|
||
blabla | ||
|
||
```jsligo group=taco-shop compilation=contract | ||
@entry | ||
let buy_taco = (taco_kind_index: nat, taco_shop_storage: taco_shop_storage): return_ => { | ||
/* Retrieve the taco_kind from the contracts storage or fail */ | ||
let taco_kind = | ||
match (Map.find_opt (taco_kind_index, taco_shop_storage), { | ||
Some: (k:taco_supply) => k, | ||
None: (_:unit) => (failwith ("Unknown kind of taco") as taco_supply) | ||
}) ; | ||
} | ||
\``` | ||
``` | ||
|
||
Will regroup and test snippets by running `ligo compile contract tmp/taco-shop.jsligo` on a temp file which is defined by | ||
```jsligo | ||
type taco_supply is record [current_stock : nat; max_price : tez] | ||
type taco_shop_storage is map (nat, taco_supply) | ||
type return_ = [list <operation>, taco_shop_storage]; | ||
@entry | ||
let buy_taco = (taco_kind_index: nat, taco_shop_storage: taco_shop_storage): return_ => { | ||
/* Retrieve the taco_kind from the contracts storage or fail */ | ||
let taco_kind = | ||
match (Map.find_opt (taco_kind_index, taco_shop_storage), { | ||
Some: (k:taco_supply) => k, | ||
None: (_:unit) => (failwith ("Unknown kind of taco") as taco_supply) | ||
}) ; | ||
} | ||
``` | ||
|
||
:warning: This is file scopped, groups cannot be shared between files | ||
|
||
### Branch onto group | ||
|
||
It's possible to branch on snippet, for example if you want to define step by step a function : | ||
|
||
```markdown | ||
|
||
```jsligo group=taco-shop;taco-shop2 | ||
type taco_supply is record [current_stock : nat; max_price : tez] | ||
|
||
type taco_shop_storage is map (nat, taco_supply) | ||
|
||
type return_ = [list <operation>, taco_shop_storage]; | ||
|
||
\``` | ||
|
||
blabla | ||
|
||
|
||
```jsligo group=taco-shop compilation=contract | ||
@entry | ||
let buy_taco = (taco_kind_index: nat, taco_shop_storage: taco_shop_storage): return_ => { | ||
[], taco_shop_storage | ||
} | ||
\``` | ||
|
||
blablablabla | ||
|
||
```jsligo group=taco-shop2 compilation=contract | ||
@entry | ||
let buy_taco = (taco_kind_index: nat, taco_shop_storage: taco_shop_storage): return_ => { | ||
/* Retrieve the taco_kind from the contracts storage or fail */ | ||
let taco_kind = | ||
match (Map.find_opt (taco_kind_index, taco_shop_storage), { | ||
Some: (k:taco_supply) => k, | ||
None: (_:unit) => (failwith ("Unknown kind of taco") as taco_supply) | ||
}) ; | ||
} | ||
\``` | ||
``` | ||
|
||
Will create two snippets named `taco-shop` and `taco-shop2` and test them using `ligo compile contract` | ||
|
||
### Use shell command onto a snippet | ||
Some time your documentation contains a bash command and you want to test it too, it's possible : | ||
|
||
``` | ||
```jsligo group=contract/taco-shop | ||
<your contract code here> | ||
\``` | ||
|
||
blabla | ||
|
||
```zsh group=contract/taco-shop compilation=command | ||
ligo run dry-run contract/taco-shop.jsligo 4 3 --entry-point main | ||
\``` | ||
``` | ||
|
||
### Build snippet with invisible code | ||
|
||
Some time, your code is not compilable itself. You can add some code between `<!-- -->` and tag it with the correct group. For example : | ||
``` | ||
<!-- | ||
```cameligo group=invisible-snippet | ||
type taco_supply = { current_stock : nat ; max_price : tez } | ||
type taco_shop_storage = (nat, taco_supply) map | ||
\``` | ||
--> | ||
|
||
```cameligo group=invisible-snippet compilation=interpret interpretation-type=declaration | ||
type return = operation list * taco_shop_storage | ||
\``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(lang dune 3.0) | ||
(name ligo-mdx) ; optional | ||
(version 0.1.0) ; optional |
Oops, something went wrong.