Skip to content

Commit 4835a85

Browse files
authored
Add CI (#11)
* add check CI * fix spacing from tabs * add licenses * rewrite CI to only use allowed action domains * remove redundant clippy * sort deps * forge fmt and build before testing * remove cache and timings * simplify test schema * remove duplicate ABI gen and rebuild * remove unused action * automatically build and copy * add note to rebuild statement
1 parent 35f9285 commit 4835a85

File tree

22 files changed

+616
-286
lines changed

22 files changed

+616
-286
lines changed

.github/workflows/main.yml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
permissions:
2+
contents: read
3+
# This configuration allows maintainers of this repo to create a branch and pull request based on
4+
# the new branch. Restricting the push trigger to the main branch ensures that the PR only gets
5+
# built once.
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
workflow_dispatch:
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
13+
cancel-in-progress: true
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
RISC0_TOOLCHAIN_VERSION: v2024-04-22.0
17+
RISC0_MONOREPO_REF: "release-1.0"
18+
jobs:
19+
check:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
# Full history is required by license-check.py
25+
fetch-depth: 0
26+
submodules: recursive
27+
- uses: risc0/risc0/.github/actions/rustup@main
28+
- name: Install cargo-sort
29+
uses: risc0/cargo-install@b9307573043522ab0d3e3be64a51763b765b52a4
30+
with:
31+
crate: cargo-sort
32+
version: "1.0"
33+
- uses: actions/setup-node@v3
34+
with:
35+
node-version: 18
36+
- uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
37+
- run: cargo fmt --all --check
38+
- run: cargo sort --workspace --check
39+
- run: cargo clippy -p risc0-tm-core
40+
- run: forge fmt --check
41+
working-directory: contracts
42+
- uses: actions/setup-python@v4
43+
with:
44+
python-version: "3.10"
45+
- run: python license-check.py
46+
- name: check for "D0 NOT MERGE" comments
47+
run: |
48+
[ "$(grep -re 'DO[_ ]\?NOT[_ ]\?MERGE' $(git ls-tree --full-tree --name-only -r HEAD) | tee /dev/fd/2 | wc -l)" -eq "0" ]
49+
test:
50+
runs-on: ubuntu-latest
51+
steps:
52+
# This is a workaround from: https://github.com/actions/checkout/issues/590#issuecomment-970586842
53+
- name: checkout dummy commit (submodule bug workaround)
54+
run: "git checkout -f $(git -c user.name=x -c user.email=x@x commit-tree $(git hash-object -t tree /dev/null) < /dev/null) || :"
55+
56+
- name: clone repository
57+
uses: actions/checkout@v4
58+
with:
59+
submodules: recursive
60+
61+
- name: Install rust
62+
uses: risc0/risc0/.github/actions/rustup@main
63+
64+
- name: Install Foundry
65+
uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
66+
67+
- name: risczero toolchain install
68+
uses: risc0/risc0-ethereum/.github/actions/[email protected]
69+
with:
70+
ref: ${{ env.RISC0_MONOREPO_REF }}
71+
72+
- name: cargo check to build autogenerated files
73+
run: cargo check
74+
75+
# Note: check above should rebuild contracts
76+
# - name: build solidity contracts
77+
# run: forge build
78+
# working-directory: contracts
79+
80+
- name: run tests
81+
run: cargo test
82+
83+
- name: run foundry tests in dev mode
84+
env:
85+
RISC0_DEV_MODE: true
86+
run: forge test -vvv
87+
working-directory: contracts

Cargo.lock

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

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["host", "core"]
3+
members = ["core", "host"]
44
default-members = ["host"]
55

66
[workspace.dependencies]

batch-guest/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ edition = "2021"
77
risc0-build = { version = "1.0.1" }
88
risc0-build-ethereum = { git = "https://github.com/risc0/risc0-ethereum", tag = "v1.0.0" }
99

10+
# Currently just used to format built artifact
11+
serde_json = "1.0"
12+
1013
[package.metadata.risc0]
1114
methods = ["guest"]

batch-guest/build.rs

+48-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 RISC Zero, Inc.
1+
// Copyright 2024 RISC Zero, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,10 +12,17 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{collections::HashMap, env};
15+
use std::{
16+
collections::HashMap,
17+
env,
18+
fs::{self, File},
19+
io::BufReader,
20+
process::Command,
21+
};
1622

1723
use risc0_build::{embed_methods_with_options, DockerOptions, GuestOptions};
1824
use risc0_build_ethereum::generate_solidity_files;
25+
use serde_json::Value;
1926

2027
// Paths where the generated Solidity files will be written.
2128
const SOLIDITY_IMAGE_ID_PATH: &str = "../contracts/src/ImageID.sol";
@@ -43,4 +50,43 @@ fn main() {
4350
.with_elf_sol_path(SOLIDITY_ELF_PATH);
4451

4552
generate_solidity_files(guests.as_slice(), &solidity_opts).unwrap();
53+
54+
let contracts_dir = fs::canonicalize(env!("CARGO_MANIFEST_DIR"))
55+
.unwrap()
56+
// Go back a directory from `./batch-guest`
57+
.parent()
58+
.unwrap()
59+
// Use guest directory.
60+
.join("contracts");
61+
62+
// Rebuild contracts after generating image ID to avoid inconsistencies.
63+
Command::new("forge")
64+
.args(["build", "--silent"])
65+
.current_dir(&contracts_dir)
66+
.status()
67+
.unwrap();
68+
69+
// Read and deserialize JSON artifact
70+
let file = File::open(
71+
contracts_dir
72+
.clone()
73+
.join("out")
74+
.join("Blobstream0.sol")
75+
.join("Blobstream0.json"),
76+
)
77+
.expect("Failed to open JSON file");
78+
let reader = BufReader::new(file);
79+
let artifact: Value = serde_json::from_reader(reader).expect("Failed to parse JSON");
80+
81+
// Write the artifact to artifacts dir
82+
// Open the file for writing
83+
let output_file = File::create(contracts_dir.join("artifacts").join("Blobstream0.json"))
84+
.expect("Failed to create output file");
85+
86+
// Write the formatted JSON
87+
serde_json::to_writer_pretty(output_file, &artifact).expect("Failed to write formatted JSON");
88+
89+
// NOTE: This should not be a circular update, as the code files are not updated with this, just
90+
// the built artifact that is pointed to.
91+
println!("cargo:rerun-if-changed={}", contracts_dir.display());
4692
}

batch-guest/guest/src/main.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
// Copyright 2024 RISC Zero, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
use alloy_primitives::U256;
216
use alloy_sol_types::SolValue;
317
use light_client_guest::TM_LIGHT_CLIENT_ID;
4-
use risc0_tm_core::{DataRootTuple, LightClientCommit, MerkleTree, RangeCommitment};
18+
use risc0_tm_core::{
19+
IBlobstream::{DataRootTuple, RangeCommitment},
20+
LightClientCommit, MerkleTree,
21+
};
522
use risc0_zkvm::{guest::env, serde::from_slice};
623

724
// TODO by default this will serialize poorly, optimize

batch-guest/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1+
// Copyright 2024 RISC Zero, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
include!(concat!(env!("OUT_DIR"), "/methods.rs"));

0 commit comments

Comments
 (0)