I can't think of a simple way to get the gas used as part of a deployment script.
If it's acceptable to inspect this manually:
If you're working on a local environment you can run a node (hardhat node) and manually inspect the output you get after running your deployment script against this node (hardhat run --network localhost scripts/deploy.js).
If you're working on a network that has an Etherscan explorer, you can go on the explorer to see all the transactions that were sent and how much gas they consumed.
If you need to do it in a script, what you could do is get the current block number before you deploy anything, then after your deployment get the new current block number. Then list all of the transactions that happened between those two blocks, filter it to those that were sent from your deployer account, and then sum the total gas. This is the only way I can think of for doing it programmatically.
Looks good except keep in mind it will count all transactions that have happened on the node since it started. If you want to measure the deployment only you could ask for current block number before deployment and only check from that block onward.
Yea, that was used in a hardhat test where the node get kicked up just for the test, i need to know the gasUsed of all deployment happening in that test...
I'm sure there would be 100s of better implementations than this workaround i posted above...