@@ -32345,9 +32345,9 @@ const fs = __nccwpck_require__(7147);
3234532345
3234632346async function run() {
3234732347 try {
32348- const freshSnapshot = core.getInput("fresh-shapshots")==='true';
32349- const includeFuzzTests = core.getInput('include-fuzz-tests')==='true';
32350- const includeNewContracts = core.getInput('include-new-contracts')==='true';
32348+ const freshSnapshot = core.getInput("fresh-shapshots") === 'true';
32349+ const includeFuzzTests = core.getInput('include-fuzz-tests') === 'true';
32350+ const includeNewContracts = core.getInput('include-new-contracts') === 'true';
3235132351 const token = process.env.GITHUB_TOKEN || core.getInput("token");
3235232352 const octokit = getOctokit(token);
3235332353 const repo = context.repo.repo;
@@ -32377,7 +32377,7 @@ async function run() {
3237732377 if (prSnapshot === null) {
3237832378 throw new Error(`prSnapshot is null`);
3237932379 }
32380-
32380+
3238132381 fs.writeFileSync('.gas-snapshot.pr', prSnapshot);
3238232382 core.endGroup()
3238332383
@@ -32425,14 +32425,29 @@ async function getGitFileContent(octokit, owner, repo, ref, filePath) {
3242532425}
3242632426
3242732427async function generateGasSnapshot(repoFullName, branchName, fileName) {
32428- await exec.exec('git', ['fetch', `https://github.com/${repoFullName}`, `${branchName}`]);
32429- await exec.exec('git', ['checkout', '-b', branchName, `FETCH_HEAD`]);
32428+ const isFork = repoFullName !== `${context.repo.owner}/${context.repo.repo}`;
32429+
32430+ core.info(`Fetching branch: ${branchName} from repo: ${repoFullName}`);
32431+
32432+ // First, ensure we're on a clean branch
32433+ await exec.exec('git', ['checkout', '-B', `temp-${branchName}`]);
32434+
32435+ if (isFork) {
32436+ // If it's a fork, add a new remote and fetch from it
32437+ await exec.exec('git', ['remote', 'add', 'fork', `https://github.com/${repoFullName}.git`], { ignoreReturnCode: true });
32438+ await exec.exec('git', ['fetch', 'fork', branchName]);
32439+ await exec.exec('git', ['reset', '--hard', `fork/${branchName}`]);
32440+ } else {
32441+ // If it's the same repo, fetch as usual
32442+ await exec.exec('git', ['fetch', 'origin', branchName]);
32443+ await exec.exec('git', ['reset', '--hard', `origin/${branchName}`]);
32444+ }
3243032445
3243132446 const options = {
3243232447 ignoreReturnCode: true,
3243332448 silent: true
3243432449 };
32435- await exec.exec('forge', ['snapshot', '--snap', fileName] , options);
32450+ await exec.exec('forge', ['snapshot', '--snap', fileName], options);
3243632451}
3243732452
3243832453async function getDiffFileContent() {
@@ -32453,7 +32468,7 @@ async function getDiffFileContent() {
3245332468
3245432469function generateReport(diffSnapshot, genCommit, comCommit, includeFuzzTests, includeNewContracts) {
3245532470 if (!diffSnapshot || diffSnapshot.trim() === "") return ""; // Return if diffSnapshot is blank
32456-
32471+
3245732472 const mainTests = [];
3245832473 const prTests = [];
3245932474
@@ -32502,28 +32517,28 @@ function generateReport(diffSnapshot, genCommit, comCommit, includeFuzzTests, in
3250232517 ]));
3250332518
3250432519
32505- const testData = uniqueTests.map(testName => {
32506- const [contractName, simpleTestName] = testName.split(':');
32507- const mainTest = mainTests.find(t => t.testName === testName) || { gasValue: '-' };
32508- const prTest = prTests.find(t => t.testName === testName) || { gasValue: '-' };
32509- const diff = (mainTest.gasValue !== '-' && prTest.gasValue !== '-')
32510- ? (parseInt(prTest.gasValue) - parseInt(mainTest.gasValue))
32511- : '-';
32512-
32513- return {
32514- contractName,
32515- testName: simpleTestName,
32516- mainGas: mainTest.gasValue,
32517- prGas: prTest.gasValue,
32518- diff
32519- };
32520- }).filter(entry =>
32521- (includeNewContracts || entry.diff !== '-') && entry.diff !== 0); // Include new contracts or existing ones with valid gas values
32522-
32523- // sort testData for correct rowSpan in report
32524- testData.sort((a, b) => a.contractName.localeCompare(b.contractName));
32520+ const testData = uniqueTests.map(testName => {
32521+ const [contractName, simpleTestName] = testName.split(':');
32522+ const mainTest = mainTests.find(t => t.testName === testName) || { gasValue: '-' };
32523+ const prTest = prTests.find(t => t.testName === testName) || { gasValue: '-' };
32524+ const diff = (mainTest.gasValue !== '-' && prTest.gasValue !== '-')
32525+ ? (parseInt(prTest.gasValue) - parseInt(mainTest.gasValue))
32526+ : '-';
32527+
32528+ return {
32529+ contractName,
32530+ testName: simpleTestName,
32531+ mainGas: mainTest.gasValue,
32532+ prGas: prTest.gasValue,
32533+ diff
32534+ };
32535+ }).filter(entry =>
32536+ (includeNewContracts || entry.diff !== '-') && entry.diff !== 0); // Include new contracts or existing ones with valid gas values
3252532537
32526- let report = `
32538+ // sort testData for correct rowSpan in report
32539+ testData.sort((a, b) => a.contractName.localeCompare(b.contractName));
32540+
32541+ let report = `
3252732542### Gas Snapshot Comparison Report
3252832543
3252932544> Generated at commit : ${genCommit}, Compared to commit : ${comCommit}
@@ -32536,15 +32551,15 @@ function generateReport(diffSnapshot, genCommit, comCommit, includeFuzzTests, in
3253632551 <th>PR Gas</th>
3253732552 <th>Diff</th>
3253832553 </tr>`;
32539-
32554+
3254032555 let lastContractName = '';
3254132556
3254232557 // Process each test entry to generate report rows
3254332558 testData.forEach(entry => {
3254432559 if (entry.contractName !== lastContractName) {
3254532560 // Calculate rowSpan for the current contract
3254632561 const rowSpan = testData.filter(t => t.contractName === entry.contractName).length;
32547-
32562+
3254832563 report += `
3254932564 <tr>
3255032565 <td rowspan="${rowSpan}">${entry.contractName}</td>`;
0 commit comments