diff --git a/packages/devtools-evm-hardhat/src/tasks/deploy.ts b/packages/devtools-evm-hardhat/src/tasks/deploy.ts index d45c83843a..9e7b6847dd 100644 --- a/packages/devtools-evm-hardhat/src/tasks/deploy.ts +++ b/packages/devtools-evm-hardhat/src/tasks/deploy.ts @@ -261,6 +261,25 @@ const action: ActionType = async ( error == null ? [] : [{ networkName, error }] ) + // We count the total number of contracts that were deployed across all networks + const totalDeployedContracts = Object.values(results).reduce( + (acc, { contracts }) => acc + (contracts ? Object.keys(contracts).length : 0), + 0 + ) + + // If tags were specified but no contracts were deployed, warn the user + // This could happen if the tag doesn't match any deploy scripts, or if all matching contracts are already deployed + if (selectedTags.length > 0 && totalDeployedContracts === 0 && errors.length === 0) { + logger.warn( + `${printBoolean(false)} No contracts were deployed. This could mean no deploy scripts matched the given ${pluralizeNoun(selectedTags.length, 'tag', 'tags')} (${selectedTags.join(', ')}), or the contracts are already deployed` + ) + + // Mark the process as unsuccessful + process.exitCode = process.exitCode || 1 + + return results + } + // If nothing went wrong we just exit if (errors.length === 0) { return logger.info(`${printBoolean(true)} Your contracts are now deployed`), results diff --git a/tests/devtools-evm-hardhat-test/test/task/deploy.test.expectations/deploy-all-missing-tag.exp b/tests/devtools-evm-hardhat-test/test/task/deploy.test.expectations/deploy-all-missing-tag.exp index fb6a053772..ff29e72e1a 100755 --- a/tests/devtools-evm-hardhat-test/test/task/deploy.test.expectations/deploy-all-missing-tag.exp +++ b/tests/devtools-evm-hardhat-test/test/task/deploy.test.expectations/deploy-all-missing-tag.exp @@ -44,6 +44,6 @@ expect "Do you want to continue?" send -- "\r" expect "Deploying..." -expect "Your contracts are now deployed" +expect "No contracts were deployed" expect eof