|
| 1 | +const { execSync, execFileSync } = require("child_process"); |
| 2 | +const fs = require("fs"); |
| 3 | +const tmp = require("tmp"); |
| 4 | + |
| 5 | +const ref = process.argv[2] || "HEAD"; |
| 6 | + |
| 7 | +const newTags = execFileSync("git", ["tag", "--points-at", ref]) |
| 8 | + .toString() |
| 9 | + .trim() |
| 10 | + .split("\n") |
| 11 | + .filter(Boolean); |
| 12 | + |
| 13 | +const summary = newTags.map((tag) => { |
| 14 | + const atIndex = tag.lastIndexOf("@"); |
| 15 | + const packageName = tag.slice(0, atIndex); |
| 16 | + const currentVersion = tag.slice(atIndex + 1); |
| 17 | + |
| 18 | + const previousTags = execSync( |
| 19 | + `git tag --sort=-version:refname -l "${packageName}@*"` |
| 20 | + ) |
| 21 | + .toString() |
| 22 | + .trim() |
| 23 | + .split("\n") |
| 24 | + .filter(Boolean); |
| 25 | + |
| 26 | + const previousTag = previousTags.find((t) => t !== tag); |
| 27 | + const previousVersion = previousTag |
| 28 | + ? previousTag.slice(previousTag.lastIndexOf("@") + 1) |
| 29 | + : null; |
| 30 | + |
| 31 | + return { package: packageName, previousVersion, currentVersion }; |
| 32 | +}); |
| 33 | + |
| 34 | +const jsonContent = JSON.stringify(summary, null, 2); |
| 35 | +const textContent = summary |
| 36 | + .map((entry) => { |
| 37 | + const prev = entry.previousVersion || "new"; |
| 38 | + return `${entry.package}: ${prev} -> ${entry.currentVersion}`; |
| 39 | + }) |
| 40 | + .join("\n"); |
| 41 | + |
| 42 | +console.log(textContent); |
| 43 | + |
| 44 | +const jsonTmp = tmp.fileSync({ prefix: "version-bump-summary-", postfix: ".json" }); |
| 45 | +fs.writeFileSync(jsonTmp.name, jsonContent + "\n"); |
| 46 | + |
| 47 | +const txtTmp = tmp.fileSync({ prefix: "version-bump-summary-", postfix: ".txt" }); |
| 48 | +fs.writeFileSync(txtTmp.name, textContent + "\n"); |
| 49 | + |
| 50 | +const ghOutput = process.env.GITHUB_OUTPUT; |
| 51 | +if (ghOutput) { |
| 52 | + fs.appendFileSync(ghOutput, `json-file=${jsonTmp.name}\n`); |
| 53 | + fs.appendFileSync(ghOutput, `text-file=${txtTmp.name}\n`); |
| 54 | +} |
0 commit comments