Skip to content

Commit

Permalink
ci: wip actions
Browse files Browse the repository at this point in the history
  • Loading branch information
losman0s committed Dec 4, 2023
1 parent 75541b8 commit 9ba8b1c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
7 changes: 1 addition & 6 deletions .github/actions/build-verifiable-program/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ runs:
shell: bash
env:
PROGRAM: ${{ inputs.program_lib_name }}

- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: ${{ inputs.program_lib_name }}-verifiable_build-${{ github.run_id }}-${{ github.run_attempt }}
path: ./target/deploy/${{ inputs.program_lib_name }}.so

21 changes: 21 additions & 0 deletions .github/workflows/release-program.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,31 @@ jobs:
with:
program_lib_name: ${{ env.PROGRAM_LIB_NAME }}

- name: Patch IDL and TS files
run: cargo run --release -p marginfi-v2-cli --features dev -- patch-idl target/idl/marginfi.json

# Display contents of /target/deploy and /target/idl
- run: ls -l target/deploy
- run: ls -l target/idl

- name: Upload program
uses: actions/upload-artifact@v2
with:
name: ${{ inputs.program_lib_name }}-verifiable_build-${{ github.run_id }}-${{ github.run_attempt }}
path: ./target/deploy/${{ inputs.program_lib_name }}.so

- name: Upload IDL (json)
uses: actions/upload-artifact@v2
with:
name: ${{ inputs.program_lib_name }}-idl-${{ github.run_id }}-${{ github.run_attempt }}
path: ./target/idl/${{ inputs.program_lib_name }}_patched.json

- name: Upload IDL (types)
uses: actions/upload-artifact@v2
with:
name: ${{ inputs.program_lib_name }}-types-${{ github.run_id }}-${{ github.run_attempt }}
path: ./target/idl/${{ inputs.program_lib_name }}_patched.ts

# # Deploy the program to the buffer account
# - uses: ./.github/actions/buffer-deploy/
# id: buffer-deploy
Expand Down
26 changes: 26 additions & 0 deletions clients/rust/marginfi-cli/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ fn inspect_size() -> Result<()> {
#[cfg(feature = "dev")]
fn patch_idl(idl_path: String) -> Result<()> {
use crate::patch_type_layout;
use std::io::Write;

let file = std::fs::File::open(&idl_path)?;
let reader = std::io::BufReader::new(file);
Expand All @@ -697,9 +698,34 @@ fn patch_idl(idl_path: String) -> Result<()> {
let writer = std::io::BufWriter::new(file);
serde_json::to_writer_pretty(writer, &idl)?;

let program_name = idl["name"].as_str().unwrap();
let camel_case_program_name = snake_to_camel_case(program_name);
let ts_file_path = idl_path.replace(".json", "_patched.ts");
let mut ts_file = std::fs::File::create(ts_file_path)?;
write!(ts_file, "export type {} = {};\n", camel_case_program_name, serde_json::to_string_pretty(&idl)?)?;
write!(ts_file, "export const IDL: {} = {};\n", camel_case_program_name, serde_json::to_string_pretty(&idl)?)?;

Ok(())
}

fn snake_to_camel_case(input: &str) -> String {
let mut camel_case = String::new();
let mut capitalize_next = true;

for c in input.chars() {
if c == '_' {
capitalize_next = true;
} else if capitalize_next {
camel_case.push(c.to_ascii_uppercase());
capitalize_next = false;
} else {
camel_case.push(c);
}
}

camel_case
}

fn process_account_subcmd(subcmd: AccountCommand, global_options: &GlobalOptions) -> Result<()> {
let profile = load_profile()?;
let config = profile.get_config(Some(global_options))?;
Expand Down

0 comments on commit 9ba8b1c

Please sign in to comment.