-
Notifications
You must be signed in to change notification settings - Fork 610
Add gas reporting job parallelization on CI #1305
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
00166a0
add task for merging gas reports files on CI
mjlescano 29eb367
add parallelized gas reports to unit tests
mjlescano 0342770
update codechecks unit-test-gas-report name
mjlescano 46ce5ac
remove optimizer flag from unit tests
mjlescano 4bf0249
remove test:gas script from package.json
mjlescano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| # Measures deployment and transaction gas usage in unit tests | ||
| {{> job-header.yml}} | ||
| resource_class: large | ||
| steps: | ||
| - checkout | ||
| - attach_workspace: | ||
| at: . | ||
| - run: npm run test:gas | ||
| - run: npx codechecks codechecks.unit.yml | ||
| - run: | ||
| name: Upload gas reports | ||
| command: | | ||
| npx hardhat test:merge-gas-reports gasReporterOutput-*.json | ||
| npx codechecks codechecks.unit.yml | ||
| - store_artifacts: | ||
| path: test-gas-used.log | ||
| path: gasReporterOutput.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| requires: | ||
| - job-prepare | ||
| - job-unit-tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const { gray } = require('chalk'); | ||
| const { task } = require('hardhat/config'); | ||
| const { globSync } = require('hardhat/internal/util/glob'); | ||
| const uniq = require('lodash.uniq'); | ||
|
|
||
| /** | ||
| * Task for merging multiple gasReporterOuput.json files generated by eth-gas-reporter | ||
| * This task is necessary when we want to generate different parts of the reports | ||
| * parallelized on different jobs, then merge the results and upload it to codechecks. | ||
| * Gas Report JSON file schema: https://github.com/cgewecke/eth-gas-reporter/blob/master/docs/gasReporterOutput.md | ||
| */ | ||
|
|
||
| task('test:merge-gas-reports', 'Merge several gasReporterOuput.json files into one') | ||
| .addOptionalParam('output', 'Target file to save the merged report', 'gasReporterOutput.json') | ||
| .addVariadicPositionalParam( | ||
| 'input', | ||
| 'A list of gasReporterOutput.json files generated by eth-gas-reporter. Files can be defined using glob patterns' | ||
| ) | ||
| .setAction(async taskArguments => { | ||
| const output = path.resolve(taskArguments.output); | ||
|
|
||
| // Parse input files and calculate glob patterns | ||
| const input = uniq(taskArguments.input.map(globSync).flat()).map(inputFile => | ||
| path.resolve(inputFile) | ||
| ); | ||
|
|
||
| if (input.length === 0) { | ||
| throw new Error(`No files found for the given input: ${taskArguments.input.join(' ')}`); | ||
| } | ||
|
|
||
| console.log(gray(`Merging ${input.length} input files:`)); | ||
| input.forEach(inputFile => { | ||
| console.log(gray(' - ', inputFile)); | ||
| }); | ||
|
|
||
| console.log(gray('\nOutput: ', output)); | ||
|
|
||
| const result = { | ||
| namespace: null, | ||
| config: null, | ||
| info: { | ||
| methods: {}, | ||
| deployments: [], | ||
| blockLimit: null, | ||
| }, | ||
| }; | ||
|
|
||
| input.forEach(inputFile => { | ||
| const report = JSON.parse(fs.readFileSync(inputFile, 'utf-8')); | ||
|
|
||
| if (!report.config) { | ||
| throw new Error(`Missing "config" property on ${inputFile}`); | ||
| } | ||
|
|
||
| if (!result.config) result.config = report.config; | ||
|
|
||
| if (!result.namespace) { | ||
| result.namespace = report.namespace; | ||
| } | ||
|
|
||
| if (result.namespace !== report.namespace) { | ||
| throw new Error('Cannot merge reports with different namespaces'); | ||
| } | ||
|
|
||
| // Update config.gasPrice only if the newer one has a bigger number | ||
| if (typeof report.config.gasPrice === 'number') { | ||
| if ( | ||
| typeof result.config.gasPrice !== 'number' || | ||
| result.config.gasPrice < report.config.gasPrice | ||
| ) { | ||
| result.config.gasPrice = report.config.gasPrice; | ||
| } | ||
| } else { | ||
| result.config.gasPrice = report.config.gasPrice; | ||
| } | ||
|
|
||
| if (!report.info || typeof report.info.blockLimit !== 'number') { | ||
| throw new Error(`Invalid "info" property on ${inputFile}`); | ||
| } | ||
|
|
||
| if (!result.info.blockLimit) { | ||
| result.info.blockLimit = report.info.blockLimit; | ||
| } else if (result.info.blockLimit !== report.info.blockLimit) { | ||
| throw new Error('"info.blockLimit" should be the same on all reports'); | ||
| } | ||
|
|
||
| if (!report.info.methods) { | ||
| throw new Error(`Missing "info.methods" property on ${inputFile}`); | ||
| } | ||
|
|
||
| // Merge info.methods objects | ||
| Object.entries(report.info.methods).forEach(([key, value]) => { | ||
| if (!result.info.methods[key]) { | ||
| result.info.methods[key] = value; | ||
| return; | ||
| } | ||
|
|
||
| result.info.methods[key].gasData = [ | ||
| ...result.info.methods[key].gasData, | ||
| ...report.info.methods[key].gasData, | ||
| ].sort((a, b) => a - b); | ||
|
|
||
| result.info.methods[key].numberOfCalls += report.info.methods[key].numberOfCalls; | ||
| }); | ||
|
|
||
| if (!Array.isArray(report.info.deployments)) { | ||
| throw new Error(`Invalid "info.deployments" property on ${inputFile}`); | ||
| } | ||
|
|
||
| // Merge info.deployments objects | ||
| report.info.deployments.forEach(deployment => { | ||
| const current = result.info.deployments.find(d => d.name === deployment.name); | ||
|
|
||
| if (current) { | ||
| current.gasData = [...current.gasData, ...deployment.gasData].sort((a, b) => a - b); | ||
| } else { | ||
| result.info.deployments.push(deployment); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| fs.writeFileSync(output, JSON.stringify(result), 'utf-8'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.