Skip to content

Commit

Permalink
Example with guards and asynchronous code for Rust canisters (#877)
Browse files Browse the repository at this point in the history
* Infrastructure

* integration test

* examples with various futures

* add dfx support

* temp with made up future

* clean-up

* use same state field for single/multi items test

* clean-up

* doc

* added Github workflow file

* provision  pocket-ic server

* use same version as locally

* added guard against parallel processing

* upgrade PocketIc

* added test against parallel processing.

* simplify provisioning of PocketIC and added Linting

* fix

* fix order of CI steps

* ensure items are not in processing when reset

* add ownership
  • Loading branch information
gregorydemay authored Jun 4, 2024
1 parent 46704c2 commit 01b1e4d
Show file tree
Hide file tree
Showing 11 changed files with 2,524 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
/rust/dip721-nft-container/ @dfinity/sdk
/rust/encrypted-notes-dapp-vetkd/ @dfinity/dept-crypto-library
/rust/encrypted-notes-dapp/ @dfinity/div-Crypto
/rust/guards/ @dfinity/cross-chain-team
/rust/hello/ @dfinity/sdk
/rust/icp_transfer/ @dfinity/growth
/rust/image-classification/ @dfinity/runtime
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/provision-pocket-ic-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -ex

POCKET_IC_SERVER_VERSION=${POCKET_IC_SERVER_VERSION:=4.0.0}
POCKET_IC_SERVER_PATH=${POCKET_IC_SERVER_PATH:="${HOME}/bin/pocket-ic-server"}

if [[ $OSTYPE == "linux-gnu"* ]] || [[ $RUNNER_OS == "Linux" ]]
then
PLATFORM=linux
elif [[ $OSTYPE == "darwin"* ]] || [[ $RUNNER_OS == "macOS" ]]
then
PLATFORM=darwin
else
echo "OS not supported: ${OSTYPE:-$RUNNER_OS}"
exit 1
fi

if [ ! -f "$POCKET_IC_SERVER_PATH" ]; then
echo "Downloading PocketIC."
mkdir -p "$(dirname "${POCKET_IC_SERVER_PATH}")"
curl -sSL "https://github.com/dfinity/pocketic/releases/download/${POCKET_IC_SERVER_VERSION}/pocket-ic-x86_64-${PLATFORM}.gz" -o "${POCKET_IC_SERVER_PATH}".gz
gunzip "${POCKET_IC_SERVER_PATH}.gz"
chmod +x "${POCKET_IC_SERVER_PATH}"
else
echo "PocketIC server already exists, skipping download."
fi

# Set environment variables.
echo "POCKET_IC_BIN=${POCKET_IC_SERVER_PATH}" >> "$GITHUB_ENV"
63 changes: 63 additions & 0 deletions .github/workflows/rust-guards-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: rust-guards
on:
push:
branches:
- master
pull_request:
paths:
- rust/guards/**
- .github/workflows/provision-darwin.sh
- .github/workflows/provision-linux.sh
- .github/workflows/provision-pocket-ic-server.sh
- .github/workflows/rust-guards-example.yml
- .ic-commit
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
rust-guards-darwin:
runs-on: macos-12
steps:
- uses: actions/checkout@v1
- name: Provision Darwin
run: bash .github/workflows/provision-darwin.sh
- name: Provision PocketIC Darwin
run: bash .github/workflows/provision-pocket-ic-server.sh
- name: Build Guards Darwin
run: |
pushd rust/guards
cargo build --target wasm32-unknown-unknown --release
popd
- name: Lint Guards Darwin
run: |
pushd rust/guards
cargo fmt --all -- --check && cargo clippy --all-targets --all-features -- -D warnings
popd
- name: Test Guards Darwin
run: |
pushd rust/guards
cargo test
popd
rust-guards-linux:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Provision Linux
run: bash .github/workflows/provision-linux.sh
- name: Provision PocketIC Linux
run: bash .github/workflows/provision-pocket-ic-server.sh
- name: Build Guards Linux
run: |
pushd rust/guards
cargo build --target wasm32-unknown-unknown --release
popd
- name: Lint Guards Linux
run: |
pushd rust/guards
cargo fmt --all -- --check && cargo clippy --all-targets --all-features -- -D warnings
popd
- name: Test Guards Linux
run: |
pushd rust/guards
cargo test
popd
Loading

0 comments on commit 01b1e4d

Please sign in to comment.