Skip to content

Commit b52d41d

Browse files
authoredMar 12, 2025
ci: setup release workflow, update contributing (#5)
1 parent 9c4d21e commit b52d41d

File tree

18 files changed

+337
-106
lines changed

18 files changed

+337
-106
lines changed
 

‎.github/workflows/ci-checks.yml

+32
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,38 @@ jobs:
2121

2222
- name: Setup rust cache
2323
uses: Swatinem/rust-cache@v2
24+
with:
25+
key: ci-checks
26+
27+
- name: Install candid-extractor
28+
run: |
29+
TMPDIR=$(mktemp -d)
30+
VERSION="0.1.5"
31+
BINARY="candid-extractor-x86_64-unknown-linux-gnu.tar.gz"
32+
33+
wget -P "$TMPDIR" "https://github.com/dfinity/candid-extractor/releases/download/${VERSION}/${BINARY}"
34+
tar xzf "$TMPDIR/$BINARY" -C "$TMPDIR"
35+
mkdir -p "$HOME/.local/bin"
36+
mv "$TMPDIR/candid-extractor" "$HOME/.local/bin/"
37+
rm -rf "$TMPDIR"
38+
39+
candid-extractor --version
40+
41+
- name: Install wasm-opt
42+
run: |
43+
TMPDIR=$(mktemp -d)
44+
VERSION="version_122"
45+
BINARY="binaryen-$VERSION-x86_64-linux.tar.gz"
46+
47+
wget -P "$TMPDIR" "https://github.com/WebAssembly/binaryen/releases/download/$VERSION/$BINARY"
48+
tar xzf "$TMPDIR/$BINARY" -C "$TMPDIR"
49+
mkdir -p "$HOME/.local/bin"
50+
mv "$TMPDIR/binaryen-$VERSION/bin/"* "$HOME/.local/bin/"
51+
52+
# Cleanup temporary directory
53+
rm -rf "$TMPDIR"
54+
55+
wasm-opt --version
2456
2557
- name: Build
2658
run: |

‎.github/workflows/release.yml

+220
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
paths:
9+
- Cargo.toml
10+
- Cargo.lock
11+
- "contracts/**"
12+
- .github/workflows/release.yml
13+
pull_request:
14+
types: [opened, synchronize, reopened]
15+
branches:
16+
- master
17+
paths:
18+
- Cargo.toml
19+
- Cargo.lock
20+
- "contracts/**"
21+
- .github/workflows/release.yml
22+
23+
jobs:
24+
prepare:
25+
name: Prepare
26+
runs-on: ubuntu-latest
27+
outputs:
28+
rust_protocol_matrix: ${{ steps.setup_matrix.outputs.rust_protocol_matrix }}
29+
version: ${{ steps.version_info.outputs.version }}
30+
release_required: ${{ steps.version_info.outputs.release_required }}
31+
build_required: ${{ steps.version_info.outputs.build_required }}
32+
target_commit: ${{ steps.version_info.outputs.target_commit }}
33+
prerelease: ${{ steps.version_info.outputs.prerelease }}
34+
overwrite_release: ${{ steps.version_info.outputs.overwrite_release }}
35+
steps:
36+
- name: Checkout code
37+
uses: actions/checkout@v4
38+
39+
- name: Setup matrix
40+
id: setup_matrix
41+
run: |
42+
echo 'rust_protocol_matrix=["icp", "near", "stellar"]' >> "$GITHUB_OUTPUT"
43+
44+
- name: Get version info
45+
id: version_info
46+
shell: bash
47+
env:
48+
GH_TOKEN: ${{ github.token }}
49+
run: |
50+
echo "Validating contract versions"
51+
52+
version_candidate=""
53+
for protocol in $(echo '${{ steps.setup_matrix.outputs.rust_protocol_matrix }}' | jq -r '.[]'); do
54+
for contract in "contracts/${protocol}"/*; do
55+
if [ -d "${contract}" ]; then
56+
contract_version=$(cargo pkgid --manifest-path "${contract}/Cargo.toml" | awk -F'[#@]' '{print $NF}')
57+
echo " contract: $contract, version: $contract_version"
58+
59+
if [ -z "$version_candidate" ]; then
60+
version_candidate="$contract_version"
61+
elif [ "$version_candidate" != "$contract_version" ]; then
62+
echo "Version mismatch between contracts"
63+
echo "Make sure all contracts have the same version"
64+
echo "All contract protocols:"
65+
echo " - rust_protocol_matrix: '${{ steps.setup_matrix.outputs.rust_protocol_matrix }}'"
66+
exit 1
67+
fi
68+
fi
69+
done
70+
done
71+
echo "Valid version candidate: $version_candidate"
72+
73+
echo "target_commit=${{ github.sha }}" >> $GITHUB_OUTPUT
74+
75+
if [ "${{ github.ref }}" == "refs/heads/master" ]; then
76+
version="$version_candidate"
77+
echo "Master version: $version"
78+
79+
if gh release view "$version" --repo ${{ github.repository }} >/dev/null 2>&1; then
80+
echo "Master release for this version already exists"
81+
echo "release_required=false" >> $GITHUB_OUTPUT
82+
else
83+
echo "New master release required"
84+
echo "release_required=true" >> $GITHUB_OUTPUT
85+
fi
86+
87+
echo "build_required=true" >> $GITHUB_OUTPUT
88+
echo "prerelease=false" >> $GITHUB_OUTPUT
89+
echo "overwrite_release=false">> $GITHUB_OUTPUT
90+
echo "version=$version" >> $GITHUB_OUTPUT
91+
elif [ "${{ github.event_name }}" == "pull_request" ] && [[ "${{ github.head_ref }}" == release/* ]]; then
92+
version="prerelease-${{ github.event.number }}"
93+
echo "Prerelease version: $version"
94+
95+
echo "build_required=true" >> $GITHUB_OUTPUT
96+
echo "release_required=true" >> $GITHUB_OUTPUT
97+
echo "prerelease=true" >> $GITHUB_OUTPUT
98+
echo "overwrite_release=true">> $GITHUB_OUTPUT
99+
echo "version=$version" >> $GITHUB_OUTPUT
100+
else
101+
echo "This is not a master branch or a release PR"
102+
echo "build_required=false" >> $GITHUB_OUTPUT
103+
echo "release_required=false" >> $GITHUB_OUTPUT
104+
fi
105+
106+
build-rust:
107+
name: Build Rust
108+
if: needs.prepare.outputs.build_required == 'true'
109+
runs-on: ubuntu-latest
110+
needs: prepare
111+
112+
steps:
113+
- name: Checkout code
114+
uses: actions/checkout@v4
115+
116+
- name: Setup rust toolchain
117+
run: rustup toolchain install stable --profile minimal
118+
119+
- name: Setup rust cache
120+
uses: Swatinem/rust-cache@v2
121+
with:
122+
key: release
123+
124+
- name: Install candid-extractor
125+
run: |
126+
TMPDIR=$(mktemp -d)
127+
VERSION="0.1.5"
128+
BINARY="candid-extractor-x86_64-unknown-linux-gnu.tar.gz"
129+
130+
wget -P "$TMPDIR" "https://github.com/dfinity/candid-extractor/releases/download/${VERSION}/${BINARY}"
131+
tar xzf "$TMPDIR/$BINARY" -C "$TMPDIR"
132+
mkdir -p "$HOME/.local/bin"
133+
mv "$TMPDIR/candid-extractor" "$HOME/.local/bin/"
134+
rm -rf "$TMPDIR"
135+
136+
candid-extractor --version
137+
138+
- name: Install wasm-opt
139+
run: |
140+
TMPDIR=$(mktemp -d)
141+
VERSION="version_122"
142+
BINARY="binaryen-$VERSION-x86_64-linux.tar.gz"
143+
144+
wget -P "$TMPDIR" "https://github.com/WebAssembly/binaryen/releases/download/$VERSION/$BINARY"
145+
tar xzf "$TMPDIR/$BINARY" -C "$TMPDIR"
146+
mkdir -p "$HOME/.local/bin"
147+
mv "$TMPDIR/binaryen-$VERSION/bin/"* "$HOME/.local/bin/"
148+
149+
# Cleanup temporary directory
150+
rm -rf "$TMPDIR"
151+
152+
wasm-opt --version
153+
154+
- name: Build
155+
run: |
156+
./scripts/build-rust.sh
157+
158+
- name: Compress artifacts using gzip
159+
run: |
160+
create_archive() {
161+
local protocol_name=$1
162+
local artifacts_folder=$2
163+
164+
local archive_name="${protocol_name}.tar.gz"
165+
local tmp_dir=$(mktemp -d)
166+
167+
for contract in "contracts/${protocol_name}"/*; do
168+
if [ -d "${contract}" ]; then
169+
find "${contract}/res" -maxdepth 1 -type f -exec cp {} "$tmp_dir" \;
170+
fi
171+
done
172+
173+
ls -al "$tmp_dir"
174+
175+
tar -czf "$archive_name" -C "$tmp_dir" .
176+
mv "$archive_name" "$artifacts_folder"
177+
rm -rf "$tmp_dir"
178+
}
179+
180+
mkdir -p artifacts
181+
182+
for protocol in $(echo '${{ needs.prepare.outputs.rust_protocol_matrix }}' | jq -r '.[]'); do
183+
create_archive "${protocol}" artifacts
184+
done
185+
186+
ls -al artifacts
187+
188+
- name: Upload artifacts
189+
uses: actions/upload-artifact@v4
190+
with:
191+
name: artifacts-${{ matrix.target }}
192+
path: artifacts/*
193+
retention-days: 2
194+
195+
release:
196+
name: Release
197+
if: needs.prepare.outputs.release_required == 'true'
198+
runs-on: ubuntu-latest
199+
needs: [prepare, build-rust]
200+
steps:
201+
- name: Checkout code
202+
uses: actions/checkout@v4
203+
204+
- name: Download Artifact
205+
uses: actions/download-artifact@v4
206+
with:
207+
path: artifacts/
208+
merge-multiple: true
209+
210+
- name: Upload binaries to release
211+
uses: svenstaro/upload-release-action@v2
212+
with:
213+
repo_token: ${{ secrets.GITHUB_TOKEN }}
214+
file: artifacts/*
215+
file_glob: true
216+
tag: ${{ needs.prepare.outputs.version }}
217+
release_name: ${{ needs.prepare.outputs.version }}
218+
prerelease: ${{ needs.prepare.outputs.prerelease }}
219+
overwrite: ${{ needs.prepare.outputs.overwrite_release }}
220+
target_commit: ${{ needs.prepare.outputs.target_commit }}

‎CONTRIBUTING.md

+25
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,31 @@ effective for everyone.
1111

1212
Start by reading the [README][] to understand the project better.
1313

14+
## Local Project Setup
15+
16+
### Dependencies
17+
- [`rustc` and `cargo`](https://www.rust-lang.org/tools/install) - required for rust contracts
18+
- [wasm-opt](https://github.com/WebAssembly/binaryen/discussions/3797) - optional, for optimizing wasm binaries
19+
- [candid-extractor](https://github.com/dfinity/candid-extractor) - optional, used for DID generation for ICP contracts
20+
- [PocketIC](https://github.com/dfinity/pocketic) - required for ICP contracts testing
21+
22+
### Rust Contracts
23+
To build and test rust contracts locally, run the following commands:
24+
25+
```bash
26+
./scripts/build-rust.sh
27+
cargo test
28+
```
29+
30+
### Versions
31+
All contracts must have the same version as the core project.
32+
To bump contract versions, run the following commands:
33+
34+
```bash
35+
./scripts/bump-contracts-version.sh 0.4.0
36+
./scripts/build-rust.sh
37+
```
38+
1439
## Project Status
1540

1641
This project is actively being developed.

‎Cargo.lock

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+1-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ members = [
2424

2525
[workspace.dependencies]
2626
bs58 = "0.5.0"
27+
calimero-context-config = { git = "https://github.com/calimero-network/core", tag = "0.4.0" }
2728
candid = "0.10.10"
2829
cfg-if = "1.0.0"
2930
ed25519-dalek = "2.1.1"
@@ -45,17 +46,7 @@ stellar-xdr = { version = "22.1.0", default-features = false }
4546
thiserror = "1.0.56"
4647
tokio = "1.35.1"
4748

48-
calimero-context-config = { git = "https://github.com/calimero-network/core", tag = "0.4.0" }
49-
50-
calimero-registry = { path = "./contracts/near/registry" }
5149
calimero-context-config-near = { path = "./contracts/near/context-config" }
52-
calimero-context-proxy-near = { path = "./contracts/near/context-proxy" }
53-
calimero-test-counter-near = { path = "./contracts/near/test-counter" }
54-
55-
calimero-context-contract-icp = { path = "./contracts/icp/context-config" }
56-
calimero-proxy-contract-icp = { path = "./contracts/icp/context-proxy" }
57-
calimero-mock-ledger-icp = { path = "./contracts/icp/context-proxy/mock/ledger" }
58-
calimero-mock-external-icp = { path = "./contracts/icp/context-proxy/mock/external" }
5950

6051
[profile.release]
6152
strip = "symbols"

0 commit comments

Comments
 (0)
Failed to load comments.