Skip to content

Commit 607c6e1

Browse files
committed
when none deployed
1 parent ab680e5 commit 607c6e1

2 files changed

Lines changed: 76 additions & 4 deletions

File tree

packages/devtools-evm-hardhat/src/tasks/deploy.ts

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { task } from 'hardhat/config'
2-
import type { ActionType } from 'hardhat/types'
2+
import type { ActionType, HardhatRuntimeEnvironment } from 'hardhat/types'
33
import { TASK_COMPILE } from 'hardhat/builtin-tasks/task-names'
44
import { TASK_LZ_DEPLOY } from '@/constants/tasks'
55
import {
@@ -17,11 +17,57 @@ import { formatEid } from '@layerzerolabs/devtools'
1717
import { getEidsByNetworkName, getHreByNetworkName } from '@/runtime'
1818
import { types } from '@/cli'
1919
import { promptForText } from '@layerzerolabs/io-devtools'
20-
import { Deployment } from 'hardhat-deploy/dist/types'
20+
import { Deployment, DeployFunction } from 'hardhat-deploy/dist/types'
2121
import { assertDefinedNetworks, assertHardhatDeploy } from '@/internal/assertions'
2222
import { splitCommaSeparated } from '@layerzerolabs/devtools'
2323
import { isDeepEqual } from '@layerzerolabs/devtools'
2424
import { Stage, endpointIdToStage } from '@layerzerolabs/lz-definitions'
25+
import { readdirSync, statSync } from 'fs'
26+
import { join, extname } from 'path'
27+
28+
/**
29+
* Get all available tags from deploy scripts in the given deploy paths.
30+
* Uses require() with ts-node/esm loader to handle TypeScript files.
31+
*/
32+
const getAvailableTagsFromDeployScripts = async (hre: HardhatRuntimeEnvironment): Promise<Set<string>> => {
33+
const tags = new Set<string>()
34+
const deployPaths = hre.config.paths.deploy
35+
36+
for (const deployPath of deployPaths) {
37+
try {
38+
const files = readdirSync(deployPath)
39+
for (const file of files) {
40+
const filePath = join(deployPath, file)
41+
// Skip directories and non-script files
42+
if (statSync(filePath).isDirectory()) {
43+
continue
44+
}
45+
const ext = extname(file)
46+
if (!['.js', '.ts'].includes(ext)) {
47+
continue
48+
}
49+
50+
try {
51+
// Use require which works with ts-node/register in hardhat context
52+
// eslint-disable-next-line @typescript-eslint/no-var-requires
53+
const deployScript = require(filePath)
54+
const deployFunc: DeployFunction = deployScript.default ?? deployScript
55+
if (deployFunc?.tags) {
56+
for (const tag of deployFunc.tags) {
57+
tags.add(tag)
58+
}
59+
}
60+
} catch {
61+
// Skip files that can't be imported
62+
}
63+
}
64+
} catch {
65+
// Skip paths that don't exist
66+
}
67+
}
68+
69+
return tags
70+
}
2571

2672
interface TaskArgs {
2773
networks?: string[]
@@ -166,6 +212,16 @@ const action: ActionType<TaskArgs> = async (
166212
logger.warn(`Will use all deployment scripts`)
167213
} else {
168214
logger.info(`Will use deploy scripts tagged with ${selectedTags.join(', ')}`)
215+
216+
// Check if selected tags match any available deploy script tags
217+
const availableTags = await getAvailableTagsFromDeployScripts(hre)
218+
const unmatchedTags = selectedTags.filter((tag) => !availableTags.has(tag))
219+
220+
if (unmatchedTags.length > 0) {
221+
logger.warn(
222+
`The following tags do not match any deploy scripts: ${unmatchedTags.join(', ')}. Available tags: ${[...availableTags].join(', ') || 'none'}`
223+
)
224+
}
169225
}
170226

171227
// Now we confirm with the user that they want to continue
@@ -261,8 +317,23 @@ const action: ActionType<TaskArgs> = async (
261317
error == null ? [] : [{ networkName, error }]
262318
)
263319

264-
// If nothing went wrong we just exit
320+
// We check whether any contracts were actually deployed
321+
const totalContractsDeployed = Object.values(results).reduce(
322+
(sum, { contracts }) => sum + Object.keys(contracts ?? {}).length,
323+
0
324+
)
325+
326+
// If nothing went wrong we check if any contracts were deployed
265327
if (errors.length === 0) {
328+
if (totalContractsDeployed === 0) {
329+
return (
330+
logger.warn(
331+
`${printBoolean(false)} No contracts were deployed. This could mean the deploy script tags don't match any scripts, or all contracts were already deployed.`
332+
),
333+
results
334+
)
335+
}
336+
266337
return logger.info(`${printBoolean(true)} Your contracts are now deployed`), results
267338
}
268339

tests/devtools-evm-hardhat-test/test/task/deploy.test.expectations/deploy-all-missing-tag.exp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ send -- "\r"
4040

4141
expect "Will deploy 3 networks: britney, tango, vengaboys"
4242
expect "Will use deploy scripts tagged with MeNoExist"
43+
expect "do not match any deploy scripts"
4344
expect "Do you want to continue?"
4445
send -- "\r"
4546

4647
expect "Deploying..."
47-
expect "Your contracts are now deployed"
48+
expect "No contracts were deployed"
4849

4950
expect eof

0 commit comments

Comments
 (0)