Skip to content

Commit 0dac888

Browse files
VictorCMiraldogithub-actions0xd34df00d
authored
Preparing the repo for open-sourcing (#58)
* Added license * Revamp the main README * Attempt to automatically push generated cabal files on a PR * Adding the cabal files into the repo with an automatic update from CI; I can't find another solution to let people reference our code in a cabal.project without keeping the cabal files in * Generated cabal files * Fix bug in script * Will I see a cabal update? * Tell the checkout action to checkout the current branch, otherwise it stays in a detached HEAD state and we can't push * syntax error on workflow file * Is itworking now? * Try again * Try again * again * again * Forgot to change our script to just push * Generated cabal files * Seems like its working * Removd superfluous file. I'm expecting a commit from GH actions * Scipt didn't run * There we go again * Generated cabal files * Update README.md Co-authored-by: 0xd34df00d <[email protected]> * Update README.md Co-authored-by: 0xd34df00d <[email protected]> * More info on README * typo and ToC addition Co-authored-by: github-actions <[email protected]> Co-authored-by: 0xd34df00d <[email protected]>
1 parent 0a897fc commit 0dac888

File tree

11 files changed

+577
-49
lines changed

11 files changed

+577
-49
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@ jobs:
99
name: Build and test
1010
runs-on: ubuntu-latest
1111
steps:
12-
- name: Check out repository code.
12+
# There's two different checkout steps; one runs from main, the other runs
13+
# from a pull_request. The difference is that when running from a PR, we might
14+
# want to push changes to cabal files, hence we need to set up the ref.
15+
- name: Check out repository code (from PR).
16+
if: github.ref != 'refs/heads/main'
1317
uses: actions/checkout@v2
18+
with:
19+
ref: ${{ github.head_ref }}
20+
- name: Check out repository code (from main).
21+
if: github.ref == 'refs/heads/main'
22+
uses: actions/checkout@v2
23+
########
24+
########
1425
- name: Install nix.
1526
uses: cachix/install-nix-action@v13
1627
with:
@@ -32,7 +43,11 @@ jobs:
3243
cabal-cache
3344
- name: Chmod test script.
3445
run: |
35-
chmod u+x tests/run-tests.sh
46+
chmod u+x ci/run-tests.sh
47+
chmod u+x ci/commit-and-push-cabal-changes.sh
3648
- name: Build and test.
3749
run: |
38-
nix-shell --run "./tests/run-tests.sh --ci" --allowed-uris 'https://github.com/NixOS/nixpkgs https://github.com/input-output-hk https://github.com/NixOS/nixpkgs-channels' --option trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" --option substituters "https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/" nix/ci.nix
50+
nix-shell --run "./ci/run-tests.sh --ci" --allowed-uris 'https://github.com/NixOS/nixpkgs https://github.com/input-output-hk https://github.com/NixOS/nixpkgs-channels' --option trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" --option substituters "https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/" nix/ci.nix
51+
- name: Commit and push cabal files if necessary
52+
if: success() && github.ref != 'refs/heads/main'
53+
run: ci/commit-and-push-cabal-changes.sh

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Tweag I/O Limited.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,73 @@
1+
# Tweag Plutus Libraries
2+
3+
_These libraries are a research prototype under active development_
4+
5+
* [Projects](#projects)
6+
* [Developer Tools and Env](#developer-tools-and-environment)
7+
- [IMPORTANT: Nix Cache](#nix)
8+
- [Updating Plutus](#updating-plutus)
9+
10+
This repository contains a collection of the libraries we use for developing and auditing [Plutus](https://github.com/input-output-hk/plutus) contracts.
11+
112
## Projects
213

3-
- [cooked-validators](cooked-validators) is a library for exercising validator scripts without
4-
having to rely on Plutus' `EmulatorTrace`
5-
- [tasty-twaudit-metadata](tasty-twaudit-metadata) is a library for generating our LaTeX reports
6-
out of an annotated tasty test-suite.
14+
This repository hosts many projects. You are likely only interested in [cooked-validators](cooked-validators) and the [examples](examples) provided therein.
15+
16+
### [cooked-validators](cooked-validators)
17+
18+
- Property-based testing of Plutus contracts with no code duplication.
19+
- Interacts seamlessly with Plutus `Contract` monad.
20+
- Supports loading UPLC contracts from bytestrings for testing.
21+
22+
### [examples](examples)
23+
24+
- Example contracts and their test suites written using `cooked-validators`
25+
26+
### [tasty-twaudit-metadata](tasty-twaudit-metadata)
27+
28+
- Work-in-progress of internal library that we use to generate LaTeX reports.
29+
30+
## Developer Tools and Environment
31+
32+
All of the project dependencies, except for Plutus, are handled by nix. Plutus is handled by cabal.
33+
34+
### Nix
35+
36+
A Nix shell development environment is provided.
37+
See [`nix-shell` docs](https://nixos.org/manual/nix/unstable/command-ref/nix-shell.html).
38+
39+
#### _IMPORTANT:_ Configure your nix cache!
40+
41+
Plutus uses a custom GHC version. To avoid building GHC, make sure you set up the IOHK binary nix cache
42+
as instructed [here](https://github.com/input-output-hk/plutus#iohk-binary-cache).
43+
44+
#### Seamless Integration with `direnv`
45+
46+
Install `direnv` and run `direnv allow` at the root of the repo.
47+
To cache the nix environment and make direnv load faster you can configure
48+
and use [nix-direnv](https://github.com/nix-community/nix-direnv#with-nix-env).
49+
Several editors have support for `direnv`. If you use emacs, we recomend using [`envrc-mode`](https://github.com/purcell/envrc).
50+
51+
#### Nixpkgs and HaskellNix pin
52+
53+
In order to improve reproducibility, nixpkgs and [`haskell.nix`](https://input-output-hk.github.io/haskell.nix/) are pinned.
54+
See ["FAQ/Pinning Nixpkgs" wiki](https://nixos.wiki/wiki/FAQ/Pinning_Nixpkgs)
55+
56+
Pinning is done using [`niv`](https://github.com/nmattia/niv). Updating them is simple:
757

8-
## Dependencies
958

10-
All of the project dependencies, except for Plutus, is handled by nix.
11-
Plutus is handled by cabal.
59+
```
60+
nix-shell -p niv --run "niv update nixpkgs"
61+
nix-shell -p niv --run "niv update haskellNix"
62+
```
63+
64+
Check out the `nix/sources.json` file, you might need to switch the branch.
65+
1266

1367
### Updating Plutus
1468

1569
We are _not_ pinning plutus with nix in favor of a simpler nix setup and
16-
to be able to cache CI builds more easily. This does make the update process
70+
to be able to cache CI builds easily. This does make the update process
1771
more manual but its also pretty straightforward.
1872

1973
Our `cabal.project` file is a copy of the homonym file from
@@ -23,7 +77,7 @@ of packages to build.
2377

2478
In order to bump plutus, all one has to do is:
2579

26-
1. Select the tag you want to updat to from `plutus-apps`.
80+
1. Select the tag you want to update _to_ from `plutus-apps`.
2781
2. Copy the `cabal.project` from there
2882
3. Modify the `packages:` section to build our packages
2983
4. Add the relevant setting for linking with libsodium:
@@ -49,39 +103,11 @@ In order to bump plutus, all one has to do is:
49103
quickcheck-dynamic
50104
```
51105
In this case, we're running with `plutus-apps` at tag `v2021-11-05`.
52-
6. Run `cabal build all` and grab a coffee.
53-
54-
## Developer Tools and Environment
106+
6. Run `cabal build all` and grab a coffee, this will take a while.
55107
56108
### Pre-commit Hooks and CI
57109
58110
Our ci runs `ormolu`, `hlint` and `cabal test` for each of our subprojects.
59111
In order to help avoid CI failures due to formatting problems, we recommend
60112
that you install the [pre-commit hook for running ormolu](tests/ormolu-pre-commit-hook.sh).
61113
To do so, simply copy (or link) the script into `.git/hooks/pre-commit`.
62-
63-
### Nix
64-
65-
A Nix shell development environment is provided.
66-
See [`nix-shell` docs](https://nixos.org/manual/nix/unstable/command-ref/nix-shell.html).
67-
68-
#### Seamless Integration with `direnv`
69-
70-
Install `direnv` and run `direnv allow` at the root of the repo.
71-
To cache the nix environment and make direnv load faster you can configure
72-
and use [nix-direnv](https://github.com/nix-community/nix-direnv#with-nix-env).
73-
74-
#### Nixpkgs pin
75-
76-
In order to improve reproducibility, nixpkgs is pinned.
77-
See ["FAQ/Pinning Nixpkgs" wiki](https://nixos.wiki/wiki/FAQ/Pinning_Nixpkgs)
78-
79-
Pinning is done using [`niv`](https://github.com/nmattia/niv).
80-
81-
##### Update
82-
83-
```
84-
nix-shell -p niv --run "niv update nixpkgs"
85-
```
86-
87-
Check out the `nix/sources.json` file, you might need to switch the branch.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#! /bin/bash
2+
3+
if ! $CI; then
4+
echo "This script is meant to be ran in CI; it will mess up your local git config otherwise"
5+
exit 0
6+
fi
7+
8+
changes=$(git status --porcelain | grep "^ M" | grep "\.cabal$" | sed 's/ M //')
9+
if [[ ! -z "$changes" ]]; then
10+
git config user.name github-actions
11+
git config user.email [email protected]
12+
git add $changes
13+
git commit -m "Generated cabal files"
14+
git push
15+
fi
File renamed without changes.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -uo pipefail
33

44
show_help() {
55
cat <<EOF
6-
usage: ./tests/run-tests.sh [--ci]
6+
usage: ./ci/run-tests.sh [--ci]
77
88
Note the script is ran from the repo root; Running without --ci
99
will run "ormolu --mode inplace" and fix offending files.
@@ -36,15 +36,15 @@ run_ormolu() {
3636
echo "Running ormolu on $proj"
3737
local ormolu_res=0
3838
if $ci; then
39-
ormolu --mode check $(find ./$proj -name '*.hs') 2> >(tee "tests/${proj}-ormolu.artifact")
39+
ormolu --mode check $(find ./$proj -name '*.hs') 2> >(tee "ci/${proj}-ormolu.artifact")
4040
ormolu_res=$?
4141
else
4242
ormolu --mode inplace $(find ./$proj -name '*.hs')
4343
ormolu_res=$?
4444
fi
4545

4646
if $ci && [[ "$ormolu_res" -eq "0" ]]; then
47-
rm "tests/${proj}-ormolu.artifact"
47+
rm "ci/${proj}-ormolu.artifact"
4848
fi
4949

5050
return $ormolu_res
@@ -60,7 +60,7 @@ run_cabal_test() {
6060

6161
local cabal_res=0
6262
if $ci; then
63-
cabal run tests | tee "../tests/${proj}-cabal-test.artifact"
63+
cabal run tests | tee "../ci/${proj}-cabal-test.artifact"
6464
cabal_res=$?
6565
else
6666
cabal run tests
@@ -70,7 +70,7 @@ run_cabal_test() {
7070
popd
7171

7272
if $ci && [[ "$cabal_res" -eq "0" ]]; then
73-
rm "tests/$proj-cabal-test.artifact"
73+
rm "ci/$proj-cabal-test.artifact"
7474
fi
7575

7676
return $cabal_res
@@ -83,15 +83,15 @@ run_hlint() {
8383

8484
local hlint_res=0
8585
if $ci; then
86-
hlint --hint="tests/hlint.yaml" ${proj} | tee "tests/${proj}-hlint.artifact"
86+
hlint --hint="ci/hlint.yaml" ${proj} | tee "ci/${proj}-hlint.artifact"
8787
hlint_res=$?
8888
else
89-
hlint --hint="tests/hlint.yaml" ${proj}
89+
hlint --hint="ci/hlint.yaml" ${proj}
9090
hlint_res=$?
9191
fi
9292

9393
if $ci && [[ "$hlint_res" -eq "0" ]]; then
94-
rm "tests/$proj-hlint.artifact"
94+
rm "ci/$proj-hlint.artifact"
9595
fi
9696

9797
return $hlint_res

0 commit comments

Comments
 (0)