Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: add option to specify program keypair when using 'anchor deploy' #1786

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The minor version will be incremented upon a breaking change and the patch versi

## [Unreleased]

### Features

* cli: Add `--program-keypair` to `anchor deploy` ([#1786](https://github.com/project-serum/anchor/pull/1786)).

### Fixes

* lang: Fix `returns` being serialized as `null` instead of `undefined` in IDL ([#1782](https://github.com/project-serum/anchor/pull/1782)).
Expand Down
24 changes: 19 additions & 5 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,12 @@ pub enum Command {
Clean,
/// Deploys each program in the workspace.
Deploy {
/// Only deploy this program
#[clap(short, long)]
program_name: Option<String>,
/// Keypair of the program (filepath) (requires program-name)
#[clap(long, requires = "program-name")]
program_keypair: Option<String>,
},
/// Runs the deploy migration script.
Migrate,
Expand Down Expand Up @@ -415,7 +419,10 @@ pub fn entry(opts: Opts) -> Result<()> {
cargo_args,
),
Command::Clean => clean(&opts.cfg_override),
Command::Deploy { program_name } => deploy(&opts.cfg_override, program_name),
Command::Deploy {
program_name,
program_keypair,
} => deploy(&opts.cfg_override, program_name, program_keypair),
Command::Expand {
program_name,
cargo_args,
Expand Down Expand Up @@ -1839,7 +1846,7 @@ fn test(
// In either case, skip the deploy if the user specifies.
let is_localnet = cfg.provider.cluster == Cluster::Localnet;
if (!is_localnet || skip_local_validator) && !skip_deploy {
deploy(cfg_override, None)?;
deploy(cfg_override, None, None)?;
}
let mut is_first_suite = true;
if cfg.scripts.get("test").is_some() {
Expand Down Expand Up @@ -2338,7 +2345,11 @@ fn clean(cfg_override: &ConfigOverride) -> Result<()> {
Ok(())
}

fn deploy(cfg_override: &ConfigOverride, program_str: Option<String>) -> Result<()> {
fn deploy(
cfg_override: &ConfigOverride,
program_str: Option<String>,
program_keypair: Option<String>,
) -> Result<()> {
with_workspace(cfg_override, |cfg| {
let url = cluster_url(cfg, &cfg.test_validator);
let keypair = cfg.provider.wallet.to_string();
Expand All @@ -2362,7 +2373,10 @@ fn deploy(cfg_override: &ConfigOverride, program_str: Option<String>) -> Result<
);
println!("Program path: {}...", binary_path);

let file = program.keypair_file()?;
let program_keypair_filepath = match program_keypair.clone() {
Some(program_keypair) => program_keypair,
paul-schaaf marked this conversation as resolved.
Show resolved Hide resolved
None => program.keypair_file()?.path().display().to_string(),
};

// Send deploy transactions.
let exit = std::process::Command::new("solana")
Expand All @@ -2373,7 +2387,7 @@ fn deploy(cfg_override: &ConfigOverride, program_str: Option<String>) -> Result<
.arg("--keypair")
.arg(&keypair)
.arg("--program-id")
.arg(file.path().display().to_string())
.arg(program_keypair_filepath)
.arg(&binary_path)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
Expand Down