Skip to content

Commit

Permalink
Add workspace-enabled example contracts (was PR:#44) (#52)
Browse files Browse the repository at this point in the history
* feature: check contracts in workspace

* fixes in CI

* fixes in CI

* fixes in CI: s/steps/step

* fixes in CI: enable examples step

* wip CI/CD: run contracts along regular ones, but with different step

* wip CI/CD: log changed files also use the right variable to check for them

* wip CI/CD: hopefuly preventing error on invalid character..

* wip CI/CD: changed approach to run both workspace contracts on same runner..

* wip CI/CD: whole workspace at once

* wip CI/CD: specify workspace cargo

* wip CI/CD: no test on workspace

* wip CI/CD: removed debug info/vars

* wip CI/CD: removed debug info/vars

* updated the CI/CD to be ready when using/having cargo-contract v 4.0.

* fix unnoticed error in contract

* Update ci.yml removed redundant configuration

Update ci.yml removed redundant configuration
  • Loading branch information
tenuki authored Nov 21, 2023
1 parent 254fa73 commit 33ecf5b
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 3 deletions.
47 changes: 44 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
**/*.md
multi-contract-caller/**
upgradeable-contracts/**
workspace-contracts/**
ui/**
**/frontend/**
json: true
Expand All @@ -71,15 +72,48 @@ jobs:
files_ignore: |
**/.gitignore
**/*.md
workspace-contracts/**
json: true

- name: Look for changes in workspace contracts
id: CHANGED_WORKSPACE_CONTRACTS
uses: tj-actions/changed-files@v39
with:
dir_names: "true"
dir_names_exclude_current_dir: "true"
dir_names_max_depth: 2
files: |
workspace-contracts/**
files_ignore: |
**/.gitignore
**/*.md
json: true


- name: List all changed files
run: |
echo " Changed workspace contracts "
for file in ${{ steps.CHANGED_WORKSPACE_CONTRACTS.outputs.all_changed_files }}; do
echo "$file was changed"
done
echo "no more files.."
- name: Build matrix
id: build_matrix
run: |
ALL_CHANGED_CONTRACTS=$(jq -s 'add' \
<(echo "${{ steps.CHANGED_CONTRACTS.outputs.all_changed_files }}") \
<(echo "${{ steps.CHANGED_MULTI_AND_UPGRADEABLE_CONTRACTS.outputs.all_changed_files }}"))
if [ ${{steps.CHANGED_WORKSPACE_CONTRACTS.outputs.all_changed_files }} = "[]" ]
then
echo "Nothing important changed. Workspace contracts job will be skipped."
else
ALL_CHANGED_CONTRACTS=$(jq -s 'add' \
<(echo "$ALL_CHANGED_CONTRACTS") \
<(echo "[\"workspace-contracts\"]"))
fi
if [ $ALL_CHANGED_CONTRACTS = "[]" ]
then
echo "Nothing important changed. Checks job will be skipped."
Expand Down Expand Up @@ -181,9 +215,16 @@ jobs:
cargo contract --version
- name: Build ${{ matrix.contract }} on ${{ matrix.platform }}-${{ matrix.toolchain }}
if: runner.os != 'Windows'
if: runner.os != 'Windows' && matrix.contract != 'workspace-contracts'
run: cargo contract build --verbose --manifest-path=${{ matrix.contract }}/Cargo.toml;

- name: Test ${{ matrix.contract }} on ${{ matrix.platform }}-${{ matrix.toolchain }}
if: runner.os != 'Windows'
run: cargo test --verbose --manifest-path=${{ matrix.contract }}/Cargo.toml;
if: runner.os != 'Windows' && matrix.contract != 'workspace-contracts'
run: cargo test --verbose --manifest-path=${{ matrix.contract }}/Cargo.toml;

- name: Build workspace ${{ matrix.contract }} on ${{ matrix.platform }}-${{ matrix.toolchain }}
if: runner.os != 'Windows' && matrix.contract == 'workspace-contracts'
run: |
echo FOLLOWING SEEMS TO WORK WITH CARGO-CONTRACT 4.0
cargo contract build --verbose --manifest-path=workspace-contracts/flipper/Cargo.toml
cargo contract build --verbose --manifest-path=workspace-contracts/incrementer/Cargo.toml
9 changes: 9 additions & 0 deletions workspace-contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore build artifacts from the local tests sub-crate.
/target/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk

# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
10 changes: 10 additions & 0 deletions workspace-contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[workspace]
members = ["*"]
exclude = [".cargo", "target"]
resolver = "2"

[workspace.dependencies]
ink = { version = "4.3.0", default-features = false }
ink_e2e = "4.3.0"
scale = { package = "parity-scale-codec", version = "=3.6.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"] }
28 changes: 28 additions & 0 deletions workspace-contracts/flipper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "flipper"
version = "4.3.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
ink = { workspace = true }

scale = { workspace = true, package = "parity-scale-codec" }
scale-info = { workspace = true, optional = true }

[dev-dependencies]
ink_e2e = { workspace = true }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
]
ink-as-dependency = []
e2e-tests = []
35 changes: 35 additions & 0 deletions workspace-contracts/flipper/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

#[ink::contract]
pub mod flipper {
#[ink(storage)]
pub struct Flipper {
value: bool,
}

impl Flipper {
/// Creates a new flipper smart contract initialized with the given value.
#[ink(constructor)]
pub fn new(init_value: bool) -> Self {
Self { value: init_value }
}

/// Creates a new flipper smart contract initialized to `false`.
#[ink(constructor)]
pub fn new_default() -> Self {
Self::new(Default::default())
}

/// Flips the current value of the Flipper's boolean.
#[ink(message)]
pub fn flip(&mut self) {
self.value = !self.value;
}

/// Returns the current value of the Flipper's boolean.
#[ink(message)]
pub fn get(&self) -> bool {
self.value
}
}
}
24 changes: 24 additions & 0 deletions workspace-contracts/incrementer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "incrementer"
version = "4.3.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
publish = false

[dependencies]
ink = { workspace = true }

scale = { workspace = true, package = "parity-scale-codec" }
scale-info = { workspace = true, optional = true }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
]
ink-as-dependency = []
31 changes: 31 additions & 0 deletions workspace-contracts/incrementer/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

#[ink::contract]
mod incrementer {
#[ink(storage)]
pub struct Incrementer {
value: i32,
}

impl Incrementer {
#[ink(constructor)]
pub fn new(init_value: i32) -> Self {
Self { value: init_value }
}

#[ink(constructor)]
pub fn new_default() -> Self {
Self::new(Default::default())
}

#[ink(message)]
pub fn inc(&mut self, by: i32) {
self.value = self.value.saturating_add(by);
}

#[ink(message)]
pub fn get(&self) -> i32 {
self.value
}
}
}

0 comments on commit 33ecf5b

Please sign in to comment.