|
| 1 | +import { danger, warn } from "danger"; |
| 2 | +import { execSync } from "child_process"; |
| 3 | +import fs from "fs"; |
| 4 | +import path from "path"; |
| 5 | + |
| 6 | +const replayJarChanged = danger.git.modified_files.includes( |
| 7 | + "packages/core/android/libs/replay-stubs.jar" |
| 8 | +); |
| 9 | + |
| 10 | +if (!replayJarChanged) { |
| 11 | + console.log("replay-stubs.jar not changed, skipping check."); |
| 12 | + return; |
| 13 | +} |
| 14 | + |
| 15 | + |
| 16 | +const jsDist = path.join(process.cwd(), "js-dist"); |
| 17 | +const newSrc = path.join(process.cwd(), "replay-stubs-src"); |
| 18 | +const oldSrc = path.join(process.cwd(), "replay-stubs-old-src"); |
| 19 | + |
| 20 | +[jsDist, newSrc, oldSrc].forEach(dir => { |
| 21 | + if (!fs.existsSync(dir)) fs.mkdirSync(dir); |
| 22 | +}); |
| 23 | + |
| 24 | +// Tool for decompiling JARs. |
| 25 | +execSync(`curl -L -o ${jsDist}/jd-cli.zip https://github.com/intoolswetrust/jd-cli/releases/download/jd-cli-1.2.0/jd-cli-1.2.0-dist.zip`); |
| 26 | +execSync(`unzip -o ${jsDist}/jd-cli.zip -d ${jsDist}`); |
| 27 | + |
| 28 | +const newJarPath = path.join(jsDist, "replay-stubs.jar"); |
| 29 | +fs.copyFileSync("packages/core/android/libs/replay-stubs.jar", newJarPath); |
| 30 | + |
| 31 | +const baseJarPath = path.join(jsDist, "replay-stubs-old.jar"); |
| 32 | +const baseJarContent = execSync(`git show ${danger.github.pr.base.ref}:packages/core/android/libs/replay-stubs.jar`); |
| 33 | +fs.writeFileSync(baseJarPath, baseJarContent); |
| 34 | + |
| 35 | +// Decompile both JARs |
| 36 | +execSync(`java -jar ${jsDist}/jd-cli.jar -od ${newSrc} ${newJarPath}`); |
| 37 | +execSync(`java -jar ${jsDist}/jd-cli.jar -od ${oldSrc} ${baseJarPath}`); |
| 38 | + |
| 39 | +// Compare directory listings |
| 40 | +const newListing = execSync(`ls -lR ${newSrc}`).toString(); |
| 41 | +const oldListing = execSync(`ls -lR ${oldSrc}`).toString(); |
| 42 | + |
| 43 | +if (newListing !== oldListing) { |
| 44 | + warn(`⚠️ replay-stubs.jar changes detected. Directory listing diff:\n\`\`\`\n${oldListing}\n---\n${newListing}\n\`\`\``); |
| 45 | +} |
0 commit comments