Skip to content

Commit

Permalink
Merge #2849
Browse files Browse the repository at this point in the history
2849: Update plutus-example dependencies r=newhoggy a=newhoggy

Also add `plutus-example` to Github Actions.

Co-authored-by: John Ky <john.ky@iohk.io>
  • Loading branch information
iohk-bors[bot] and newhoggy committed Jun 23, 2021
2 parents 13d71da + ffbaf10 commit b76de42
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 22 deletions.
117 changes: 117 additions & 0 deletions .github/workflows/build-plutus-examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Plutus Examples

on: [push]

jobs:
build:
runs-on: ${{ matrix.os }}

defaults:
run:
shell: bash

strategy:
fail-fast: false
matrix:
ghc: ["8.10.4"]
os: [ubuntu-latest, macos-latest]

steps:

- uses: haskell/actions/setup@v1
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: 3.4.0.0

- name: Set cache version
run: echo "CACHE_VERSION=grFfw8r" >> $GITHUB_ENV

- uses: actions/checkout@v2

- name: Add build script path
run: echo "$(pwd)/.github/bin" >> $GITHUB_PATH

- name: Install pkgconfiglite
if: matrix.os == 'windows-latest'
run: retry 2 choco install -y pkgconfiglite

- name: Install libsodium (Windows)
if: matrix.os == 'windows-latest'
run: |
curl -Ls \
--connect-timeout 5 \
--max-time 10 \
--retry 5 \
--retry-delay 0 \
--retry-max-time 40 \
https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-mingw.tar.gz -o libsodium-1.0.18-mingw.tar.gz
tar zxvf libsodium-1.0.18-mingw.tar.gz
sed -i "s|/d/a/1/s/|D:/a/cardano-node/cardano-node/|g" libsodium-win64/lib/pkgconfig/libsodium.pc
export PKG_CONFIG_PATH="$(readlink -f libsodium-win64/lib/pkgconfig)"
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV
export LIBSODIUM_PATH="$(readlink -f libsodium-win64/bin | sed 's|^/d|D:|g' | tr / '\\')"
echo "LIBSODIUM_PATH=$LIBSODIUM_PATH"
echo "$LIBSODIUM_PATH" >> $GITHUB_PATH
- name: Install libsodium (MacOS)
if: matrix.os == 'macos-latest'
run: brew install libsodium

- name: Setup Github Scripts
run: echo "$(pwd)/.github/bin" >> $GITHUB_PATH

- name: Configure to use libsodium
run: |
cd plutus-example
cat >> cabal.project <<EOF
package cardano-crypto-praos
flags: -external-libsodium-vrf
EOF
- name: Haskell versions
run: |
ghc --version
cabal --version
- name: Install build environment
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get -y install libsodium23 libsodium-dev
sudo apt-get -y install libsystemd0 libsystemd-dev
sudo apt-get -y remove --purge software-properties-common
sudo apt-get -y autoremove
- name: Cabal update
run: retry 2 cabal update

- name: Record dependencies
run: |
cd plutus-example
cabal build plutus-example --only-dependencies --dry-run
cat ${{ env.PLAN_JSON }} | jq -r '."install-plan"[].id' | sort | uniq > dependencies.txt
date > date.txt
- uses: actions/cache@v2
name: Cache cabal store
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('plutus-example/dependencies.txt') }}-${{ hashFiles('date.txt') }}
restore-keys: |
cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('plutus-example/dependencies.txt') }}-${{ hashFiles('date.txt') }}
cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('plutus-example/dependencies.txt') }}
cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}
- name: Build
run: |
cd plutus-example
retry 2 cabal build plutus-example
- name: Run tests
run: |
cd plutus-example
retry 2 cabal test plutus-example
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/cabal.project.old
configuration/defaults/simpleview/genesis/
configuration/defaults/liveview/genesis/
/dist-newstyle/
dist-newstyle
dist/
*~
\#*
Expand Down
22 changes: 11 additions & 11 deletions plutus-example/cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ test-show-details: direct
source-repository-package
type: git
location: https://github.com/input-output-hk/hedgehog-extras
tag: 8bcd3c9dc22cc44f9fcfe161f4638a384fc7a187
--sha256: 12viwpahjdfvlqpnzdgjp40nw31rvyznnab1hml9afpaxd6ixh70
tag: ccb5648ad3c93744f67e244706a7a3e36dcfbab0
--sha256: 0p9jgpj9cjkg184y1rswz90sw0nq13rld80fa5s59xcyvsa31p7y

source-repository-package
type: git
Expand All @@ -35,7 +35,6 @@ source-repository-package
cardano-crypto-tests
slotting
strict-containers

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-crypto
Expand All @@ -45,8 +44,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: d6b3d6b8ed16b2c69684fa44218f4e7060f166d3
--sha256: 1afsvxv8a24rpd3inr4m323l1dx5xg6kmfnjkzb6jw72ykcgpsyz
tag: 0fa5a737aa5bed6f835402526f0b2d541ed83dab
--sha256: 0dd75944f1ww0bnr1l02igwkiwbwkvrlv6yldlgakdpqyfn1np9d
subdir:
alonzo/impl
byron/chain/executable-spec
Expand Down Expand Up @@ -97,17 +96,18 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/Win32-network
tag: 82f4afb8c240b8446a1db6c6b50901a42028ce0f
--sha256: 0ljxjzywk6xh9n4mfg21am65z65anlrq47z6zyzcav3h6iasvfq2
tag: 5b3d08c454f425da5cf045fe7865950d7c806691
--sha256: 0npyihbaqlih9abdbaj451lm1h0kl5braczy8vn41s3ivbbnvpcw

source-repository-package
type: git
location: https://github.com/input-output-hk/ouroboros-network
tag: 47b94669555fb3e4f5f3b985f5d804090cfb60c4
--sha256: 1y20brl7scppf55037bq5rnq6vdab2f6x56nqsg8grj2gipihkdp
tag: b749bc878bb05478f924d6e2d4970d1bdaef94ef
--sha256: 1k1cc5sqq9h6jrr5psi4vzs1ay3wafj42gpfv8b67cpnxfivj4m6
subdir:
io-sim
io-sim-classes
monoidal-synchronisation
network-mux
ouroboros-consensus
ouroboros-consensus-byron
Expand All @@ -122,8 +122,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/plutus
tag: bd0dec6dbbf87a14b54384cc083be2bfaf8d5ca6
--sha256: 09qhhiks1qj3x0h3vhr3j7p8kfnbrp2sqi2gc6d16s5zy2pyjbqh
tag: e11d59a181f558fb5d2e5b0a2a32afd496660bc1
--sha256: 0hdck39i4yv656phxjy5ppqgzrq7x3q4b5rf8vj7hrzcs0aggl8r
subdir:
plutus-core
plutus-ledger
Expand Down
2 changes: 0 additions & 2 deletions plutus-example/plutus-example/app/plutus-example.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import Cardano.Api
import Cardano.Api.Shelley

import qualified Cardano.Ledger.Alonzo.Data as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.Coin as Shelley
import Data.Aeson (encode)
import qualified Data.ByteString.Lazy as LBS
import qualified Plutus.V1.Ledger.Api as Plutus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import PlutusTx.Prelude hiding (Semigroup (..), unless)
{- HLINT ignore "Avoid lambda" -}

{-# INLINABLE mkPolicy #-}
mkPolicy :: PubKeyHash -> ScriptContext -> Bool
mkPolicy ownerPkh ctx =
mkPolicy :: PubKeyHash -> () -> ScriptContext -> Bool
mkPolicy ownerPkh () ctx =
traceIfFalse "Only owner can mint" mustBeSignedBy'
where
info :: TxInfo
Expand All @@ -47,20 +47,20 @@ mkPolicy ownerPkh ctx =
mustBeSignedBy' :: Bool
mustBeSignedBy' = txSignedBy info ownerPkh

policy :: PubKeyHash -> Scripts.MonetaryPolicy
policy ownerPkh = mkMonetaryPolicyScript $
$$(PlutusTx.compile [|| \ownerPkh' -> Scripts.wrapMonetaryPolicy $ mkPolicy ownerPkh' ||])
policy :: PubKeyHash -> Scripts.MintingPolicy
policy ownerPkh = mkMintingPolicyScript $
$$(PlutusTx.compile [|| \ownerPkh' -> Scripts.wrapMintingPolicy (mkPolicy ownerPkh') ||])
`PlutusTx.applyCode`
PlutusTx.liftCode ownerPkh

plutusScript :: Script
plutusScript =
unMonetaryPolicyScript
unMintingPolicyScript
$ policy "e7dc13db93c1f56b3fd51752c14d5fdd20157334b9f0a0186d8dbd39"

validator :: Validator
validator =
Validator . unMonetaryPolicyScript
Validator . unMintingPolicyScript
$ policy "e7dc13db93c1f56b3fd51752c14d5fdd20157334b9f0a0186d8dbd39"

scriptAsCbor :: LB.ByteString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import qualified Data.ByteString.Short as SBS
import Ledger.Contexts (ScriptContext (..))
import qualified Ledger.Typed.Scripts as Scripts
import qualified Plutus.V1.Ledger.Scripts as Plutus
import PlutusTx (Data (..))
import qualified PlutusTx
import PlutusTx.Prelude hiding (Semigroup (..), unless)

Expand Down
27 changes: 27 additions & 0 deletions scripts/project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

CYAN='\033[0;36m'
NC='\033[0m' # No Color

build() {
echo -e "${CYAN}[ Building project ]${NC}"
cabal build all --write-ghc-environment-files=ghc8.4.4+ --enable-tests

echo -e "${CYAN}[ Building plutus-example] ${NC}"
cd plutus-example
cabal build all --write-ghc-environment-files=ghc8.4.4+ --enable-tests
}

test() {
echo -e "${CYAN}[ Testing project ]${NC}"
cabal test all --write-ghc-environment-files=ghc8.4.4+ --enable-tests --test-show-details=direct

echo -e "${CYAN}[ Testing plutus-example ]${NC}"
cd plutus-example
cabal test all --write-ghc-environment-files=ghc8.4.4+ --enable-tests --test-show-details=direct
}

case "$1" in
build ) build ;;
test ) test ;;
esac

0 comments on commit b76de42

Please sign in to comment.