-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: fetch possible example contracts at compile time
- Loading branch information
1 parent
195d354
commit 0d6cba6
Showing
3 changed files
with
47 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,45 @@ | ||
fn main() { | ||
crate_git_revision::init(); | ||
let w = &mut std::io::stdout(); | ||
__set_example_contracts(w).unwrap(); | ||
} | ||
|
||
fn __set_example_contracts(w: &mut impl std::io::Write) -> std::io::Result<()> { | ||
// let example_contracts = get_example_contracts().unwrap().join(","); | ||
let example_contracts = get_example_contracts().unwrap().join(","); | ||
writeln!(w, "cargo:rustc-env=EXAMPLE_CONTRACTS={example_contracts}")?; | ||
Ok(()) | ||
} | ||
|
||
const GITHUB_API_URL: &str = | ||
"https://api.github.com/repos/stellar/soroban-examples/git/trees/main?recursive=1"; | ||
|
||
#[derive(serde::Deserialize, Debug)] | ||
struct RepoPath { | ||
path: String, | ||
#[serde(rename = "type")] | ||
type_field: String, | ||
} | ||
|
||
#[derive(serde::Deserialize, Debug)] | ||
struct ReqBody { | ||
tree: Vec<RepoPath>, | ||
} | ||
|
||
fn get_example_contracts() -> Result<Vec<String>, ureq::Error> { | ||
let body: ReqBody = ureq::get(GITHUB_API_URL).call()?.into_json()?; | ||
let mut valid_examples = Vec::new(); | ||
for item in body.tree { | ||
if item.type_field == "blob" | ||
|| item.path.starts_with('.') | ||
|| item.path.contains('/') | ||
|| item.path == "hello_world" | ||
{ | ||
continue; | ||
} | ||
|
||
valid_examples.push(item.path); | ||
} | ||
|
||
Ok(valid_examples) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters