Skip to content

Commit 33ecf5b

Browse files
authored
Add workspace-enabled example contracts (was PR:#44) (#52)
* 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
1 parent 254fa73 commit 33ecf5b

File tree

7 files changed

+181
-3
lines changed

7 files changed

+181
-3
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
**/*.md
5555
multi-contract-caller/**
5656
upgradeable-contracts/**
57+
workspace-contracts/**
5758
ui/**
5859
**/frontend/**
5960
json: true
@@ -71,15 +72,48 @@ jobs:
7172
files_ignore: |
7273
**/.gitignore
7374
**/*.md
75+
workspace-contracts/**
7476
json: true
7577

78+
- name: Look for changes in workspace contracts
79+
id: CHANGED_WORKSPACE_CONTRACTS
80+
uses: tj-actions/changed-files@v39
81+
with:
82+
dir_names: "true"
83+
dir_names_exclude_current_dir: "true"
84+
dir_names_max_depth: 2
85+
files: |
86+
workspace-contracts/**
87+
files_ignore: |
88+
**/.gitignore
89+
**/*.md
90+
json: true
91+
92+
93+
- name: List all changed files
94+
run: |
95+
echo " Changed workspace contracts "
96+
for file in ${{ steps.CHANGED_WORKSPACE_CONTRACTS.outputs.all_changed_files }}; do
97+
echo "$file was changed"
98+
done
99+
echo "no more files.."
100+
76101
- name: Build matrix
77102
id: build_matrix
78103
run: |
79104
ALL_CHANGED_CONTRACTS=$(jq -s 'add' \
80105
<(echo "${{ steps.CHANGED_CONTRACTS.outputs.all_changed_files }}") \
81106
<(echo "${{ steps.CHANGED_MULTI_AND_UPGRADEABLE_CONTRACTS.outputs.all_changed_files }}"))
82107
108+
if [ ${{steps.CHANGED_WORKSPACE_CONTRACTS.outputs.all_changed_files }} = "[]" ]
109+
then
110+
echo "Nothing important changed. Workspace contracts job will be skipped."
111+
else
112+
ALL_CHANGED_CONTRACTS=$(jq -s 'add' \
113+
<(echo "$ALL_CHANGED_CONTRACTS") \
114+
<(echo "[\"workspace-contracts\"]"))
115+
fi
116+
83117
if [ $ALL_CHANGED_CONTRACTS = "[]" ]
84118
then
85119
echo "Nothing important changed. Checks job will be skipped."
@@ -181,9 +215,16 @@ jobs:
181215
cargo contract --version
182216
183217
- name: Build ${{ matrix.contract }} on ${{ matrix.platform }}-${{ matrix.toolchain }}
184-
if: runner.os != 'Windows'
218+
if: runner.os != 'Windows' && matrix.contract != 'workspace-contracts'
185219
run: cargo contract build --verbose --manifest-path=${{ matrix.contract }}/Cargo.toml;
186220

187221
- name: Test ${{ matrix.contract }} on ${{ matrix.platform }}-${{ matrix.toolchain }}
188-
if: runner.os != 'Windows'
189-
run: cargo test --verbose --manifest-path=${{ matrix.contract }}/Cargo.toml;
222+
if: runner.os != 'Windows' && matrix.contract != 'workspace-contracts'
223+
run: cargo test --verbose --manifest-path=${{ matrix.contract }}/Cargo.toml;
224+
225+
- name: Build workspace ${{ matrix.contract }} on ${{ matrix.platform }}-${{ matrix.toolchain }}
226+
if: runner.os != 'Windows' && matrix.contract == 'workspace-contracts'
227+
run: |
228+
echo FOLLOWING SEEMS TO WORK WITH CARGO-CONTRACT 4.0
229+
cargo contract build --verbose --manifest-path=workspace-contracts/flipper/Cargo.toml
230+
cargo contract build --verbose --manifest-path=workspace-contracts/incrementer/Cargo.toml

workspace-contracts/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ignore build artifacts from the local tests sub-crate.
2+
/target/
3+
4+
# Ignore backup files creates by cargo fmt.
5+
**/*.rs.bk
6+
7+
# Remove Cargo.lock when creating an executable, leave it for libraries
8+
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
9+
Cargo.lock

workspace-contracts/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[workspace]
2+
members = ["*"]
3+
exclude = [".cargo", "target"]
4+
resolver = "2"
5+
6+
[workspace.dependencies]
7+
ink = { version = "4.3.0", default-features = false }
8+
ink_e2e = "4.3.0"
9+
scale = { package = "parity-scale-codec", version = "=3.6.5", default-features = false, features = ["derive"] }
10+
scale-info = { version = "2.6", default-features = false, features = ["derive"] }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "flipper"
3+
version = "4.3.0"
4+
authors = ["Parity Technologies <admin@parity.io>"]
5+
edition = "2021"
6+
publish = false
7+
8+
[dependencies]
9+
ink = { workspace = true }
10+
11+
scale = { workspace = true, package = "parity-scale-codec" }
12+
scale-info = { workspace = true, optional = true }
13+
14+
[dev-dependencies]
15+
ink_e2e = { workspace = true }
16+
17+
[lib]
18+
path = "lib.rs"
19+
20+
[features]
21+
default = ["std"]
22+
std = [
23+
"ink/std",
24+
"scale/std",
25+
"scale-info/std",
26+
]
27+
ink-as-dependency = []
28+
e2e-tests = []

workspace-contracts/flipper/lib.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![cfg_attr(not(feature = "std"), no_std, no_main)]
2+
3+
#[ink::contract]
4+
pub mod flipper {
5+
#[ink(storage)]
6+
pub struct Flipper {
7+
value: bool,
8+
}
9+
10+
impl Flipper {
11+
/// Creates a new flipper smart contract initialized with the given value.
12+
#[ink(constructor)]
13+
pub fn new(init_value: bool) -> Self {
14+
Self { value: init_value }
15+
}
16+
17+
/// Creates a new flipper smart contract initialized to `false`.
18+
#[ink(constructor)]
19+
pub fn new_default() -> Self {
20+
Self::new(Default::default())
21+
}
22+
23+
/// Flips the current value of the Flipper's boolean.
24+
#[ink(message)]
25+
pub fn flip(&mut self) {
26+
self.value = !self.value;
27+
}
28+
29+
/// Returns the current value of the Flipper's boolean.
30+
#[ink(message)]
31+
pub fn get(&self) -> bool {
32+
self.value
33+
}
34+
}
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "incrementer"
3+
version = "4.3.0"
4+
authors = ["Parity Technologies <admin@parity.io>"]
5+
edition = "2021"
6+
publish = false
7+
8+
[dependencies]
9+
ink = { workspace = true }
10+
11+
scale = { workspace = true, package = "parity-scale-codec" }
12+
scale-info = { workspace = true, optional = true }
13+
14+
[lib]
15+
path = "lib.rs"
16+
17+
[features]
18+
default = ["std"]
19+
std = [
20+
"ink/std",
21+
"scale/std",
22+
"scale-info/std",
23+
]
24+
ink-as-dependency = []
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![cfg_attr(not(feature = "std"), no_std, no_main)]
2+
3+
#[ink::contract]
4+
mod incrementer {
5+
#[ink(storage)]
6+
pub struct Incrementer {
7+
value: i32,
8+
}
9+
10+
impl Incrementer {
11+
#[ink(constructor)]
12+
pub fn new(init_value: i32) -> Self {
13+
Self { value: init_value }
14+
}
15+
16+
#[ink(constructor)]
17+
pub fn new_default() -> Self {
18+
Self::new(Default::default())
19+
}
20+
21+
#[ink(message)]
22+
pub fn inc(&mut self, by: i32) {
23+
self.value = self.value.saturating_add(by);
24+
}
25+
26+
#[ink(message)]
27+
pub fn get(&self) -> i32 {
28+
self.value
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)