Skip to content

Commit

Permalink
feat(cli): add --alwaysPostDeploy flag to deploys (#1765)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Oct 13, 2023
1 parent 61c6ab7 commit ccc21e9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/metal-pots-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@latticexyz/cli": minor
---

Added a `--alwaysRunPostDeploy` flag to deploys (`deploy`, `test`, `dev-contracts` commands) to always run `PostDeploy.s.sol` script after each deploy. By default, `PostDeploy.s.sol` is only run once after a new world is deployed.

This is helpful if you want to continue a deploy that may not have finished (due to an error or otherwise) or to run deploys with an idempotent `PostDeploy.s.sol` script.
2 changes: 2 additions & 0 deletions packages/cli/src/commands/dev-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Address } from "viem";
const devOptions = {
rpc: deployOptions.rpc,
configPath: deployOptions.configPath,
alwaysRunPostDeploy: deployOptions.alwaysRunPostDeploy,
};

const commandModule: CommandModule<typeof devOptions, InferredOptionTypes<typeof devOptions>> = {
Expand Down Expand Up @@ -74,6 +75,7 @@ const commandModule: CommandModule<typeof devOptions, InferredOptionTypes<typeof
}
// TODO: handle errors
const deploy = await runDeploy({
...opts,
configPath,
rpc,
skipBuild: false,
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/runDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const deployOptions = {
worldAddress: { type: "string", desc: "Deploy to an existing World at the given address" },
srcDir: { type: "string", desc: "Source directory. Defaults to foundry src directory." },
skipBuild: { type: "boolean", desc: "Skip rebuilding the contracts before deploying" },
alwaysRunPostDeploy: {
type: "boolean",
desc: "Always run PostDeploy.s.sol after each deploy (including during upgrades). By default, PostDeploy.s.sol is only run once after a new world is deployed.",
},
} as const satisfies Record<string, Options>;

export type DeployOptions = InferredOptionTypes<typeof deployOptions>;
Expand Down Expand Up @@ -84,7 +88,7 @@ in your contracts directory to use the default anvil private key.`
client,
config: resolvedConfig,
});
if (opts.worldAddress == null) {
if (opts.worldAddress == null || opts.alwaysRunPostDeploy) {
await postDeploy(config.postDeployScript, worldDeploy.address, rpc, profile);
}
console.log(chalk.green("Deployment completed in", (Date.now() - startTime) / 1000, "seconds"));
Expand Down

0 comments on commit ccc21e9

Please sign in to comment.